Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Initialization. |
| 4 | */ |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 5 | static void |
| 6 | PyThread__init_thread(void) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 7 | { |
| 8 | } |
| 9 | |
| 10 | /* |
| 11 | * Thread support. |
| 12 | */ |
Guido van Rossum | 3c28863 | 2001-10-16 21:13:49 +0000 | [diff] [blame] | 13 | long |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 14 | PyThread_start_new_thread(void (*func)(void *), void *arg) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 15 | { |
| 16 | int success = 0; /* init not needed when SOLARIS_THREADS and */ |
| 17 | /* C_THREADS implemented properly */ |
| 18 | |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 19 | dprintf(("PyThread_start_new_thread called\n")); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 20 | if (!initialized) |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 21 | PyThread_init_thread(); |
Guido van Rossum | 3c28863 | 2001-10-16 21:13:49 +0000 | [diff] [blame] | 22 | return success < 0 ? -1 : 0; |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 25 | long |
| 26 | PyThread_get_thread_ident(void) |
Guido van Rossum | e944da8 | 1994-05-23 12:43:41 +0000 | [diff] [blame] | 27 | { |
| 28 | if (!initialized) |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 29 | PyThread_init_thread(); |
Guido van Rossum | e944da8 | 1994-05-23 12:43:41 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 32 | static |
| 33 | void do_PyThread_exit_thread(int no_cleanup) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 34 | { |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 35 | dprintf(("PyThread_exit_thread called\n")); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 36 | if (!initialized) |
| 37 | if (no_cleanup) |
| 38 | _exit(0); |
| 39 | else |
| 40 | exit(0); |
| 41 | } |
| 42 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 43 | void |
| 44 | PyThread_exit_thread(void) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 45 | { |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 46 | do_PyThread_exit_thread(0); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 49 | void |
| 50 | PyThread__exit_thread(void) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 51 | { |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 52 | do_PyThread_exit_thread(1); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | #ifndef NO_EXIT_PROG |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 56 | static |
| 57 | void do_PyThread_exit_prog(int status, int no_cleanup) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 58 | { |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 59 | dprintf(("PyThread_exit_prog(%d) called\n", status)); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 60 | if (!initialized) |
| 61 | if (no_cleanup) |
| 62 | _exit(status); |
| 63 | else |
| 64 | exit(status); |
| 65 | } |
| 66 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 67 | void |
| 68 | PyThread_exit_prog(int status) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 69 | { |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 70 | do_PyThread_exit_prog(status, 0); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 73 | void |
| 74 | PyThread__exit_prog(int status) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 75 | { |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 76 | do_PyThread_exit_prog(status, 1); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 77 | } |
| 78 | #endif /* NO_EXIT_PROG */ |
| 79 | |
| 80 | /* |
| 81 | * Lock support. |
| 82 | */ |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 83 | PyThread_type_lock |
| 84 | PyThread_allocate_lock(void) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 85 | { |
| 86 | |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 87 | dprintf(("PyThread_allocate_lock called\n")); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 88 | if (!initialized) |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 89 | PyThread_init_thread(); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 90 | |
Fred Drake | a44d353 | 2000-06-30 15:01:00 +0000 | [diff] [blame] | 91 | dprintf(("PyThread_allocate_lock() -> %p\n", lock)); |
Guido van Rossum | 65d5b57 | 1998-12-21 19:32:43 +0000 | [diff] [blame] | 92 | return (PyThread_type_lock) lock; |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 95 | void |
| 96 | PyThread_free_lock(PyThread_type_lock lock) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 97 | { |
Fred Drake | a44d353 | 2000-06-30 15:01:00 +0000 | [diff] [blame] | 98 | dprintf(("PyThread_free_lock(%p) called\n", lock)); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 101 | int |
| 102 | PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 103 | { |
| 104 | int success; |
| 105 | |
Fred Drake | a44d353 | 2000-06-30 15:01:00 +0000 | [diff] [blame] | 106 | dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); |
| 107 | dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 108 | return success; |
| 109 | } |
| 110 | |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 111 | void |
| 112 | PyThread_release_lock(PyThread_type_lock lock) |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 113 | { |
Fred Drake | a44d353 | 2000-06-30 15:01:00 +0000 | [diff] [blame] | 114 | dprintf(("PyThread_release_lock(%p) called\n", lock)); |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 115 | } |