fix public interface

To make some kind of Ractor related extensions, some functions
should be exposed.

* include/ruby/thread_native.h
  * rb_native_mutex_*
  * rb_native_cond_*
* include/ruby/ractor.h
  * RB_OBJ_SHAREABLE_P(obj)
  * rb_ractor_shareable_p(obj)
  * rb_ractor_std*()
  * rb_cRactor

and rm ractor_pub.h
and rename srcdir/ractor.h to srcdir/ractor_core.h
    (to avoid conflict with include/ruby/ractor.h)
This commit is contained in:
Koichi Sasada 2020-11-17 16:40:47 +09:00
parent 0683912db8
commit 5e3259ea74
Notes: git 2020-11-18 03:53:22 +09:00
23 changed files with 121 additions and 135 deletions

View file

@ -52,12 +52,12 @@ w32_error(const char *func)
}
static int
w32_mutex_lock(HANDLE lock)
w32_mutex_lock(HANDLE lock, bool try)
{
DWORD result;
while (1) {
thread_debug("rb_native_mutex_lock: %p\n", lock);
result = w32_wait_events(&lock, 1, INFINITE, 0);
result = w32_wait_events(&lock, 1, try ? 0 : INFINITE, 0);
switch (result) {
case WAIT_OBJECT_0:
/* get mutex object */
@ -70,7 +70,7 @@ w32_mutex_lock(HANDLE lock)
return 0;
case WAIT_TIMEOUT:
thread_debug("timeout mutex: %p\n", lock);
break;
return EBUSY;
case WAIT_ABANDONED:
rb_bug("win32_mutex_lock: WAIT_ABANDONED");
break;
@ -97,7 +97,7 @@ w32_mutex_create(void)
static void
gvl_acquire(rb_global_vm_lock_t *gvl, rb_thread_t *th)
{
w32_mutex_lock(gvl->lock);
w32_mutex_lock(gvl->lock, false);
if (GVL_DEBUG) fprintf(stderr, "gvl acquire (%p): acquire\n", th);
}
@ -323,12 +323,22 @@ void
rb_native_mutex_lock(rb_nativethread_lock_t *lock)
{
#if USE_WIN32_MUTEX
w32_mutex_lock(lock->mutex);
w32_mutex_lock(lock->mutex, false);
#else
EnterCriticalSection(&lock->crit);
#endif
}
int
rb_native_mutex_trylock(rb_nativethread_lock_t *lock)
{
#if USE_WIN32_MUTEX
return w32_mutex_lock(lock->mutex, true);
#else
return TryEnterCriticalSection(&lock->crit) == 0 ? EBUSY : 0;
#endif
}
void
rb_native_mutex_unlock(rb_nativethread_lock_t *lock)
{
@ -340,27 +350,6 @@ rb_native_mutex_unlock(rb_nativethread_lock_t *lock)
#endif
}
RBIMPL_ATTR_MAYBE_UNUSED()
static int
native_mutex_trylock(rb_nativethread_lock_t *lock)
{
#if USE_WIN32_MUTEX
int result;
thread_debug("native_mutex_trylock: %p\n", lock->mutex);
result = w32_wait_events(&lock->mutex, 1, 1, 0);
thread_debug("native_mutex_trylock result: %d\n", result);
switch (result) {
case WAIT_OBJECT_0:
return 0;
case WAIT_TIMEOUT:
return EBUSY;
}
return EINVAL;
#else
return TryEnterCriticalSection(&lock->crit) == 0;
#endif
}
void
rb_native_mutex_initialize(rb_nativethread_lock_t *lock)
{