Project

General

Profile

Feature #10134 ยป thread_native.patch

normalperson (Eric Wong), 08/14/2014 09:15 PM

View differences:

thread_pthread.c
#include <sys/time.h>
#endif
static void native_mutex_lock(pthread_mutex_t *lock);
static void native_mutex_unlock(pthread_mutex_t *lock);
static int native_mutex_trylock(pthread_mutex_t *lock);
static void native_mutex_initialize(pthread_mutex_t *lock);
static void native_mutex_destroy(pthread_mutex_t *lock);
static void native_mutex_lock(rb_nativethread_lock_t *lock);
static void native_mutex_unlock(rb_nativethread_lock_t *lock);
static int native_mutex_trylock(rb_nativethread_lock_t *lock);
static void native_mutex_initialize(rb_nativethread_lock_t *lock);
static void native_mutex_destroy(rb_nativethread_lock_t *lock);
static void native_cond_signal(rb_nativethread_cond_t *cond);
static void native_cond_broadcast(rb_nativethread_cond_t *cond);
static void native_cond_wait(rb_nativethread_cond_t *cond, pthread_mutex_t *mutex);
static void native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex);
static void native_cond_initialize(rb_nativethread_cond_t *cond, int flags);
static void native_cond_destroy(rb_nativethread_cond_t *cond);
static void rb_thread_wakeup_timer_thread_low(void);
......
#define NATIVE_MUTEX_LOCK_DEBUG 0
static void
mutex_debug(const char *msg, pthread_mutex_t *lock)
mutex_debug(const char *msg, void *lock)
{
if (NATIVE_MUTEX_LOCK_DEBUG) {
int r;
static pthread_mutex_t dbglock = PTHREAD_MUTEX_INITIALIZER;
if ((r = pthread_mutex_lock(&dbglock)) != 0) {exit(EXIT_FAILURE);}
fprintf(stdout, "%s: %p\n", msg, (void *)lock);
fprintf(stdout, "%s: %p\n", msg, lock);
if ((r = pthread_mutex_unlock(&dbglock)) != 0) {exit(EXIT_FAILURE);}
}
}
......
#if USE_THREAD_CACHE
static pthread_mutex_t thread_cache_lock = PTHREAD_MUTEX_INITIALIZER;
static rb_nativethread_lock_t thread_cache_lock = RB_NATIVETHREAD_LOCK_INIT;
struct cached_thread_entry *cached_thread_root;
static rb_thread_t *
register_cached_thread_and_wait(void)
{
rb_nativethread_cond_t cond = { PTHREAD_COND_INITIALIZER, };
rb_nativethread_cond_t cond = RB_NATIVETHREAD_COND_INIT;
volatile rb_thread_t *th_area = 0;
struct timeval tv;
struct timespec ts;
......
ts.tv_sec = tv.tv_sec + 60;
ts.tv_nsec = tv.tv_usec * 1000;
pthread_mutex_lock(&thread_cache_lock);
native_mutex_lock(&thread_cache_lock);
{
entry->th_area = &th_area;
entry->cond = &cond;
......
free(entry); /* ok */
native_cond_destroy(&cond);
}
pthread_mutex_unlock(&thread_cache_lock);
native_mutex_unlock(&thread_cache_lock);
return (rb_thread_t *)th_area;
}
......
struct cached_thread_entry *entry;
if (cached_thread_root) {
pthread_mutex_lock(&thread_cache_lock);
native_mutex_lock(&thread_cache_lock);
entry = cached_thread_root;
{
if (cached_thread_root) {
......
if (result) {
native_cond_signal(entry->cond);
}
pthread_mutex_unlock(&thread_cache_lock);
native_mutex_unlock(&thread_cache_lock);
}
#endif
return result;
......
native_sleep(rb_thread_t *th, struct timeval *timeout_tv)
{
struct timespec timeout;
pthread_mutex_t *lock = &th->interrupt_lock;
rb_nativethread_lock_t *lock = &th->interrupt_lock;
rb_nativethread_cond_t *cond = &th->native_thread_data.sleep_cond;
if (timeout_tv) {
......
GVL_UNLOCK_BEGIN();
{
pthread_mutex_lock(lock);
native_mutex_lock(lock);
th->unblock.func = ubf_pthread_cond_signal;
th->unblock.arg = th;
......
th->unblock.func = 0;
th->unblock.arg = 0;
pthread_mutex_unlock(lock);
native_mutex_unlock(lock);
}
GVL_UNLOCK_END();
......
void rb_thread_wakeup_timer_thread(void) {}
static void rb_thread_wakeup_timer_thread_low(void) {}
static pthread_mutex_t timer_thread_lock;
static rb_nativethread_lock_t timer_thread_lock;
static rb_nativethread_cond_t timer_thread_cond;
static inline void
thread_pthread.h
#include <pthread_np.h>
#endif
#define RB_NATIVETHREAD_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
#define RB_NATIVETHREAD_COND_INIT { PTHREAD_COND_INITIALIZER, }
typedef struct rb_thread_cond_struct {
pthread_cond_t cond;
#ifdef HAVE_CLOCKID_T
-
    (1-1/1)