-#include "c11/threads.h"
-
-#ifdef HAVE_PTHREAD
-#include <signal.h>
-#endif
-
-
-/* pipe_thread
- */
-typedef thrd_t pipe_thread;
-
-#define PIPE_THREAD_ROUTINE( name, param ) \
- int name( void *param )
-
-static inline pipe_thread pipe_thread_create( PIPE_THREAD_ROUTINE((*routine), ), void *param )
-{
- pipe_thread thread;
-#ifdef HAVE_PTHREAD
- sigset_t saved_set, new_set;
- int ret;
-
- sigfillset(&new_set);
- pthread_sigmask(SIG_SETMASK, &new_set, &saved_set);
- ret = thrd_create( &thread, routine, param );
- pthread_sigmask(SIG_SETMASK, &saved_set, NULL);
-#else
- int ret;
- ret = thrd_create( &thread, routine, param );
-#endif
- if (ret)
- return 0;
-
- return thread;
-}
-
-static inline int pipe_thread_wait( pipe_thread thread )
-{
- return thrd_join( thread, NULL );
-}
-
-static inline int pipe_thread_destroy( pipe_thread thread )
-{
- return thrd_detach( thread );
-}
-
-static inline void pipe_thread_setname( const char *name )
-{
-#if defined(HAVE_PTHREAD)
-# if defined(__GNU_LIBRARY__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__) && \
- (__GLIBC__ >= 3 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 12))
- pthread_setname_np(pthread_self(), name);
-# endif
-#endif
- (void)name;
-}
-
-
-static inline int pipe_thread_is_self( pipe_thread thread )
-{
-#if defined(HAVE_PTHREAD)
-# if defined(__GNU_LIBRARY__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__) && \
- (__GLIBC__ >= 3 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 12))
- return pthread_equal(pthread_self(), thread);
-# endif
-#endif
- return 0;
-}
-
-/* pipe_mutex
- */
-typedef mtx_t pipe_mutex;
-
-#define pipe_static_mutex(mutex) \
- static pipe_mutex mutex = _MTX_INITIALIZER_NP
-
-#define pipe_mutex_init(mutex) \
- (void) mtx_init(&(mutex), mtx_plain)
-
-#define pipe_mutex_destroy(mutex) \
- mtx_destroy(&(mutex))
-
-#define pipe_mutex_lock(mutex) \
- (void) mtx_lock(&(mutex))
-
-#define pipe_mutex_unlock(mutex) \
- (void) mtx_unlock(&(mutex))