2006-12-31 10:02:22 -05:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
thread_pthread.h -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
|
* blockinlining.c, compile.c, compile.h, debug.c, debug.h,
id.c, insnhelper.h, insns.def, thread.c, thread_pthread.ci,
thread_pthread.h, thread_win32.ci, thread_win32.h, vm.h,
vm_dump.c, vm_evalbody.ci, vm_opts.h: fix comments and
copyright year.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-13 17:13:04 -05:00
|
|
|
Copyright (C) 2004-2007 Koichi Sasada
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
2008-01-18 03:56:11 -05:00
|
|
|
#ifndef RUBY_THREAD_PTHREAD_H
|
|
|
|
#define RUBY_THREAD_PTHREAD_H
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2010-02-04 02:17:03 -05:00
|
|
|
#ifdef HAVE_PTHREAD_NP_H
|
|
|
|
#include <pthread_np.h>
|
|
|
|
#endif
|
2011-05-06 12:47:38 -04:00
|
|
|
|
thread_pthread: prefer rb_nativethread* types/functions
This will make it easier for us to try alternative mutex/condvar
implementations while still using pthreads for thread management.
[Feature #10134]
* thread_pthread.h: define RB_NATIVETHREAD_LOCK_INIT and
RB_NATIVETHREAD_COND_INIT macros
* thread_pthread.c (native_mutex_lock, native_mutex_unlock,
native_mutex_trylock, native_mutex_initialize,
native_mutex_destroy, native_cond_wait):
use rb_nativethread_lock_t instead of pthread_mutex_t
* thread_pthread.c (native_mutex_debug): make argument type-agnostic
to avoid later cast.
* thread_pthread.c (register_cached_thread_and_wait):
replace PTHREAD_COND_INITIALIZER with RB_NATIVETHREAD_COND_INIT,
use native_mutex_{lock,unlock}
* thread_pthread.c (use_cached_thread):
use native_mutex_{lock,unlock}
* thread_pthread.c (native_sleep):
use rb_nativethread_lock_t to match th->interrupt_lock,
use native_mutex_{lock,unlock}
* thread_pthread.c (timer_thread_lock): use rb_nativethread_lock_t type
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-14 20:17:53 -04:00
|
|
|
#define RB_NATIVETHREAD_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
|
|
|
|
#define RB_NATIVETHREAD_COND_INIT { PTHREAD_COND_INITIALIZER, }
|
|
|
|
|
2011-05-06 12:47:38 -04:00
|
|
|
typedef struct rb_thread_cond_struct {
|
|
|
|
pthread_cond_t cond;
|
2011-05-07 05:28:43 -04:00
|
|
|
#ifdef HAVE_CLOCKID_T
|
2011-05-06 12:47:38 -04:00
|
|
|
clockid_t clockid;
|
2011-05-07 05:28:43 -04:00
|
|
|
#endif
|
2013-07-23 06:50:32 -04:00
|
|
|
} rb_nativethread_cond_t;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
typedef struct native_thread_data_struct {
|
2015-11-30 15:33:20 -05:00
|
|
|
struct list_node ubf_list;
|
2013-07-23 06:50:32 -04:00
|
|
|
rb_nativethread_cond_t sleep_cond;
|
2006-12-31 10:02:22 -05:00
|
|
|
} native_thread_data_t;
|
|
|
|
|
2011-10-28 20:05:11 -04:00
|
|
|
#undef except
|
|
|
|
#undef try
|
|
|
|
#undef leave
|
|
|
|
#undef finally
|
|
|
|
|
2010-11-27 15:15:59 -05:00
|
|
|
typedef struct rb_global_vm_lock_struct {
|
2011-06-13 10:14:53 -04:00
|
|
|
/* fast path */
|
|
|
|
unsigned long acquired;
|
2014-07-08 16:50:37 -04:00
|
|
|
rb_nativethread_lock_t lock;
|
2011-06-13 10:14:53 -04:00
|
|
|
|
|
|
|
/* slow path */
|
2011-06-27 08:59:08 -04:00
|
|
|
volatile unsigned long waiting;
|
2013-07-23 06:50:32 -04:00
|
|
|
rb_nativethread_cond_t cond;
|
2011-06-13 10:14:53 -04:00
|
|
|
|
|
|
|
/* yield */
|
2013-07-23 06:50:32 -04:00
|
|
|
rb_nativethread_cond_t switch_cond;
|
|
|
|
rb_nativethread_cond_t switch_wait_cond;
|
2011-06-14 12:31:23 -04:00
|
|
|
int need_yield;
|
|
|
|
int wait_yield;
|
2010-11-27 15:15:59 -05:00
|
|
|
} rb_global_vm_lock_t;
|
|
|
|
|
2008-01-18 03:56:11 -05:00
|
|
|
#endif /* RUBY_THREAD_PTHREAD_H */
|