23 #if defined(WITH_PTHREADS)
24 #if !defined(_POSIX_PTHREAD_SEMANTICS)
25 #define _POSIX_PTHREAD_SEMANTICS
27 #if !defined(_REENTRANT)
31 #undef _POSIX_PTHREAD_SEMANTICS
39 #if defined(WITH_PTHREADS)
55 #define pthread_self() 0
56 #define pthread_equal(_t1, _t2) ((_t1) == (_t2))
57 #define pthread_create(__newthread, __attr, __start_routine, arg) (EINVAL)
58 #define pthread_join(__thread, __value_ptr) (EINVAL)
59 #define pthread_cancel(__th) (EINVAL)
60 #define pthread_cleanup_pop(__execute)
61 #define pthread_cleanup_push(__routine, __arg)
63 #define pthread_attr_t int
64 #define pthread_attr_init(__attr) (EINVAL)
65 #define pthread_attr_destroy(__attr) (EINVAL)
66 #define pthread_attr_setdetachstate(__attr, __detachstate) (EINVAL)
68 #define pthread_mutex_t int
69 #define PTHREAD_MUTEX_INITIALIZER 0
70 #define PTHREAD_CREATE_JOINABLE 0
71 #define pthread_mutex_destroy(__mutex) (0)
72 #define pthread_mutex_init(__mutex, __attr) (0)
73 #define pthread_mutex_lock(__mutex) (0)
74 #define pthread_mutex_unlock(__mutex) (0)
76 #define pthread_cond_t int
77 #define PTHREAD_COND_INITIALIZER 0
78 #define pthread_cond_destroy(__cond) (0)
79 #define pthread_cond_init(__cond, __attr) (0)
80 #define pthread_cond_wait(__cond, __mutex) (EINVAL)
81 #define pthread_cond_broadcast(__cond) (0)
87 #if defined(__LCLINT__)
91 extern int __sigsetjmp (
struct __jmp_buf_tag __env[1],
int __savemask)
__THROW
93 extern void (*__cancel_routine) (
void *)
95 extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
97 extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
99 extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
122 void *(*__start_routine)(
void*),
123 void *__restrict
arg)
__THROW __nonnull ((1, 3))
131 const pthread_mutexattr_t *restrict attr)
148 const pthread_condattr_t *restrict attr)
154 const struct timespec *restrict abstime)
188 static void _fail(
int err,
const char * fn,
unsigned ln)
192 fprintf(stderr,
"%s: pthread error: %s(%d) -- aborting at %s:%u\n", yarnPrefix,
193 strerror(err), err, fn, ln);
197 exit(err == ENOMEM || err == EAGAIN ? err : EINVAL);
199 #define fail(_err) _fail((_err), __FILE__, __LINE__)
203 typedef void *(*malloc_t)(size_t);
205 #if defined(__LCLINT__)
206 static void *(*my_malloc_f)(
size_t nb)
209 static void (*
my_free)(
void * p)
257 bolt->
value = initial;
292 #define until(a) while(!(a))
368 #if defined(WITH_PTHREADS)
369 static void yarnReenter(
void * dummy)
381 while ((match = *prior) != NULL) {
384 prior = &(match->
next);
391 if (threads != match) {
392 *prior = match->
next;
407 #if defined(WITH_PTHREADS)
408 static void * yarnIgnition(
void *
arg)
437 void * stack,
size_t nstack)
443 struct capsule * capsule;
444 #if defined(WITH_PTHREADS)
452 capsule = (
struct capsule *)
my_malloc(
sizeof(*capsule));
465 || (ret = (stack ? pthread_attr_setstack(&attr, stack, nstack) : 0))
503 while ((match = *prior) != NULL) {
506 prior = &(match->
next);
513 threads_lock.
value--;
514 *prior = match->
next;
538 while (threads != NULL) {
544 while ((match = *prior) != NULL) {
547 prior = &(match->
next);
556 threads_lock.
value--;
557 *prior = match->
next;
static void * my_malloc(size_t size)
#define pthread_cleanup_push(__routine, __arg)
enum yarnTwistOP_e yarnTwistOP
void yarnTwist(yarnLock bolt, yarnTwistOP op, long val)
#define PTHREAD_MUTEX_INITIALIZER
void yarnPossess(yarnLock bolt)
#define pthread_attr_init(__attr)
long yarnPeekLock(yarnLock bolt)
#define pthread_equal(_t1, _t2)
const char const bson * cond
void *(* malloc_t)(size_t)
#define pthread_mutex_lock(__mutex)
void yarnMem(malloc_t lease, free_t vacate)
static yarnThread threads
struct yarnThread_s * yarnThread
#define pthread_cond_destroy(__cond)
#define pthread_cond_wait(__cond, __mutex)
void yarnWaitFor(yarnLock bolt, yarnWaitOP op, long val)
yarnThread yarnJoin(yarnThread ally)
#define pthread_attr_setdetachstate(__attr, __detachstate)
enum yarnWaitOP_e yarnWaitOP
#define pthread_mutex_unlock(__mutex)
yarnLock yarnNewLock(long initial)
yarnLock yarnFreeLock(yarnLock bolt)
#define pthread_attr_destroy(__attr)
void yarnDestruct(yarnThread off_course)
#define pthread_join(__thread, __value_ptr)
#define pthread_cleanup_pop(__execute)
const char const bson const bson * op
const char const char int arg
static struct yarnLock_s threads_lock
#define pthread_mutex_destroy(__mutex)
void yarnRelease(yarnLock bolt)
yarnThread yarnLaunchStack(void(*probe)(void *), void *payload, void *stack, size_t nstack)
yarnThread yarnLaunch(void(*probe)(void *), void *payload)
const char const char size_t size
#define PTHREAD_COND_INITIALIZER
#define pthread_cancel(__th)
struct yarnLock_s * yarnLock
#define pthread_cond_init(__cond, __attr)
#define pthread_mutex_init(__mutex, __attr)
#define pthread_cond_broadcast(__cond)
static malloc_t my_malloc_f
#define pthread_create(__newthread, __attr, __start_routine, arg)
#define PTHREAD_CREATE_JOINABLE
static void _fail(int err, const char *fn, unsigned ln)