Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Initialization. |
| 3 | */ |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 4 | static void |
| 5 | PyThread__init_thread(void) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 6 | { |
| 7 | } |
| 8 | |
| 9 | /* |
| 10 | * Thread support. |
| 11 | */ |
Guido van Rossum | 3c28863 | 2001-10-16 21:13:49 +0000 | [diff] [blame] | 12 | long |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 13 | PyThread_start_new_thread(void (*func)(void *), void *arg) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 14 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 15 | int success = 0; /* init not needed when SOLARIS_THREADS and */ |
| 16 | /* C_THREADS implemented properly */ |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 17 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 18 | dprintf(("PyThread_start_new_thread called\n")); |
| 19 | if (!initialized) |
| 20 | PyThread_init_thread(); |
| 21 | return success < 0 ? -1 : 0; |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 24 | long |
| 25 | PyThread_get_thread_ident(void) |
Guido van Rossum | e944da8 | 1994-05-23 12:43:41 +0000 | [diff] [blame] | 26 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 27 | if (!initialized) |
| 28 | PyThread_init_thread(); |
Guido van Rossum | e944da8 | 1994-05-23 12:43:41 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 31 | void |
| 32 | PyThread_exit_thread(void) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 33 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 34 | dprintf(("PyThread_exit_thread called\n")); |
| 35 | if (!initialized) |
| 36 | exit(0); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 39 | /* |
| 40 | * Lock support. |
| 41 | */ |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 42 | PyThread_type_lock |
| 43 | PyThread_allocate_lock(void) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 44 | { |
| 45 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 46 | dprintf(("PyThread_allocate_lock called\n")); |
| 47 | if (!initialized) |
| 48 | PyThread_init_thread(); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 49 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 50 | dprintf(("PyThread_allocate_lock() -> %p\n", lock)); |
| 51 | return (PyThread_type_lock) lock; |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 54 | void |
| 55 | PyThread_free_lock(PyThread_type_lock lock) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 56 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 57 | dprintf(("PyThread_free_lock(%p) called\n", lock)); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 60 | int |
| 61 | PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 62 | { |
Antoine Pitrou | 285a163 | 2014-04-28 21:12:11 +0200 | [diff] [blame] | 63 | return PyThread_acquire_lock_timed(lock, waitflag ? -1 : 0, 0); |
| 64 | } |
| 65 | |
| 66 | PyLockStatus |
| 67 | PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds, |
| 68 | int intr_flag) |
| 69 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 70 | int success; |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 71 | |
Antoine Pitrou | 285a163 | 2014-04-28 21:12:11 +0200 | [diff] [blame] | 72 | dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) called\n", lock, microseconds, intr_flag)); |
| 73 | dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) -> %d\n", |
| 74 | lock, microseconds, intr_flag, success)); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 75 | return success; |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 78 | void |
| 79 | PyThread_release_lock(PyThread_type_lock lock) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 80 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 81 | dprintf(("PyThread_release_lock(%p) called\n", lock)); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 82 | } |
Antoine Pitrou | 285a163 | 2014-04-28 21:12:11 +0200 | [diff] [blame] | 83 | |
| 84 | /* The following are only needed if native TLS support exists */ |
| 85 | #define Py_HAVE_NATIVE_TLS |
| 86 | |
| 87 | #ifdef Py_HAVE_NATIVE_TLS |
| 88 | int |
| 89 | PyThread_create_key(void) |
| 90 | { |
| 91 | int result; |
| 92 | return result; |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | PyThread_delete_key(int key) |
| 97 | { |
| 98 | |
| 99 | } |
| 100 | |
| 101 | int |
| 102 | PyThread_set_key_value(int key, void *value) |
| 103 | { |
| 104 | int ok; |
| 105 | |
| 106 | /* A failure in this case returns -1 */ |
| 107 | if (!ok) |
| 108 | return -1; |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | void * |
| 113 | PyThread_get_key_value(int key) |
| 114 | { |
| 115 | void *result; |
| 116 | |
| 117 | return result; |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | PyThread_delete_key_value(int key) |
| 122 | { |
| 123 | |
| 124 | } |
| 125 | |
| 126 | void |
| 127 | PyThread_ReInitTLS(void) |
| 128 | { |
| 129 | |
| 130 | } |
| 131 | |
| 132 | #endif |