30 #include <sys/resource.h>
40 #if defined(__GLIBC__) && !defined(__UCLIBC__)
41 #include <gnu/libc-version.h>
45 #define NANOSEC ((uint64_t) 1e9)
47 #if defined(PTHREAD_BARRIER_SERIAL_THREAD)
52 #if defined(_AIX) || \
53 defined(__OpenBSD__) || \
54 !defined(PTHREAD_BARRIER_SERIAL_THREAD)
93 if (barrier ==
NULL || barrier->
b ==
NULL)
99 if (++
b->in ==
b->threshold) {
101 b->out =
b->threshold;
109 last = (--
b->out == 0);
127 if (
b->in != 0 ||
b->out != 0)
148 rc = pthread_barrier_wait(barrier);
150 if (rc != PTHREAD_BARRIER_SERIAL_THREAD)
153 return rc == PTHREAD_BARRIER_SERIAL_THREAD;
158 if (pthread_barrier_destroy(barrier))
172 #if defined(__APPLE__) || defined(__linux__)
179 if (0 == getrlimit(RLIMIT_STACK, &lim) && lim.rlim_cur != RLIM_INFINITY) {
181 lim.rlim_cur -= lim.rlim_cur % (rlim_t) getpagesize();
194 if (lim.rlim_cur >= 8192)
195 if (lim.rlim_cur >= PTHREAD_STACK_MIN)
200 #if !defined(__linux__)
202 #elif defined(__PPC__) || defined(__ppc__) || defined(__powerpc__)
221 pthread_attr_t* attr;
222 pthread_attr_t attr_storage;
236 if (stack_size == 0) {
239 pagesize = (
size_t)getpagesize();
241 stack_size = (stack_size + pagesize - 1) &~ (pagesize - 1);
242 #ifdef PTHREAD_STACK_MIN
243 if (stack_size < PTHREAD_STACK_MIN)
244 stack_size = PTHREAD_STACK_MIN;
248 if (stack_size > 0) {
249 attr = &attr_storage;
251 if (pthread_attr_init(attr))
254 if (pthread_attr_setstacksize(attr, stack_size))
259 err = pthread_create(tid, attr,
f.out,
arg);
262 pthread_attr_destroy(attr);
269 return pthread_self();
278 return pthread_equal(*
t1, *t2);
283 #if defined(NDEBUG) || !defined(PTHREAD_MUTEX_ERRORCHECK)
286 pthread_mutexattr_t attr;
289 if (pthread_mutexattr_init(&attr))
292 if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK))
295 err = pthread_mutex_init(
mutex, &attr);
297 if (pthread_mutexattr_destroy(&attr))
306 pthread_mutexattr_t attr;
309 if (pthread_mutexattr_init(&attr))
312 if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE))
315 err = pthread_mutex_init(
mutex, &attr);
317 if (pthread_mutexattr_destroy(&attr))
325 if (pthread_mutex_destroy(
mutex))
331 if (pthread_mutex_lock(
mutex))
351 if (pthread_mutex_unlock(
mutex))
362 if (pthread_rwlock_destroy(rwlock))
368 if (pthread_rwlock_rdlock(rwlock))
376 err = pthread_rwlock_tryrdlock(rwlock);
388 if (pthread_rwlock_unlock(rwlock))
394 if (pthread_rwlock_wrlock(rwlock))
402 err = pthread_rwlock_trywrlock(rwlock);
414 if (pthread_rwlock_unlock(rwlock))
420 if (pthread_once(guard, callback))
424 #if defined(__APPLE__) && defined(__MACH__)
429 err = semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO,
value);
430 if (
err == KERN_SUCCESS)
432 if (
err == KERN_INVALID_ARGUMENT)
434 if (
err == KERN_RESOURCE_SHORTAGE)
443 if (semaphore_destroy(mach_task_self(), *sem))
449 if (semaphore_signal(*sem))
458 r = semaphore_wait(*sem);
459 while (
r == KERN_ABORTED);
461 if (
r != KERN_SUCCESS)
467 mach_timespec_t interval;
471 interval.tv_nsec = 0;
473 err = semaphore_timedwait(*sem, interval);
474 if (
err == KERN_SUCCESS)
476 if (
err == KERN_OPERATION_TIMED_OUT)
485 #if defined(__GLIBC__) && !defined(__UCLIBC__)
498 static void glibc_version_check(
void) {
499 const char*
version = gnu_get_libc_version();
505 #elif defined(__MVS__)
507 #define platform_needs_custom_semaphore 1
511 #define platform_needs_custom_semaphore 0
521 #if (defined(__GLIBC__) && !defined(__UCLIBC__)) || \
522 platform_needs_custom_semaphore
578 while (sem->
value == 0)
592 if (sem->
value == 0) {
627 while (
r == -1 && errno ==
EINTR);
639 while (
r == -1 && errno ==
EINTR);
651 #if defined(__GLIBC__) && !defined(__UCLIBC__)
652 uv_once(&glibc_version_check_once, glibc_version_check);
696 #if defined(__APPLE__) && defined(__MACH__) || defined(__MVS__)
705 pthread_condattr_t attr;
708 err = pthread_condattr_init(&attr);
712 err = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
716 err = pthread_cond_init(
cond, &attr);
720 err = pthread_condattr_destroy(&attr);
727 pthread_cond_destroy(
cond);
729 pthread_condattr_destroy(&attr);
736 #if defined(__APPLE__) && defined(__MACH__)
741 pthread_mutex_t
mutex;
748 if (pthread_mutex_lock(&
mutex))
754 err = pthread_cond_timedwait_relative_np(
cond, &
mutex, &ts);
758 if (pthread_mutex_unlock(&
mutex))
761 if (pthread_mutex_destroy(&
mutex))
765 if (pthread_cond_destroy(
cond))
770 if (pthread_cond_signal(
cond))
775 if (pthread_cond_broadcast(
cond))
792 #if defined(__APPLE__) && defined(__MACH__)
795 r = pthread_cond_timedwait_relative_np(
cond,
mutex, &ts);
829 if (pthread_key_delete(*
key))
835 return pthread_getspecific(*
key);
840 if (pthread_setspecific(*
key,
value))
uint64_t uv__hrtime(uv_clocktype_t type)
const lzma_allocator const uint8_t * in
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval tv
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog gettimeofday
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
assert(limit<=UINT32_MAX/2)
int sem_wait(UV_PLATFORM_SEM_T *semid)
int sem_destroy(UV_PLATFORM_SEM_T *semid)
int sem_trywait(UV_PLATFORM_SEM_T *semid)
int sem_post(UV_PLATFORM_SEM_T *semid)
int sem_init(UV_PLATFORM_SEM_T *semid, int pshared, unsigned int value)
#define cond(bop, top, mask, flags)
static void uv__custom_sem_destroy(uv_sem_t *sem_)
int uv_barrier_wait(uv_barrier_t *barrier)
int uv_rwlock_trywrlock(uv_rwlock_t *rwlock)
int uv_thread_create_ex(uv_thread_t *tid, const uv_thread_options_t *params, void(*entry)(void *arg), void *arg)
int uv_cond_init(uv_cond_t *cond)
void uv_key_set(uv_key_t *key, void *value)
void uv_cond_signal(uv_cond_t *cond)
int uv_rwlock_init(uv_rwlock_t *rwlock)
void uv_sem_wait(uv_sem_t *sem)
static int uv__custom_sem_trywait(uv_sem_t *sem_)
void uv_rwlock_rdlock(uv_rwlock_t *rwlock)
int uv_mutex_trylock(uv_mutex_t *mutex)
static void uv__custom_sem_post(uv_sem_t *sem_)
void uv_mutex_unlock(uv_mutex_t *mutex)
void uv_rwlock_wrlock(uv_rwlock_t *rwlock)
static void uv__sem_post(uv_sem_t *sem)
void * uv_key_get(uv_key_t *key)
int uv_sem_trywait(uv_sem_t *sem)
int uv_mutex_init_recursive(uv_mutex_t *mutex)
int uv_thread_join(uv_thread_t *tid)
int uv_thread_create(uv_thread_t *tid, void(*entry)(void *arg), void *arg)
void uv_sem_post(uv_sem_t *sem)
void uv_mutex_destroy(uv_mutex_t *mutex)
int uv_thread_equal(const uv_thread_t *t1, const uv_thread_t *t2)
uv_thread_t uv_thread_self(void)
void uv_once(uv_once_t *guard, void(*callback)(void))
void uv_rwlock_rdunlock(uv_rwlock_t *rwlock)
int uv_key_create(uv_key_t *key)
void uv_cond_destroy(uv_cond_t *cond)
int uv_rwlock_tryrdlock(uv_rwlock_t *rwlock)
void uv_barrier_destroy(uv_barrier_t *barrier)
static int uv__custom_sem_init(uv_sem_t *sem_, unsigned int value)
int uv_cond_timedwait(uv_cond_t *cond, uv_mutex_t *mutex, uint64_t timeout)
static int uv__sem_init(uv_sem_t *sem, unsigned int value)
int uv_sem_init(uv_sem_t *sem, unsigned int value)
void uv_cond_broadcast(uv_cond_t *cond)
void uv_rwlock_destroy(uv_rwlock_t *rwlock)
static void uv__sem_destroy(uv_sem_t *sem)
int uv_mutex_init(uv_mutex_t *mutex)
static size_t thread_stack_size(void)
void uv_mutex_lock(uv_mutex_t *mutex)
void uv_cond_wait(uv_cond_t *cond, uv_mutex_t *mutex)
struct uv_semaphore_s uv_semaphore_t
int uv_barrier_init(uv_barrier_t *barrier, unsigned int count)
void uv_sem_destroy(uv_sem_t *sem)
#define platform_needs_custom_semaphore
void uv_key_delete(uv_key_t *key)
static void uv__custom_sem_wait(uv_sem_t *sem_)
void uv_rwlock_wrunlock(uv_rwlock_t *rwlock)
static void uv__sem_wait(uv_sem_t *sem)
static int uv__sem_trywait(uv_sem_t *sem)
STATIC_ASSERT(sizeof(uv_thread_t)<=sizeof(void *))
UV_PLATFORM_SEM_T uv_sem_t
pthread_mutex_t uv_mutex_t
void error(const char *msg)
void * uv__malloc(size_t size)
@ UV_THREAD_HAS_STACK_SIZE