Use POSIX functions on Cygwin, not Win32 function
[openssl.git] / crypto / async / arch / async_posix.h
index 7b8e905bec8f7ad1f76d7f5d57d159270c3041eb..475b56faabf5741ff913501389ea0c93ad2f515e 100644 (file)
  * OF THE POSSIBILITY OF SUCH DAMAGE.
  * ====================================================================
  */
+#ifndef OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
+#define OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
 #include <openssl/e_os2.h>
 
-#ifdef OPENSSL_SYS_UNIX
+#if (defined(OPENSSL_SYS_UNIX) || defined(OPENSSL_SYS_CYGWIN)) && defined(OPENSSL_THREADS)
 
 # include <unistd.h>
 
 # if _POSIX_VERSION >= 200112L
 
-#  define ASYNC_SYSV
+# include <pthread.h>
+
+#  define ASYNC_POSIX
 #  define ASYNC_ARCH
 
 #  include <ucontext.h>
 #  include <setjmp.h>
 #  include "e_os.h"
 
-extern __thread ASYNC_CTX *sysvctx;
+extern pthread_key_t posixctx;
+extern pthread_key_t posixpool;
 
 typedef struct async_fibre_st {
     ucontext_t fibre;
     jmp_buf env;
     int env_init;
-} ASYNC_FIBRE;
+} async_fibre;
 
-#  define ASYNC_set_ctx(nctx)             (sysvctx = (nctx))
-#  define ASYNC_get_ctx()                 (sysvctx)
+#  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)
+static inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
 {
     o->env_init = 1;
 
-    if (!r || !setjmp(o->env)) {
+    if (!r || !_setjmp(o->env)) {
         if (n->env_init)
-            longjmp(n->env, 1);
+            _longjmp(n->env, 1);
         else
             setcontext(&n->fibre);
     }
@@ -90,19 +97,11 @@ static inline int ASYNC_FIBRE_swapcontext(ASYNC_FIBRE *o, ASYNC_FIBRE *n, int r)
     return 1;
 }
 
-#  define ASYNC_FIBRE_makecontext(c) \
-            (ASYNC_FIBRE_init(c) \
-            && !getcontext(&(c)->fibre) \
-            && (makecontext(&(c)->fibre, ASYNC_start_func, 0), 1))
-#  define ASYNC_FIBRE_init_dispatcher(d)
-
-int ASYNC_FIBRE_init(ASYNC_FIBRE *fibre);
-void ASYNC_FIBRE_free(ASYNC_FIBRE *fibre);
-
-int async_pipe(int *pipefds);
-int async_write1(int fd, const void *buf);
-int async_read1(int fd, void *buf);
+#  define async_fibre_init_dispatcher(d)
 
+int async_fibre_makecontext(async_fibre *fibre);
+void async_fibre_free(async_fibre *fibre);
 
 # endif
 #endif
+#endif /* OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H */