summaryrefslogtreecommitdiffstats
path: root/crypto/async/arch
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2015-11-13 23:54:44 +0000
committerMatt Caswell <matt@openssl.org>2015-11-20 23:39:30 +0000
commit68487a9b0631d27be9a1f4565e7e652ae9cb6aad (patch)
treef08b9aedfa12d06d5602f2422def273b96f7ea2c /crypto/async/arch
parent27949c353e68825f119410f8fd73ae1d667581c7 (diff)
Convert __thread to pthreads for Thread Local Storage
In theory the pthreads approach for Thread Local Storage should be more portable. This also changes some APIs in order to accommodate this change. In particular ASYNC_init_pool is renamed ASYNC_init_thread and ASYNC_free_pool is renamed ASYNC_cleanup_thread. Also introduced ASYNC_init and ASYNC_cleanup. Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/async/arch')
-rw-r--r--crypto/async/arch/async_null.c10
-rw-r--r--crypto/async/arch/async_posix.c13
-rw-r--r--crypto/async/arch/async_posix.h16
3 files changed, 30 insertions, 9 deletions
diff --git a/crypto/async/arch/async_null.c b/crypto/async/arch/async_null.c
index 8de50ed531..dba159f309 100644
--- a/crypto/async/arch/async_null.c
+++ b/crypto/async/arch/async_null.c
@@ -61,6 +61,11 @@ int async_pipe(OSSL_ASYNC_FD *pipefds)
return -1;
}
+int async_close_fd(OSSL_ASYNC_FD fd)
+{
+ return 0;
+}
+
int async_write1(OSSL_ASYNC_FD fd, const void *buf)
{
return -1;
@@ -71,5 +76,10 @@ int async_read1(OSSL_ASYNC_FD fd, void *buf)
return -1;
}
+int async_thread_local_init(void)
+{
+ return 0;
+}
+
#endif
diff --git a/crypto/async/arch/async_posix.c b/crypto/async/arch/async_posix.c
index 541c8b36b4..bd4b0c2f1b 100644
--- a/crypto/async/arch/async_posix.c
+++ b/crypto/async/arch/async_posix.c
@@ -61,11 +61,20 @@
# include <openssl/crypto.h>
# include <openssl/async.h>
-__thread async_ctx *posixctx;
-__thread async_pool *posixpool;
+pthread_key_t posixctx;
+pthread_key_t posixpool;
#define STACKSIZE 32768
+int async_thread_local_init(void)
+{
+ if (pthread_key_create(&posixctx, NULL) != 0
+ || pthread_key_create(&posixpool, NULL) != 0)
+ return 0;
+
+ return 1;
+}
+
int async_fibre_init(async_fibre *fibre)
{
void *stack = NULL;
diff --git a/crypto/async/arch/async_posix.h b/crypto/async/arch/async_posix.h
index 9fdccf9e76..36fae24788 100644
--- a/crypto/async/arch/async_posix.h
+++ b/crypto/async/arch/async_posix.h
@@ -52,12 +52,14 @@
*/
#include <openssl/e_os2.h>
-#ifdef OPENSSL_SYS_UNIX
+#if defined(OPENSSL_SYS_UNIX) && defined(OPENSSL_THREADS)
# include <unistd.h>
# if _POSIX_VERSION >= 200112L
+# include <pthread.h>
+
# define ASYNC_POSIX
# define ASYNC_ARCH
@@ -73,8 +75,8 @@
# include <setjmp.h>
# include "e_os.h"
-extern __thread async_ctx *posixctx;
-extern __thread async_pool *posixpool;
+extern pthread_key_t posixctx;
+extern pthread_key_t posixpool;
typedef struct async_fibre_st {
ucontext_t fibre;
@@ -82,10 +84,10 @@ typedef struct async_fibre_st {
int env_init;
} async_fibre;
-# define async_set_ctx(nctx) (posixctx = (nctx))
-# define async_get_ctx() (posixctx)
-# define async_set_pool(p) (posixpool = (p))
-# define async_get_pool() (posixpool)
+# define async_set_ctx(nctx) (pthread_setspecific(posixctx , (nctx)) == 0)
+# define async_get_ctx() ((async_ctx *)pthread_getspecific(posixctx))
+# define async_set_pool(p) (pthread_setspecific(posixpool , (p)) == 0)
+# define async_get_pool() ((async_pool *)pthread_getspecific(posixpool))
static inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
{