Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby32/include/ruby
File: thread_native.h
#ifndef RUBY_THREAD_NATIVE_H /*-*-C++-*-vi:se ft=cpp:*/
[0] Fix | Delete
#define RUBY_THREAD_NATIVE_H 1
[1] Fix | Delete
/**
[2] Fix | Delete
* @file
[3] Fix | Delete
* @author $Author: ko1 $
[4] Fix | Delete
* @date Wed May 14 19:37:31 2014
[5] Fix | Delete
* @copyright Copyright (C) 2014 Yukihiro Matsumoto
[6] Fix | Delete
* @copyright This file is a part of the programming language Ruby.
[7] Fix | Delete
* Permission is hereby granted, to either redistribute and/or
[8] Fix | Delete
* modify this file, provided that the conditions mentioned in the
[9] Fix | Delete
* file COPYING are met. Consult the file for details.
[10] Fix | Delete
*
[11] Fix | Delete
* This file contains wrapper APIs for native thread primitives
[12] Fix | Delete
* which Ruby interpreter uses.
[13] Fix | Delete
*
[14] Fix | Delete
* Now, we only support pthread and Windows threads.
[15] Fix | Delete
*
[16] Fix | Delete
* If you want to use Ruby's Mutex and so on to synchronize Ruby Threads,
[17] Fix | Delete
* please use Mutex directly.
[18] Fix | Delete
*/
[19] Fix | Delete
[20] Fix | Delete
#if defined(_WIN32)
[21] Fix | Delete
#include <windows.h>
[22] Fix | Delete
typedef HANDLE rb_nativethread_id_t;
[23] Fix | Delete
[24] Fix | Delete
typedef union rb_thread_lock_union {
[25] Fix | Delete
HANDLE mutex;
[26] Fix | Delete
CRITICAL_SECTION crit;
[27] Fix | Delete
} rb_nativethread_lock_t;
[28] Fix | Delete
[29] Fix | Delete
typedef struct rb_thread_cond_struct rb_nativethread_cond_t;
[30] Fix | Delete
[31] Fix | Delete
#elif defined(HAVE_PTHREAD_H)
[32] Fix | Delete
[33] Fix | Delete
#include <pthread.h>
[34] Fix | Delete
typedef pthread_t rb_nativethread_id_t;
[35] Fix | Delete
typedef pthread_mutex_t rb_nativethread_lock_t;
[36] Fix | Delete
typedef pthread_cond_t rb_nativethread_cond_t;
[37] Fix | Delete
[38] Fix | Delete
#elif defined(__wasi__) // no-thread platforms
[39] Fix | Delete
[40] Fix | Delete
typedef struct rb_nativethread_id_t *rb_nativethread_id_t;
[41] Fix | Delete
typedef struct rb_nativethread_lock_t *rb_nativethread_lock_t;
[42] Fix | Delete
typedef struct rb_nativethread_cond_t *rb_nativethread_cond_t;
[43] Fix | Delete
[44] Fix | Delete
#elif defined(__DOXYGEN__)
[45] Fix | Delete
[46] Fix | Delete
/** Opaque type that holds an ID of a native thread. */
[47] Fix | Delete
struct rb_nativethread_id_t;
[48] Fix | Delete
[49] Fix | Delete
/** Opaque type that holds a lock. */
[50] Fix | Delete
struct rb_nativethread_lock_t;
[51] Fix | Delete
[52] Fix | Delete
/** Opaque type that holds a condition variable. */
[53] Fix | Delete
struct rb_nativethread_cond_t;
[54] Fix | Delete
[55] Fix | Delete
#else
[56] Fix | Delete
#error "unsupported thread type"
[57] Fix | Delete
[58] Fix | Delete
#endif
[59] Fix | Delete
[60] Fix | Delete
RBIMPL_SYMBOL_EXPORT_BEGIN()
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Queries the ID of the native thread that is calling this function.
[64] Fix | Delete
*
[65] Fix | Delete
* @return The caller thread's native ID.
[66] Fix | Delete
*/
[67] Fix | Delete
rb_nativethread_id_t rb_nativethread_self(void);
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Fills the passed lock with an initial value.
[71] Fix | Delete
*
[72] Fix | Delete
* @param[out] lock A mutex to initialise.
[73] Fix | Delete
* @post `lock` is updated to its initial state.
[74] Fix | Delete
*
[75] Fix | Delete
* @internal
[76] Fix | Delete
*
[77] Fix | Delete
* There is no data structure that analogous to pthread_once_t in ruby. It is
[78] Fix | Delete
* pretty much tricky (if not impossible) to properly initialise a mutex
[79] Fix | Delete
* exactly once.
[80] Fix | Delete
*/
[81] Fix | Delete
void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock);
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Destroys the passed mutex.
[85] Fix | Delete
*
[86] Fix | Delete
* @param[out] lock A mutex to kill.
[87] Fix | Delete
* @post `lock` is no longer eligible for other functions.
[88] Fix | Delete
*
[89] Fix | Delete
* @internal
[90] Fix | Delete
*
[91] Fix | Delete
* It is an undefined behaviour (see `pthread_mutex_destroy(3posix)`) to
[92] Fix | Delete
* destroy a locked mutex. So it has to be unlocked. But an unlocked mutex
[93] Fix | Delete
* can of course be locked by another thread. That's the ultimate reason why
[94] Fix | Delete
* we do mutex. There is an inevitable race condition here. 2017 edition of
[95] Fix | Delete
* IEEE 1003.1 issue 7 says in its rationale that "care must be taken". Care?
[96] Fix | Delete
* How?
[97] Fix | Delete
*
[98] Fix | Delete
* @shyouhei thinks that POSIX is broken by design.
[99] Fix | Delete
*/
[100] Fix | Delete
void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock);
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Blocks until the current thread obtains a lock.
[104] Fix | Delete
*
[105] Fix | Delete
* @param[out] lock A mutex to lock.
[106] Fix | Delete
* @post `lock` is owned by the current native thread.
[107] Fix | Delete
*/
[108] Fix | Delete
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock);
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Releases a lock.
[112] Fix | Delete
*
[113] Fix | Delete
* @param[out] lock A mutex to unlock.
[114] Fix | Delete
* @pre `lock` is owned by the current native thread.
[115] Fix | Delete
* @post `lock` is not owned by the current native thread.
[116] Fix | Delete
*/
[117] Fix | Delete
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock);
[118] Fix | Delete
[119] Fix | Delete
/** @alias{rb_nativethread_lock_lock} */
[120] Fix | Delete
void rb_native_mutex_lock(rb_nativethread_lock_t *lock);
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Identical to rb_native_mutex_lock(), except it doesn't block in case
[124] Fix | Delete
* rb_native_mutex_lock() would.
[125] Fix | Delete
*
[126] Fix | Delete
* @param[out] lock A mutex to lock.
[127] Fix | Delete
* @retval 0 `lock` is successfully owned by the current thread.
[128] Fix | Delete
* @retval EBUSY `lock` is owned by someone else.
[129] Fix | Delete
*/
[130] Fix | Delete
int rb_native_mutex_trylock(rb_nativethread_lock_t *lock);
[131] Fix | Delete
[132] Fix | Delete
/** @alias{rb_nativethread_lock_unlock} */
[133] Fix | Delete
void rb_native_mutex_unlock(rb_nativethread_lock_t *lock);
[134] Fix | Delete
[135] Fix | Delete
/** @alias{rb_nativethread_lock_initialize} */
[136] Fix | Delete
void rb_native_mutex_initialize(rb_nativethread_lock_t *lock);
[137] Fix | Delete
[138] Fix | Delete
/** @alias{rb_nativethread_lock_destroy} */
[139] Fix | Delete
void rb_native_mutex_destroy(rb_nativethread_lock_t *lock);
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Signals a condition variable.
[143] Fix | Delete
*
[144] Fix | Delete
* @param[out] cond A condition variable to ping.
[145] Fix | Delete
* @post More than one threads waiting for `cond` gets signalled.
[146] Fix | Delete
* @note This function can spuriously wake multiple threads up.
[147] Fix | Delete
* `pthread_cond_signal(3posix)` says it can even be "impossible
[148] Fix | Delete
* to avoid the unblocking of more than one thread blocked on a
[149] Fix | Delete
* condition variable". Just brace spurious wakeups.
[150] Fix | Delete
*/
[151] Fix | Delete
void rb_native_cond_signal(rb_nativethread_cond_t *cond);
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* Signals a condition variable.
[155] Fix | Delete
*
[156] Fix | Delete
* @param[out] cond A condition variable to ping.
[157] Fix | Delete
* @post All threads waiting for `cond` gets signalled.
[158] Fix | Delete
*/
[159] Fix | Delete
void rb_native_cond_broadcast(rb_nativethread_cond_t *cond);
[160] Fix | Delete
[161] Fix | Delete
/**
[162] Fix | Delete
* Waits for the passed condition variable to be signalled.
[163] Fix | Delete
*
[164] Fix | Delete
* @param[out] cond A condition variable to wait.
[165] Fix | Delete
* @param[out] mutex A mutex.
[166] Fix | Delete
* @pre `mutex` is owned by the current thread.
[167] Fix | Delete
* @post `mutex` is owned by the current thread.
[168] Fix | Delete
* @note This can wake up spuriously.
[169] Fix | Delete
*/
[170] Fix | Delete
void rb_native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex);
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Identical to rb_native_cond_wait(), except it additionally takes timeout in
[174] Fix | Delete
* msec resolution. Timeouts can be detected by catching exceptions.
[175] Fix | Delete
*
[176] Fix | Delete
* @param[out] cond A condition variable to wait.
[177] Fix | Delete
* @param[out] mutex A mutex.
[178] Fix | Delete
* @param[in] msec Timeout.
[179] Fix | Delete
* @exception rb_eSystemCallError `Errno::ETIMEDOUT` for timeout.
[180] Fix | Delete
* @pre `mutex` is owned by the current thread.
[181] Fix | Delete
* @post `mutex` is owned by the current thread.
[182] Fix | Delete
* @note This can wake up spuriously.
[183] Fix | Delete
*/
[184] Fix | Delete
void rb_native_cond_timedwait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex, unsigned long msec);
[185] Fix | Delete
[186] Fix | Delete
/**
[187] Fix | Delete
* Fills the passed condition variable with an initial value.
[188] Fix | Delete
*
[189] Fix | Delete
* @param[out] cond A condition variable to initialise.
[190] Fix | Delete
* @post `cond` is updated to its initial state.
[191] Fix | Delete
*/
[192] Fix | Delete
void rb_native_cond_initialize(rb_nativethread_cond_t *cond);
[193] Fix | Delete
[194] Fix | Delete
/**
[195] Fix | Delete
* Destroys the passed condition variable.
[196] Fix | Delete
*
[197] Fix | Delete
* @param[out] cond A condition variable to kill.
[198] Fix | Delete
* @post `cond` is no longer eligible for other functions.
[199] Fix | Delete
*/
[200] Fix | Delete
void rb_native_cond_destroy(rb_nativethread_cond_t *cond);
[201] Fix | Delete
[202] Fix | Delete
RBIMPL_SYMBOL_EXPORT_END()
[203] Fix | Delete
#endif
[204] Fix | Delete
[205] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function