1 /** 2 Mirror _pythread.h 3 */ 4 module deimos.python.pythread; 5 6 import deimos.python.pyport; 7 8 extern(C): 9 // Python-header-file: Include/pythread.h: 10 11 version(Python_3_2_Or_Later) { 12 /** Return status codes for Python lock acquisition. Chosen for maximum 13 * backwards compatibility, ie failure -> 0, success -> 1. */ 14 /// Availability: >= 3.2 15 enum PyLockStatus { 16 /// _ 17 PY_LOCK_FAILURE = 0, 18 /// _ 19 PY_LOCK_ACQUIRED = 1, 20 /// _ 21 PY_LOCK_INTR 22 } 23 } 24 25 /// _ 26 alias void* PyThread_type_lock; 27 /// _ 28 alias void* PyThread_type_sema; 29 30 /// _ 31 void PyThread_init_thread(); 32 /// _ 33 C_long PyThread_start_new_thread(void function(void*), void*); 34 /// _ 35 void PyThread_exit_thread(); 36 /// _ 37 void PyThread__PyThread_exit_thread(); 38 /// _ 39 C_long PyThread_get_thread_ident(); 40 41 /// _ 42 PyThread_type_lock PyThread_allocate_lock(); 43 /// _ 44 void PyThread_free_lock(PyThread_type_lock); 45 /// _ 46 int PyThread_acquire_lock(PyThread_type_lock, int); 47 /// _ 48 enum WAIT_LOCK = 1; 49 /// _ 50 enum NOWAIT_LOCK = 0; 51 version(Python_3_2_Or_Later) { 52 /** PY_TIMEOUT_T is the integral type used to specify timeouts when waiting 53 on a lock (see PyThread_acquire_lock_timed() below). 54 PY_TIMEOUT_MAX is the highest usable value (in microseconds) of that 55 type, and depends on the system threading API. 56 57 NOTE: this isn't the same value as `_thread.TIMEOUT_MAX`. The _thread 58 module exposes a higher-level API, with timeouts expressed in seconds 59 and floating-point numbers allowed. 60 */ 61 /// Availability: >= 3.2 62 alias C_long PY_TIMEOUT_T; 63 64 /* In the NT API, the timeout is a DWORD and is expressed in milliseconds */ 65 /+ ?? 66 #if defined (NT_THREADS) 67 #if (Py_LL(0xFFFFFFFF) * 1000 < PY_TIMEOUT_MAX) 68 #undef PY_TIMEOUT_MAX 69 #define PY_TIMEOUT_MAX (Py_LL(0xFFFFFFFF) * 1000) 70 #endif 71 #endif 72 +/ 73 74 /* If microseconds == 0, the call is non-blocking: it returns immediately 75 even when the lock can't be acquired. 76 If microseconds > 0, the call waits up to the specified duration. 77 If microseconds < 0, the call waits until success (or abnormal failure) 78 79 microseconds must be less than PY_TIMEOUT_MAX. Behaviour otherwise is 80 undefined. 81 82 If intr_flag is true and the acquire is interrupted by a signal, then the 83 call will return PY_LOCK_INTR. The caller may reattempt to acquire the 84 lock. 85 */ 86 /// Availability: >= 3.2 87 PyLockStatus PyThread_acquire_lock_timed( 88 PyThread_type_lock, 89 PY_TIMEOUT_T microseconds, 90 int intr_flag); 91 92 } 93 /// _ 94 void PyThread_release_lock(PyThread_type_lock); 95 96 version(Python_2_5_Or_Later){ 97 /// Availability: >= 2.5 98 size_t PyThread_get_stacksize(); 99 /// Availability: >= 2.5 100 int PyThread_set_stacksize(size_t); 101 } 102 103 /// _ 104 void PyThread_exit_prog(int); 105 /// _ 106 void PyThread__PyThread_exit_prog(int); 107 108 /// _ 109 int PyThread_create_key(); 110 /// _ 111 void PyThread_delete_key(int); 112 /// _ 113 int PyThread_set_key_value(int, void*); 114 /// _ 115 void* PyThread_get_key_value(int); 116 /// _ 117 void PyThread_delete_key_value(int key); 118 119 version(Python_2_5_Or_Later) { 120 /// Availability: >= 2.5 121 void PyThread_ReInitTLS(); 122 } 123