Commit 68487a9b authored by Matt Caswell's avatar Matt Caswell
Browse files

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: default avatarRich Salz <rsalz@openssl.org>
parent 27949c35
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1208,7 +1208,7 @@ int s_client_main(int argc, char **argv)

    if (async) {
        SSL_CTX_set_mode(ctx, SSL_MODE_ASYNC);
        ASYNC_init_pool(0, 0);
        ASYNC_init(1, 0, 0);
    }

    if (!config_ctx(cctx, ssl_args, ctx, 1, jpake_secret == NULL))
@@ -2102,7 +2102,7 @@ int s_client_main(int argc, char **argv)
        SSL_free(con);
    }
    if (async) {
        ASYNC_free_pool();
        ASYNC_cleanup(1);
    }
#if !defined(OPENSSL_NO_NEXTPROTONEG)
    OPENSSL_free(next_proto.data);
+2 −2
Original line number Diff line number Diff line
@@ -1660,7 +1660,7 @@ int s_server_main(int argc, char *argv[])

    if (async) {
        SSL_CTX_set_mode(ctx, SSL_MODE_ASYNC);
        ASYNC_init_pool(0, 0);
        ASYNC_init(1, 0, 0);
    }

#ifndef OPENSSL_NO_SRTP
@@ -1974,7 +1974,7 @@ int s_server_main(int argc, char *argv[])
    BIO_free(bio_s_msg);
    bio_s_msg = NULL;
    if (async) {
        ASYNC_free_pool();
        ASYNC_cleanup(1);
    }
    return (ret);
}
+10 −0
Original line number Diff line number Diff line
@@ -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
+11 −2
Original line number Diff line number Diff line
@@ -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;
+9 −7
Original line number Diff line number Diff line
@@ -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)
{
Loading