ruby-changes:50075
From: k0kubun <ko1@a...>
Date: Sun, 4 Feb 2018 17:25:06 +0900 (JST)
Subject: [ruby-changes:50075] k0kubun:r62193 (trunk): mjit.c: use InterlockedExchangePointer
k0kubun 2018-02-04 17:24:58 +0900 (Sun, 04 Feb 2018) New Revision: 62193 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62193 Log: mjit.c: use InterlockedExchangePointer for Windows, if it's available. Before this commit, Windows builds printed following warnings. mjit.c ../mjit.c(802) : warning C4047: 'function' : 'volatile LONG *' differs in levels of indirection from 'void **' ../mjit.c(802) : warning C4024: '_InterlockedExchange' : different types for formal and actual parameter 1 ../mjit.c(802) : warning C4047: 'function' : 'LONG' differs in levels of indirection from 'void *' ../mjit.c(802) : warning C4024: '_InterlockedExchange' : different types for formal and actual parameter 2 ATOMIC_SET is using InterlockedExchange which takes LONG as its value. As InterlockedExchangePointer takes PVOID, we should use this to set function pointer atomically. Modified files: trunk/mjit.c Index: mjit.c =================================================================== --- mjit.c (revision 62192) +++ mjit.c (revision 62193) @@ -118,6 +118,17 @@ typedef intptr_t pid_t; https://github.com/ruby/ruby/blob/trunk/mjit.c#L118 #define va_copy(dest, src) ((dest) = (src)) #endif +/* Atomically set function pointer if possible. */ +#ifdef _WIN32 +# ifdef InterlockedExchangePointer +# define MJIT_ATOMIC_SET(var, val) InterlockedExchangePointer(&(var), val) +# else +# define MJIT_ATOMIC_SET(var, val) (void)((var) = (val)) +# endif +#else +# define MJIT_ATOMIC_SET(var, val) ATOMIC_SET(var, val) +#endif + /* A copy of MJIT portion of MRI options since MJIT initialization. We need them as MJIT threads still can work when the most MRI data were freed. */ @@ -800,7 +811,7 @@ worker(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L811 CRITICAL_SECTION_START(3, "in jit func replace"); if (node->unit->iseq) { /* Check whether GCed or not */ /* Usage of jit_code might be not in a critical section. */ - ATOMIC_SET(node->unit->iseq->body->jit_func, func); + MJIT_ATOMIC_SET(node->unit->iseq->body->jit_func, func); } remove_from_list(node, &unit_queue); CRITICAL_SECTION_FINISH(3, "in jit func replace"); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/