summaryrefslogtreecommitdiff
path: root/thread_sync.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-21 01:01:42 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-21 01:01:42 +0000
commit79bdb6f9c8ca823c39ae49f053d41390bb37b86e (patch)
tree35bf89661005baa62ec9b44734a0db4392726b2f /thread_sync.c
parent383d7dba121d385fcbaf8a00d64b068b3c35e553 (diff)
thread*.c: replace GetMutexPtr with mutex_ptr
Following ko1's lead in r59192, this gets rid of non-obvious assignments which happen inside macros. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_sync.c')
-rw-r--r--thread_sync.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/thread_sync.c b/thread_sync.c
index 5adb97f6b2..76632ebe5f 100644
--- a/thread_sync.c
+++ b/thread_sync.c
@@ -81,9 +81,6 @@ static const char* rb_mutex_unlock_th(rb_mutex_t *mutex, rb_thread_t *th);
*
*/
-#define GetMutexPtr(obj, tobj) \
- TypedData_Get_Struct((obj), rb_mutex_t, &mutex_data_type, (tobj))
-
#define mutex_mark NULL
static size_t
@@ -123,6 +120,15 @@ static const rb_data_type_t mutex_data_type = {
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
};
+static rb_mutex_t *
+mutex_ptr(VALUE obj)
+{
+ rb_mutex_t *mutex;
+
+ TypedData_Get_Struct(obj, rb_mutex_t, &mutex_data_type, mutex);
+ return mutex;
+}
+
VALUE
rb_obj_is_mutex(VALUE obj)
{
@@ -172,16 +178,15 @@ rb_mutex_new(void)
VALUE
rb_mutex_locked_p(VALUE self)
{
- rb_mutex_t *mutex;
- GetMutexPtr(self, mutex);
+ rb_mutex_t *mutex = mutex_ptr(self);
+
return mutex->th ? Qtrue : Qfalse;
}
static void
mutex_locked(rb_thread_t *th, VALUE self)
{
- rb_mutex_t *mutex;
- GetMutexPtr(self, mutex);
+ rb_mutex_t *mutex = mutex_ptr(self);
if (th->keeping_mutexes) {
mutex->next_mutex = th->keeping_mutexes;
@@ -199,9 +204,8 @@ mutex_locked(rb_thread_t *th, VALUE self)
VALUE
rb_mutex_trylock(VALUE self)
{
- rb_mutex_t *mutex;
+ rb_mutex_t *mutex = mutex_ptr(self);
VALUE locked = Qfalse;
- GetMutexPtr(self, mutex);
if (mutex->th == 0) {
rb_thread_t *th = GET_THREAD();
@@ -225,8 +229,7 @@ static VALUE
do_mutex_lock(VALUE self, int interruptible_p)
{
rb_thread_t *th = GET_THREAD();
- rb_mutex_t *mutex;
- GetMutexPtr(self, mutex);
+ rb_mutex_t *mutex = mutex_ptr(self);
/* When running trap handler */
if (!FL_TEST_RAW(self, MUTEX_ALLOW_TRAP) &&
@@ -325,9 +328,7 @@ rb_mutex_owned_p(VALUE self)
{
VALUE owned = Qfalse;
rb_thread_t *th = GET_THREAD();
- rb_mutex_t *mutex;
-
- GetMutexPtr(self, mutex);
+ rb_mutex_t *mutex = mutex_ptr(self);
if (mutex->th == th)
owned = Qtrue;
@@ -388,8 +389,7 @@ VALUE
rb_mutex_unlock(VALUE self)
{
const char *err;
- rb_mutex_t *mutex;
- GetMutexPtr(self, mutex);
+ rb_mutex_t *mutex = mutex_ptr(self);
err = rb_mutex_unlock_th(mutex, GET_THREAD());
if (err) rb_raise(rb_eThreadError, "%s", err);
@@ -410,14 +410,13 @@ rb_mutex_abandon_keeping_mutexes(rb_thread_t *th)
static void
rb_mutex_abandon_locking_mutex(rb_thread_t *th)
{
- rb_mutex_t *mutex;
-
- if (!th->locking_mutex) return;
+ if (th->locking_mutex) {
+ rb_mutex_t *mutex = mutex_ptr(th->locking_mutex);
- GetMutexPtr(th->locking_mutex, mutex);
- if (mutex->th == th)
- rb_mutex_abandon_all(mutex);
- th->locking_mutex = Qfalse;
+ if (mutex->th == th)
+ rb_mutex_abandon_all(mutex);
+ th->locking_mutex = Qfalse;
+ }
}
static void