|
@@ -16,6 +16,7 @@
|
|
|
|
|
|
#define __FORCE_GLIBC
|
|
|
#include <features.h>
|
|
|
+#define __USE_GNU
|
|
|
#include <errno.h>
|
|
|
#include <netdb.h> /* for h_errno */
|
|
|
#include <stddef.h>
|
|
@@ -90,8 +91,10 @@ struct _pthread_descr_struct __pthread_initial_thread = {
|
|
|
0,
|
|
|
0,
|
|
|
{{{0, }}, 0, NULL},
|
|
|
- ATOMIC_INITIALIZER,
|
|
|
+ __ATOMIC_INITIALIZER,
|
|
|
0,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
NULL,
|
|
|
NULL,
|
|
|
NULL,
|
|
@@ -140,8 +143,10 @@ struct _pthread_descr_struct __pthread_manager_thread = {
|
|
|
1,
|
|
|
0,
|
|
|
{{{0, }}, 0, NULL},
|
|
|
- ATOMIC_INITIALIZER,
|
|
|
+ __ATOMIC_INITIALIZER,
|
|
|
0,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
NULL,
|
|
|
NULL,
|
|
|
NULL,
|
|
@@ -189,45 +194,79 @@ int __pthread_exit_code = 0;
|
|
|
|
|
|
const int __pthread_threads_max = PTHREAD_THREADS_MAX;
|
|
|
const int __pthread_sizeof_handle = sizeof(struct pthread_handle_struct);
|
|
|
-const int __pthread_offsetof_descr = offsetof(struct pthread_handle_struct,
|
|
|
- h_descr);
|
|
|
+const int __pthread_offsetof_descr = offsetof(struct pthread_handle_struct, h_descr);
|
|
|
const int __pthread_offsetof_pid = offsetof(struct _pthread_descr_struct,
|
|
|
p_pid);
|
|
|
const int __linuxthreads_pthread_sizeof_descr
|
|
|
= sizeof(struct _pthread_descr_struct);
|
|
|
|
|
|
+const int __linuxthreads_initial_report_events;
|
|
|
|
|
|
-
|
|
|
+const char __linuxthreads_version[] = VERSION;
|
|
|
|
|
|
-static void pthread_exit_process(int retcode, void *arg);
|
|
|
-#ifndef __i386__
|
|
|
+
|
|
|
+static void pthread_onexit_process(int retcode, void *arg);
|
|
|
static void pthread_handle_sigcancel(int sig);
|
|
|
static void pthread_handle_sigrestart(int sig);
|
|
|
-#else
|
|
|
-static void pthread_handle_sigcancel(int sig, struct sigcontext ctx);
|
|
|
-static void pthread_handle_sigrestart(int sig, struct sigcontext ctx);
|
|
|
-#endif
|
|
|
static void pthread_handle_sigdebug(int sig);
|
|
|
+int __pthread_timedsuspend_new(pthread_descr self, const struct timespec *abstime);
|
|
|
|
|
|
|
|
|
In these variables we keep track of the used variables. If the
|
|
|
platform does not support any real-time signals we will define the
|
|
|
values to some unreasonable value which will signal failing of all
|
|
|
the functions below. */
|
|
|
-#ifdef __NR_rt_sigaction
|
|
|
+#ifndef __NR_rt_sigaction
|
|
|
+static int current_rtmin = -1;
|
|
|
+static int current_rtmax = -1;
|
|
|
+int __pthread_sig_restart = SIGUSR1;
|
|
|
+int __pthread_sig_cancel = SIGUSR2;
|
|
|
+int __pthread_sig_debug;
|
|
|
+#else
|
|
|
+
|
|
|
+#if __SIGRTMAX - __SIGRTMIN >= 3
|
|
|
+static int current_rtmin = __SIGRTMIN + 3;
|
|
|
+static int current_rtmax = __SIGRTMAX;
|
|
|
int __pthread_sig_restart = __SIGRTMIN;
|
|
|
int __pthread_sig_cancel = __SIGRTMIN + 1;
|
|
|
int __pthread_sig_debug = __SIGRTMIN + 2;
|
|
|
void (*__pthread_restart)(pthread_descr) = __pthread_restart_new;
|
|
|
void (*__pthread_suspend)(pthread_descr) = __pthread_wait_for_restart_signal;
|
|
|
+int (*__pthread_timedsuspend)(pthread_descr, const struct timespec *) = __pthread_timedsuspend_new;
|
|
|
#else
|
|
|
+static int current_rtmin = __SIGRTMIN;
|
|
|
+static int current_rtmax = __SIGRTMAX;
|
|
|
int __pthread_sig_restart = SIGUSR1;
|
|
|
int __pthread_sig_cancel = SIGUSR2;
|
|
|
-int __pthread_sig_debug = 0;
|
|
|
-
|
|
|
- based on availability of rt signals. */
|
|
|
+int __pthread_sig_debug;
|
|
|
void (*__pthread_restart)(pthread_descr) = __pthread_restart_old;
|
|
|
void (*__pthread_suspend)(pthread_descr) = __pthread_suspend_old;
|
|
|
+int (*__pthread_timedsuspend)(pthread_descr, const struct timespec *) = __pthread_timedsuspend_old;
|
|
|
+
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
+int __libc_current_sigrtmin (void)
|
|
|
+{
|
|
|
+ return current_rtmin;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int __libc_current_sigrtmax (void)
|
|
|
+{
|
|
|
+ return current_rtmax;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ priority. Please note that we don't use a lock since we assume
|
|
|
+ this function to be called at program start. */
|
|
|
+int __libc_allocate_rtsig (int high)
|
|
|
+{
|
|
|
+ if (current_rtmin == -1 || current_rtmin > current_rtmax)
|
|
|
+
|
|
|
+ return -1;
|
|
|
+ return high ? current_rtmin++ : current_rtmax--;
|
|
|
+}
|
|
|
#endif
|
|
|
|
|
|
|
|
@@ -307,39 +346,27 @@ static void pthread_initialize(void)
|
|
|
|
|
|
Since signal handlers are shared between threads, these settings
|
|
|
will be inherited by all other threads. */
|
|
|
-#ifndef __i386__
|
|
|
sa.sa_handler = pthread_handle_sigrestart;
|
|
|
-#else
|
|
|
- sa.sa_handler = (__sighandler_t) pthread_handle_sigrestart;
|
|
|
-#endif
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
sa.sa_flags = 0;
|
|
|
__libc_sigaction(__pthread_sig_restart, &sa, NULL);
|
|
|
-#ifndef __i386__
|
|
|
sa.sa_handler = pthread_handle_sigcancel;
|
|
|
-#else
|
|
|
- sa.sa_handler = (__sighandler_t) pthread_handle_sigcancel;
|
|
|
-#endif
|
|
|
- sa.sa_flags = 0;
|
|
|
+
|
|
|
__libc_sigaction(__pthread_sig_cancel, &sa, NULL);
|
|
|
if (__pthread_sig_debug > 0) {
|
|
|
- sa.sa_handler = pthread_handle_sigdebug;
|
|
|
- sigemptyset(&sa.sa_mask);
|
|
|
- sa.sa_flags = 0;
|
|
|
- __libc_sigaction(__pthread_sig_debug, &sa, NULL);
|
|
|
+ sa.sa_handler = pthread_handle_sigdebug;
|
|
|
+ sigemptyset(&sa.sa_mask);
|
|
|
+
|
|
|
+ __libc_sigaction(__pthread_sig_debug, &sa, NULL);
|
|
|
}
|
|
|
|
|
|
sigemptyset(&mask);
|
|
|
sigaddset(&mask, __pthread_sig_restart);
|
|
|
-PDEBUG("block mask = %x\n", mask);
|
|
|
sigprocmask(SIG_BLOCK, &mask, NULL);
|
|
|
|
|
|
|
|
|
- before pthread_exit_process. */
|
|
|
- on_exit(pthread_exit_process, NULL);
|
|
|
-#ifdef __NR_rt_sigaction
|
|
|
- __pthread_init_condvar(1);
|
|
|
-#endif
|
|
|
+ before pthread_onexit_process. */
|
|
|
+ on_exit(pthread_onexit_process, NULL);
|
|
|
}
|
|
|
|
|
|
void __pthread_initialize(void)
|
|
@@ -351,6 +378,7 @@ int __pthread_initialize_manager(void)
|
|
|
{
|
|
|
int manager_pipe[2];
|
|
|
int pid;
|
|
|
+ int report_events;
|
|
|
struct pthread_request request;
|
|
|
|
|
|
|
|
@@ -379,7 +407,18 @@ int __pthread_initialize_manager(void)
|
|
|
}
|
|
|
|
|
|
pid = 0;
|
|
|
- if (__pthread_initial_thread.p_report_events)
|
|
|
+#ifdef USE_TLS
|
|
|
+ if (__linuxthreads_initial_report_events != 0)
|
|
|
+ THREAD_SETMEM (((pthread_descr) NULL), p_report_events,
|
|
|
+ __linuxthreads_initial_report_events);
|
|
|
+ report_events = THREAD_GETMEM (((pthread_descr) NULL), p_report_events);
|
|
|
+#else
|
|
|
+ if (__linuxthreads_initial_report_events != 0)
|
|
|
+ __pthread_initial_thread.p_report_events
|
|
|
+ = __linuxthreads_initial_report_events;
|
|
|
+ report_events = __pthread_initial_thread.p_report_events;
|
|
|
+#endif
|
|
|
+ if (__builtin_expect (report_events, 0))
|
|
|
{
|
|
|
|
|
|
the manager thread. */
|
|
@@ -391,7 +430,7 @@ int __pthread_initialize_manager(void)
|
|
|
!= 0)
|
|
|
{
|
|
|
|
|
|
- __pthread_lock(__pthread_manager_thread.p_lock, NULL);
|
|
|
+ __pthread_lock(__pthread_manager_thread.p_lock, NULL);
|
|
|
|
|
|
pid = clone(__pthread_manager_event,
|
|
|
(void **) __pthread_manager_thread_tos,
|
|
@@ -405,7 +444,7 @@ int __pthread_initialize_manager(void)
|
|
|
the new thread do this since we don't know whether it was
|
|
|
already scheduled when we send the event. */
|
|
|
__pthread_manager_thread.p_eventbuf.eventdata =
|
|
|
- &__pthread_manager_thread;
|
|
|
+ &__pthread_manager_thread;
|
|
|
__pthread_manager_thread.p_eventbuf.eventnum = TD_CREATE;
|
|
|
__pthread_last_event = &__pthread_manager_thread;
|
|
|
__pthread_manager_thread.p_tid = 2* PTHREAD_THREADS_MAX + 1;
|
|
@@ -434,6 +473,7 @@ int __pthread_initialize_manager(void)
|
|
|
__pthread_manager_reader = manager_pipe[0];
|
|
|
__pthread_manager_thread.p_tid = 2* PTHREAD_THREADS_MAX + 1;
|
|
|
__pthread_manager_thread.p_pid = pid;
|
|
|
+
|
|
|
|
|
|
if (__pthread_threads_debug && __pthread_sig_debug > 0)
|
|
|
{
|
|
@@ -445,7 +485,8 @@ int __pthread_initialize_manager(void)
|
|
|
|
|
|
PDEBUG("send REQ_DEBUG to manager thread\n");
|
|
|
request.req_kind = REQ_DEBUG;
|
|
|
- __libc_write(__pthread_manager_request, (char *) &request, sizeof(request));
|
|
|
+ TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request,
|
|
|
+ (char *) &request, sizeof(request)));
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -467,7 +508,8 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
|
|
sigprocmask(SIG_SETMASK, (const sigset_t *) NULL,
|
|
|
&request.req_args.create.mask);
|
|
|
PDEBUG("write REQ_CREATE to manager thread\n");
|
|
|
- __libc_write(__pthread_manager_request, (char *) &request, sizeof(request));
|
|
|
+ TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request,
|
|
|
+ (char *) &request, sizeof(request)));
|
|
|
PDEBUG("before suspend(self)\n");
|
|
|
suspend(self);
|
|
|
PDEBUG("after suspend(self)\n");
|
|
@@ -562,45 +604,39 @@ int pthread_getschedparam(pthread_t thread, int *policy,
|
|
|
|
|
|
|
|
|
|
|
|
-static void pthread_exit_process(int retcode, void *arg)
|
|
|
+static void pthread_onexit_process(int retcode, void *arg)
|
|
|
{
|
|
|
- struct pthread_request request;
|
|
|
- pthread_descr self = thread_self();
|
|
|
-
|
|
|
- if (__pthread_manager_request >= 0) {
|
|
|
- request.req_thread = self;
|
|
|
- request.req_kind = REQ_PROCESS_EXIT;
|
|
|
- request.req_args.exit.code = retcode;
|
|
|
- __libc_write(__pthread_manager_request,
|
|
|
- (char *) &request, sizeof(request));
|
|
|
- suspend(self);
|
|
|
-
|
|
|
- children, so that timings for main thread account for all threads. */
|
|
|
- if (self == __pthread_main_thread)
|
|
|
- waitpid(__pthread_manager_thread.p_pid, NULL, __WCLONE);
|
|
|
- }
|
|
|
+ struct pthread_request request;
|
|
|
+ pthread_descr self = thread_self();
|
|
|
+
|
|
|
+ if (__pthread_manager_request >= 0) {
|
|
|
+ request.req_thread = self;
|
|
|
+ request.req_kind = REQ_PROCESS_EXIT;
|
|
|
+ request.req_args.exit.code = retcode;
|
|
|
+ TEMP_FAILURE_RETRY(__libc_write(__pthread_manager_request,
|
|
|
+ (char *) &request, sizeof(request)));
|
|
|
+ suspend(self);
|
|
|
+
|
|
|
+ children, so that timings for main thread account for all threads. */
|
|
|
+ if (self == __pthread_main_thread) {
|
|
|
+ waitpid(__pthread_manager_thread.p_pid, NULL, __WCLONE);
|
|
|
+
|
|
|
+ * (possibly holding locks), free cannot be used any more. */
|
|
|
+ __pthread_manager_thread_bos = __pthread_manager_thread_tos = NULL;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
in the thread descriptor, and optionally performs a siglongjmp
|
|
|
(for pthread_cond_timedwait). */
|
|
|
|
|
|
-#ifndef __i386__
|
|
|
static void pthread_handle_sigrestart(int sig)
|
|
|
{
|
|
|
- pthread_descr self = thread_self();
|
|
|
- PDEBUG("got called in non-i386 mode for %u\n", self);
|
|
|
-#else
|
|
|
-static void pthread_handle_sigrestart(int sig, struct sigcontext ctx)
|
|
|
-{
|
|
|
- pthread_descr self;
|
|
|
- asm volatile ("movw %w0,%%gs" : : "r" (ctx.gs));
|
|
|
- self = thread_self();
|
|
|
- PDEBUG("got called in i386-mode for %u\n", self);
|
|
|
-#endif
|
|
|
- THREAD_SETMEM(self, p_signal, sig);
|
|
|
- if (THREAD_GETMEM(self, p_signal_jmp) != NULL)
|
|
|
- siglongjmp(*THREAD_GETMEM(self, p_signal_jmp), 1);
|
|
|
+ pthread_descr self = thread_self();
|
|
|
+ THREAD_SETMEM(self, p_signal, sig);
|
|
|
+ if (THREAD_GETMEM(self, p_signal_jmp) != NULL)
|
|
|
+ siglongjmp(*THREAD_GETMEM(self, p_signal_jmp), 1);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -608,33 +644,48 @@ static void pthread_handle_sigrestart(int sig, struct sigcontext ctx)
|
|
|
For the thread manager thread, redirect the signal to
|
|
|
__pthread_manager_sighandler. */
|
|
|
|
|
|
-#ifndef __i386__
|
|
|
static void pthread_handle_sigcancel(int sig)
|
|
|
{
|
|
|
pthread_descr self = thread_self();
|
|
|
sigjmp_buf * jmpbuf;
|
|
|
-#else
|
|
|
-static void pthread_handle_sigcancel(int sig, struct sigcontext ctx)
|
|
|
-{
|
|
|
- pthread_descr self;
|
|
|
- sigjmp_buf * jmpbuf;
|
|
|
- asm volatile ("movw %w0,%%gs" : : "r" (ctx.gs));
|
|
|
- self = thread_self();
|
|
|
-#endif
|
|
|
+
|
|
|
|
|
|
if (self == &__pthread_manager_thread)
|
|
|
{
|
|
|
+#ifdef THREAD_SELF
|
|
|
+
|
|
|
+ initialized, so that the thread register might still point to the
|
|
|
+ manager thread. Double check that this is really the manager
|
|
|
+ thread. */
|
|
|
+ pthread_descr real_self = thread_self_stack();
|
|
|
+ if (real_self == &__pthread_manager_thread)
|
|
|
+ {
|
|
|
+ __pthread_manager_sighandler(sig);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ self = real_self;
|
|
|
+# ifdef INIT_THREAD_SELF
|
|
|
+ INIT_THREAD_SELF(self, self->p_nr);
|
|
|
+# endif
|
|
|
+#else
|
|
|
__pthread_manager_sighandler(sig);
|
|
|
return;
|
|
|
+#endif
|
|
|
}
|
|
|
- if (__pthread_exit_requested) {
|
|
|
+ if (__builtin_expect (__pthread_exit_requested, 0)) {
|
|
|
|
|
|
children, so that timings for main thread account for all threads. */
|
|
|
- if (self == __pthread_main_thread)
|
|
|
+ if (self == __pthread_main_thread) {
|
|
|
+#ifdef USE_TLS
|
|
|
+ waitpid(__pthread_manager_thread->p_pid, NULL, __WCLONE);
|
|
|
+#else
|
|
|
waitpid(__pthread_manager_thread.p_pid, NULL, __WCLONE);
|
|
|
+#endif
|
|
|
+ }
|
|
|
_exit(__pthread_exit_code);
|
|
|
}
|
|
|
- if (THREAD_GETMEM(self, p_canceled)
|
|
|
+ if (__builtin_expect (THREAD_GETMEM(self, p_canceled), 0)
|
|
|
&& THREAD_GETMEM(self, p_cancelstate) == PTHREAD_CANCEL_ENABLE) {
|
|
|
if (THREAD_GETMEM(self, p_canceltype) == PTHREAD_CANCEL_ASYNCHRONOUS)
|
|
|
pthread_exit(PTHREAD_CANCELED);
|
|
@@ -698,7 +749,7 @@ void __pthread_kill_other_threads_np(void)
|
|
|
{
|
|
|
struct sigaction sa;
|
|
|
|
|
|
- pthread_exit_process(0, NULL);
|
|
|
+ pthread_onexit_process(0, NULL);
|
|
|
|
|
|
changes its mind, does not exec(), and creates new threads instead. */
|
|
|
__pthread_reset_main_thread();
|
|
@@ -732,65 +783,188 @@ int __pthread_getconcurrency(void)
|
|
|
}
|
|
|
weak_alias (__pthread_getconcurrency, pthread_getconcurrency)
|
|
|
|
|
|
-void __pthread_set_own_extricate_if(pthread_descr self, pthread_extricate_if *peif)
|
|
|
-{
|
|
|
- __pthread_lock(self->p_lock, self);
|
|
|
- THREAD_SETMEM(self, p_extricate, peif);
|
|
|
- __pthread_unlock(self->p_lock);
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
|
|
void __pthread_wait_for_restart_signal(pthread_descr self)
|
|
|
{
|
|
|
- sigset_t mask;
|
|
|
+ sigset_t mask;
|
|
|
|
|
|
- sigprocmask(SIG_SETMASK, NULL, &mask);
|
|
|
- sigdelset(&mask, __pthread_sig_restart);
|
|
|
- do {
|
|
|
- self->p_signal = 0;
|
|
|
- PDEBUG("temporary block mask = %x\n", mask);
|
|
|
- sigsuspend(&mask);
|
|
|
- PDEBUG(" *** after sigsuspend *** \n");
|
|
|
- } while (self->p_signal !=__pthread_sig_restart );
|
|
|
-}
|
|
|
+ sigprocmask(SIG_SETMASK, NULL, &mask);
|
|
|
+ sigdelset(&mask, __pthread_sig_restart);
|
|
|
+ THREAD_SETMEM(self, p_signal, 0);
|
|
|
+ do {
|
|
|
+ sigsuspend(&mask);
|
|
|
+ } while (THREAD_GETMEM(self, p_signal) !=__pthread_sig_restart);
|
|
|
|
|
|
-#ifdef __NR_rt_sigaction
|
|
|
-void __pthread_restart_new(pthread_descr th)
|
|
|
-{
|
|
|
- kill(th->p_pid, __pthread_sig_restart);
|
|
|
+ READ_MEMORY_BARRIER();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- be a wasteful wrapper for __pthread_wait_for_restart_signal */
|
|
|
-#if 0
|
|
|
-void __pthread_suspend_new(pthread_descr th)
|
|
|
-{
|
|
|
- __pthread_wait_for_restart_signal(th);
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
-#else
|
|
|
-
|
|
|
+#ifndef __NR_rt_sigaction
|
|
|
+
|
|
|
+ signals.
|
|
|
On these kernels, we use SIGUSR1 and SIGUSR2 for restart and cancellation.
|
|
|
Since the restart signal does not queue, we use an atomic counter to create
|
|
|
queuing semantics. This is needed to resolve a rare race condition in
|
|
|
pthread_cond_timedwait_relative. */
|
|
|
+
|
|
|
void __pthread_restart_old(pthread_descr th)
|
|
|
{
|
|
|
- if (atomic_increment(&th->p_resume_count) == -1)
|
|
|
- kill(th->p_pid, __pthread_sig_restart);
|
|
|
+ if (atomic_increment(&th->p_resume_count) == -1)
|
|
|
+ kill(th->p_pid, __pthread_sig_restart);
|
|
|
}
|
|
|
|
|
|
void __pthread_suspend_old(pthread_descr self)
|
|
|
{
|
|
|
- if (atomic_decrement(&self->p_resume_count) <= 0)
|
|
|
- __pthread_wait_for_restart_signal(self);
|
|
|
+ if (atomic_decrement(&self->p_resume_count) <= 0)
|
|
|
+ __pthread_wait_for_restart_signal(self);
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
-
|
|
|
- be a wasteful wrapper for __pthread_wait_for_restart_signal */
|
|
|
+int
|
|
|
+__pthread_timedsuspend_old(pthread_descr self, const struct timespec *abstime)
|
|
|
+{
|
|
|
+ sigset_t unblock, initial_mask;
|
|
|
+ int was_signalled = 0;
|
|
|
+ sigjmp_buf jmpbuf;
|
|
|
+
|
|
|
+ if (atomic_decrement(&self->p_resume_count) == 0) {
|
|
|
+
|
|
|
+ the signal and sleep. */
|
|
|
+
|
|
|
+ if (sigsetjmp(jmpbuf, 1) == 0) {
|
|
|
+ THREAD_SETMEM(self, p_signal_jmp, &jmpbuf);
|
|
|
+ THREAD_SETMEM(self, p_signal, 0);
|
|
|
+
|
|
|
+ sigemptyset(&unblock);
|
|
|
+ sigaddset(&unblock, __pthread_sig_restart);
|
|
|
+ sigprocmask(SIG_UNBLOCK, &unblock, &initial_mask);
|
|
|
+
|
|
|
+ while (1) {
|
|
|
+ struct timeval now;
|
|
|
+ struct timespec reltime;
|
|
|
+
|
|
|
+
|
|
|
+ __gettimeofday (&now, NULL);
|
|
|
+ reltime.tv_nsec = abstime->tv_nsec - now.tv_usec * 1000;
|
|
|
+ reltime.tv_sec = abstime->tv_sec - now.tv_sec;
|
|
|
+ if (reltime.tv_nsec < 0) {
|
|
|
+ reltime.tv_nsec += 1000000000;
|
|
|
+ reltime.tv_sec -= 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ resume waiting as required by Single Unix Specification. */
|
|
|
+ if (reltime.tv_sec < 0 || __libc_nanosleep(&reltime, NULL) == 0)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ sigprocmask(SIG_SETMASK, &initial_mask, NULL);
|
|
|
+ was_signalled = 0;
|
|
|
+ } else {
|
|
|
+ was_signalled = 1;
|
|
|
+ }
|
|
|
+ THREAD_SETMEM(self, p_signal_jmp, NULL);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ due to the delivery of a restart signal. In that case,
|
|
|
+ we know we have been dequeued and resumed and that the
|
|
|
+ resume count is balanced. Otherwise, there are some
|
|
|
+ cases to consider. First, try to bump up the resume count
|
|
|
+ back to zero. If it goes to 1, it means restart() was
|
|
|
+ invoked on this thread. The signal must be consumed
|
|
|
+ and the count bumped down and everything is cool. We
|
|
|
+ can return a 1 to the caller.
|
|
|
+ Otherwise, no restart was delivered yet, so a potential
|
|
|
+ race exists; we return a 0 to the caller which must deal
|
|
|
+ with this race in an appropriate way; for example by
|
|
|
+ atomically removing the thread from consideration for a
|
|
|
+ wakeup---if such a thing fails, it means a restart is
|
|
|
+ being delivered. */
|
|
|
+
|
|
|
+ if (!was_signalled) {
|
|
|
+ if (atomic_increment(&self->p_resume_count) != -1) {
|
|
|
+ __pthread_wait_for_restart_signal(self);
|
|
|
+ atomic_decrement(&self->p_resume_count);
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
+#ifdef __NR_rt_sigaction
|
|
|
+void __pthread_restart_new(pthread_descr th)
|
|
|
+{
|
|
|
+
|
|
|
+ our assumptions. The intent is to commit previous writes to shared
|
|
|
+ memory so the woken thread will have a consistent view. Complementary
|
|
|
+ read barriers are present to the suspend functions. */
|
|
|
+ WRITE_MEMORY_BARRIER();
|
|
|
+ kill(th->p_pid, __pthread_sig_restart);
|
|
|
+}
|
|
|
+
|
|
|
+int __pthread_timedsuspend_new(pthread_descr self, const struct timespec *abstime)
|
|
|
+{
|
|
|
+ sigset_t unblock, initial_mask;
|
|
|
+ int was_signalled = 0;
|
|
|
+ sigjmp_buf jmpbuf;
|
|
|
+
|
|
|
+ if (sigsetjmp(jmpbuf, 1) == 0) {
|
|
|
+ THREAD_SETMEM(self, p_signal_jmp, &jmpbuf);
|
|
|
+ THREAD_SETMEM(self, p_signal, 0);
|
|
|
+
|
|
|
+ sigemptyset(&unblock);
|
|
|
+ sigaddset(&unblock, __pthread_sig_restart);
|
|
|
+ sigprocmask(SIG_UNBLOCK, &unblock, &initial_mask);
|
|
|
+
|
|
|
+ while (1) {
|
|
|
+ struct timeval now;
|
|
|
+ struct timespec reltime;
|
|
|
+
|
|
|
+
|
|
|
+ gettimeofday (&now, NULL);
|
|
|
+ reltime.tv_nsec = abstime->tv_nsec - now.tv_usec * 1000;
|
|
|
+ reltime.tv_sec = abstime->tv_sec - now.tv_sec;
|
|
|
+ if (reltime.tv_nsec < 0) {
|
|
|
+ reltime.tv_nsec += 1000000000;
|
|
|
+ reltime.tv_sec -= 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ resume waiting as required by Single Unix Specification. */
|
|
|
+ if (reltime.tv_sec < 0 || __libc_nanosleep(&reltime, NULL) == 0)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ sigprocmask(SIG_SETMASK, &initial_mask, NULL);
|
|
|
+ was_signalled = 0;
|
|
|
+ } else {
|
|
|
+ was_signalled = 1;
|
|
|
+ }
|
|
|
+ THREAD_SETMEM(self, p_signal_jmp, NULL);
|
|
|
+
|
|
|
+
|
|
|
+ due to the delivery of a restart signal. In that case,
|
|
|
+ everything is cool. We have been removed from whatever
|
|
|
+ we were waiting on by the other thread, and consumed its signal.
|
|
|
+
|
|
|
+ Otherwise we this thread woke up spontaneously, or due to a signal other
|
|
|
+ than restart. This is an ambiguous case that must be resolved by
|
|
|
+ the caller; the thread is still eligible for a restart wakeup
|
|
|
+ so there is a race. */
|
|
|
+
|
|
|
+ READ_MEMORY_BARRIER();
|
|
|
+ return was_signalled;
|
|
|
+}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
|
@@ -805,7 +979,7 @@ void __pthread_message(char * fmt, ...)
|
|
|
va_start(args, fmt);
|
|
|
vsnprintf(buffer + 8, sizeof(buffer) - 8, fmt, args);
|
|
|
va_end(args);
|
|
|
- __libc_write(2, buffer, strlen(buffer));
|
|
|
+ TEMP_FAILURE_RETRY(__libc_write(2, buffer, strlen(buffer)));
|
|
|
}
|
|
|
|
|
|
#endif
|