mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
thread_win32.h: rb_thread_lock_t for USE_WIN32_MUTEX
* thread_win32.h (rb_thread_lock_t): make a union for USE_WIN32_MUTEX. this internal is used only in thread_win32.c, but has to be complete to define rb_thread_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3c56645634
commit
cdeff42cc1
3 changed files with 24 additions and 15 deletions
|
@ -1,4 +1,8 @@
|
||||||
Sun Jun 17 16:20:56 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sun Jun 17 16:21:01 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* thread_win32.h (rb_thread_lock_t): make a union for USE_WIN32_MUTEX.
|
||||||
|
this internal is used only in thread_win32.c, but has to be complete
|
||||||
|
to define rb_thread_t.
|
||||||
|
|
||||||
* thread_win32.c (native_mutex_lock, native_mutex_destroy): fix for
|
* thread_win32.c (native_mutex_lock, native_mutex_destroy): fix for
|
||||||
USE_WIN32_MUTEX.
|
USE_WIN32_MUTEX.
|
||||||
|
|
|
@ -340,9 +340,9 @@ static int
|
||||||
native_mutex_lock(rb_thread_lock_t *lock)
|
native_mutex_lock(rb_thread_lock_t *lock)
|
||||||
{
|
{
|
||||||
#if USE_WIN32_MUTEX
|
#if USE_WIN32_MUTEX
|
||||||
w32_mutex_lock(*lock);
|
w32_mutex_lock(lock->mutex);
|
||||||
#else
|
#else
|
||||||
EnterCriticalSection(lock);
|
EnterCriticalSection(&lock->crit);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -351,10 +351,10 @@ static int
|
||||||
native_mutex_unlock(rb_thread_lock_t *lock)
|
native_mutex_unlock(rb_thread_lock_t *lock)
|
||||||
{
|
{
|
||||||
#if USE_WIN32_MUTEX
|
#if USE_WIN32_MUTEX
|
||||||
thread_debug("release mutex: %p\n", *lock);
|
thread_debug("release mutex: %p\n", lock->mutex);
|
||||||
return ReleaseMutex(*lock);
|
return ReleaseMutex(lock->mutex);
|
||||||
#else
|
#else
|
||||||
LeaveCriticalSection(lock);
|
LeaveCriticalSection(&lock->crit);
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -364,8 +364,8 @@ native_mutex_trylock(rb_thread_lock_t *lock)
|
||||||
{
|
{
|
||||||
#if USE_WIN32_MUTEX
|
#if USE_WIN32_MUTEX
|
||||||
int result;
|
int result;
|
||||||
thread_debug("native_mutex_trylock: %p\n", *lock);
|
thread_debug("native_mutex_trylock: %p\n", lock->mutex);
|
||||||
result = w32_wait_events(&*lock, 1, 1, 0);
|
result = w32_wait_events(&lock->mutex, 1, 1, 0);
|
||||||
thread_debug("native_mutex_trylock result: %d\n", result);
|
thread_debug("native_mutex_trylock result: %d\n", result);
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case WAIT_OBJECT_0:
|
case WAIT_OBJECT_0:
|
||||||
|
@ -375,7 +375,7 @@ native_mutex_trylock(rb_thread_lock_t *lock)
|
||||||
}
|
}
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
#else
|
#else
|
||||||
return TryEnterCriticalSection(lock) == 0;
|
return TryEnterCriticalSection(&lock->crit) == 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,10 +383,10 @@ static void
|
||||||
native_mutex_initialize(rb_thread_lock_t *lock)
|
native_mutex_initialize(rb_thread_lock_t *lock)
|
||||||
{
|
{
|
||||||
#if USE_WIN32_MUTEX
|
#if USE_WIN32_MUTEX
|
||||||
*lock = w32_mutex_create();
|
lock->mutex = w32_mutex_create();
|
||||||
/* thread_debug("initialize mutex: %p\n", *lock); */
|
/* thread_debug("initialize mutex: %p\n", lock->mutex); */
|
||||||
#else
|
#else
|
||||||
InitializeCriticalSection(lock);
|
InitializeCriticalSection(&lock->crit);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,9 +394,9 @@ static void
|
||||||
native_mutex_destroy(rb_thread_lock_t *lock)
|
native_mutex_destroy(rb_thread_lock_t *lock)
|
||||||
{
|
{
|
||||||
#if USE_WIN32_MUTEX
|
#if USE_WIN32_MUTEX
|
||||||
w32_close_handle(*lock);
|
w32_close_handle(lock->mutex);
|
||||||
#else
|
#else
|
||||||
DeleteCriticalSection(lock);
|
DeleteCriticalSection(&lock->crit);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,12 @@ WINBASEAPI BOOL WINAPI
|
||||||
TryEnterCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
|
TryEnterCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
|
||||||
|
|
||||||
typedef HANDLE rb_thread_id_t;
|
typedef HANDLE rb_thread_id_t;
|
||||||
typedef CRITICAL_SECTION rb_thread_lock_t;
|
|
||||||
|
typedef union rb_thread_lock_union {
|
||||||
|
HANDLE mutex;
|
||||||
|
CRITICAL_SECTION crit;
|
||||||
|
} rb_thread_lock_t;
|
||||||
|
|
||||||
typedef struct rb_thread_cond_struct {
|
typedef struct rb_thread_cond_struct {
|
||||||
struct cond_event_entry *next;
|
struct cond_event_entry *next;
|
||||||
struct cond_event_entry *prev;
|
struct cond_event_entry *prev;
|
||||||
|
|
Loading…
Reference in a new issue