Add the ASYNC_is_capable() function and use it in speed.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
# include <windows.h>
#endif
-#if defined(OPENSSL_SYS_UNIX) && defined(OPENSSL_THREADS)
-# include <unistd.h>
-#endif
-
-#if !defined(OPENSSL_NO_ASYNC)
-# if defined(OPENSSL_SYS_UNIX) && defined(OPENSSL_THREADS)
-# if _POSIX_VERSION >= 200112L
-# define ASYNC_POSIX
-# endif
-# elif defined(_WIN32) || defined(__CYGWIN__)
-# define ASYNC_WIN
-# endif
-#endif
-
-#if !defined(ASYNC_POSIX) && !defined(ASYNC_WIN)
-# define ASYNC_NULL
-#endif
-
#include <openssl/bn.h>
#ifndef OPENSSL_NO_DES
# include <openssl/des.h>
#ifndef NO_FORK
{"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"},
#endif
-#ifndef ASYNC_NULL
+#ifndef OPENSSL_NO_ASYNC
{"async_jobs", OPT_ASYNCJOBS, 'p', "Enable async mode and start pnum jobs"},
#endif
#ifndef OPENSSL_NO_ENGINE
int i = 0;
OSSL_ASYNC_FD job_fd = 0;
size_t num_job_fds = 0;
-#if defined(ASYNC_POSIX)
+#if defined(OPENSSL_SYS_UNIX)
fd_set waitfdset;
OSSL_ASYNC_FD max_fd = 0;
#endif
}
}
-#if defined(ASYNC_POSIX)
+#if defined(OPENSSL_SYS_UNIX)
FD_ZERO(&waitfdset);
/* Add to the wait set all the fds that are already in the WAIT_CTX
#endif
while (num_inprogress > 0) {
-#if defined(ASYNC_POSIX)
+#if defined(OPENSSL_SYS_UNIX)
int select_result = 0;
struct timeval select_timeout;
select_timeout.tv_sec = 0;
if (select_result == 0)
continue;
-#elif defined(ASYNC_WIN)
+#elif defined(OPENSSL_SYS_WINDOWS)
DWORD avail = 0;
#endif
}
ASYNC_WAIT_CTX_get_all_fds(loopargs[i].wait_ctx, &job_fd, &num_job_fds);
-#if defined(ASYNC_POSIX)
+#if defined(OPENSSL_SYS_UNIX)
if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
continue;
-#elif defined(ASYNC_WIN)
+#elif defined(OPENSSL_SYS_WINDOWS)
if (num_job_fds == 1 &&
!PeekNamedPipe(job_fd, NULL, 0, NULL, &avail, NULL) && avail > 0)
continue;
total_op_count += job_op_count;
}
--num_inprogress;
-#if defined(ASYNC_POSIX)
+#if defined(OPENSSL_SYS_UNIX)
FD_CLR(job_fd, &waitfdset);
#endif
loopargs[i].inprogress_job = NULL;
#endif
break;
case OPT_ASYNCJOBS:
-#ifndef ASYNC_NULL
+#ifndef OPENSSL_NO_ASYNC
async_jobs = atoi(opt_arg());
+ if (!ASYNC_is_capable()) {
+ BIO_printf(bio_err,
+ "%s: async_jobs specified but async not supported\n",
+ prog);
+ goto opterr;
+ }
#endif
break;
case OPT_MISALIGN:
#ifdef ASYNC_NULL
+int ASYNC_is_capable(void)
+{
+ return 0;
+}
+
void async_local_cleanup(void)
{
}
#define STACKSIZE 32768
-void async_local_cleanup(void)
+int ASYNC_is_capable(void)
{
+ return 1;
}
+void async_local_cleanup(void)
+{
+}
int async_fibre_makecontext(async_fibre *fibre)
{
# include <windows.h>
# include "internal/cryptlib.h"
+int ASYNC_is_capable(void)
+{
+ return 1;
+}
+
void async_local_cleanup(void)
{
async_ctx *ctx = async_get_ctx();
ASYNC_init_thread, ASYNC_cleanup_thread, ASYNC_start_job, ASYNC_pause_job,
ASYNC_in_job, ASYNC_get_wait_fd, ASYNC_set_wait_fd, ASYNC_clear_wait_fd,
-ASYNC_get_current_job, ASYNC_block_pause, ASYNC_unblock_pause - asynchronous job
-management functions
+ASYNC_get_current_job, ASYNC_block_pause, ASYNC_unblock_pause, ASYNC_is_capable
+- asynchronous job management functions
=head1 SYNOPSIS
void ASYNC_block_pause(void);
void ASYNC_unblock_pause(void);
+ int ASYNC_is_capable(void);
+
=head1 DESCRIPTION
OpenSSL implements asynchronous capabilities through an ASYNC_JOB. This
ASYNC_unblock_pause() immediately before releasing it then this situation cannot
occur.
+Some platforms cannot support async operations. The ASYNC_is_capable() function
+can be used to detect whether the current platform is async capable or not.
+
=head1 RETURN VALUES
ASYNC_init_thread returns 1 on success or 0 otherwise.
ASYNC_get_wait_ctx() returns a pointer to the ASYNC_WAIT_CTX for the job.
+ASYNC_is_capable() returns 1 if the current platform is async capable or 0
+otherwise.
+
=head1 EXAMPLE
The following example demonstrates how to use most of the core async APIs:
=head1 HISTORY
-ASYNC_init, ASYNC_init_thread, ASYNC_cleanup, ASYNC_cleanup_thread,
-ASYNC_start_job, ASYNC_pause_job, ASYNC_get_wait_fd, ASYNC_get_current_job,
-ASYNC_wake, ASYNC_clear_wake were first added to OpenSSL 1.1.0.
+ASYNC_init_thread, ASYNC_cleanup_thread,
+ASYNC_start_job, ASYNC_pause_job, ASYNC_get_current_job, ASYNC_get_wait_ctx(),
+ASYNC_block_pause(), ASYNC_unblock_pause() and ASYNC_is_capable() were first
+added to OpenSSL 1.1.0.
=cut
size_t *numdelfds);
int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key);
+int ASYNC_is_capable(void);
+
int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *ctx, int *ret,
int (*func)(void *), void *args, size_t size);
int ASYNC_pause_job(void);