Mercurial > cpython-lru_cache-weakref
comparison Python/thread_lwp.h @ 61465:e38335d4df91 2.6
Recorded merge of revisions 81029 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81029 | antoine.pitrou | 2010-05-09 16:46:46 +0200 (dim., 09 mai 2010) | 3 lines
Untabify C files. Will watch buildbots.
........
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sun, 09 May 2010 15:15:40 +0000 |
| parents | 8b116a8449bd |
| children | b36cb4602e21 |
comparison
equal
deleted
inserted
replaced
| 61461:b6e03ca8a206 | 61465:e38335d4df91 |
|---|---|
| 1 | 1 |
| 2 #include <stdlib.h> | 2 #include <stdlib.h> |
| 3 #include <lwp/lwp.h> | 3 #include <lwp/lwp.h> |
| 4 #include <lwp/stackdep.h> | 4 #include <lwp/stackdep.h> |
| 5 | 5 |
| 6 #define STACKSIZE 1000 /* stacksize for a thread */ | 6 #define STACKSIZE 1000 /* stacksize for a thread */ |
| 7 #define NSTACKS 2 /* # stacks to be put in cache initially */ | 7 #define NSTACKS 2 /* # stacks to be put in cache initially */ |
| 8 | 8 |
| 9 struct lock { | 9 struct lock { |
| 10 int lock_locked; | 10 int lock_locked; |
| 11 cv_t lock_condvar; | 11 cv_t lock_condvar; |
| 12 mon_t lock_monitor; | 12 mon_t lock_monitor; |
| 13 }; | 13 }; |
| 14 | 14 |
| 15 | 15 |
| 16 /* | 16 /* |
| 17 * Initialization. | 17 * Initialization. |
| 18 */ | 18 */ |
| 19 static void PyThread__init_thread(void) | 19 static void PyThread__init_thread(void) |
| 20 { | 20 { |
| 21 lwp_setstkcache(STACKSIZE, NSTACKS); | 21 lwp_setstkcache(STACKSIZE, NSTACKS); |
| 22 } | 22 } |
| 23 | 23 |
| 24 /* | 24 /* |
| 25 * Thread support. | 25 * Thread support. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 | 28 |
| 29 long PyThread_start_new_thread(void (*func)(void *), void *arg) | 29 long PyThread_start_new_thread(void (*func)(void *), void *arg) |
| 30 { | 30 { |
| 31 thread_t tid; | 31 thread_t tid; |
| 32 int success; | 32 int success; |
| 33 dprintf(("PyThread_start_new_thread called\n")); | 33 dprintf(("PyThread_start_new_thread called\n")); |
| 34 if (!initialized) | 34 if (!initialized) |
| 35 PyThread_init_thread(); | 35 PyThread_init_thread(); |
| 36 success = lwp_create(&tid, func, MINPRIO, 0, lwp_newstk(), 1, arg); | 36 success = lwp_create(&tid, func, MINPRIO, 0, lwp_newstk(), 1, arg); |
| 37 return success < 0 ? -1 : 0; | 37 return success < 0 ? -1 : 0; |
| 38 } | 38 } |
| 39 | 39 |
| 40 long PyThread_get_thread_ident(void) | 40 long PyThread_get_thread_ident(void) |
| 41 { | 41 { |
| 42 thread_t tid; | 42 thread_t tid; |
| 43 if (!initialized) | 43 if (!initialized) |
| 44 PyThread_init_thread(); | 44 PyThread_init_thread(); |
| 45 if (lwp_self(&tid) < 0) | 45 if (lwp_self(&tid) < 0) |
| 46 return -1; | 46 return -1; |
| 47 return tid.thread_id; | 47 return tid.thread_id; |
| 48 } | 48 } |
| 49 | 49 |
| 50 static void do_PyThread_exit_thread(int no_cleanup) | 50 static void do_PyThread_exit_thread(int no_cleanup) |
| 51 { | 51 { |
| 52 dprintf(("PyThread_exit_thread called\n")); | 52 dprintf(("PyThread_exit_thread called\n")); |
| 53 if (!initialized) | 53 if (!initialized) |
| 54 if (no_cleanup) | 54 if (no_cleanup) |
| 55 _exit(0); | 55 _exit(0); |
| 56 else | 56 else |
| 57 exit(0); | 57 exit(0); |
| 58 lwp_destroy(SELF); | 58 lwp_destroy(SELF); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void PyThread_exit_thread(void) | 61 void PyThread_exit_thread(void) |
| 62 { | 62 { |
| 63 do_PyThread_exit_thread(0); | 63 do_PyThread_exit_thread(0); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void PyThread__exit_thread(void) | 66 void PyThread__exit_thread(void) |
| 67 { | 67 { |
| 68 do_PyThread_exit_thread(1); | 68 do_PyThread_exit_thread(1); |
| 69 } | 69 } |
| 70 | 70 |
| 71 #ifndef NO_EXIT_PROG | 71 #ifndef NO_EXIT_PROG |
| 72 static void do_PyThread_exit_prog(int status, int no_cleanup) | 72 static void do_PyThread_exit_prog(int status, int no_cleanup) |
| 73 { | 73 { |
| 74 dprintf(("PyThread_exit_prog(%d) called\n", status)); | 74 dprintf(("PyThread_exit_prog(%d) called\n", status)); |
| 75 if (!initialized) | 75 if (!initialized) |
| 76 if (no_cleanup) | 76 if (no_cleanup) |
| 77 _exit(status); | 77 _exit(status); |
| 78 else | 78 else |
| 79 exit(status); | 79 exit(status); |
| 80 pod_exit(status); | 80 pod_exit(status); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void PyThread_exit_prog(int status) | 83 void PyThread_exit_prog(int status) |
| 84 { | 84 { |
| 85 do_PyThread_exit_prog(status, 0); | 85 do_PyThread_exit_prog(status, 0); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void PyThread__exit_prog(int status) | 88 void PyThread__exit_prog(int status) |
| 89 { | 89 { |
| 90 do_PyThread_exit_prog(status, 1); | 90 do_PyThread_exit_prog(status, 1); |
| 91 } | 91 } |
| 92 #endif /* NO_EXIT_PROG */ | 92 #endif /* NO_EXIT_PROG */ |
| 93 | 93 |
| 94 /* | 94 /* |
| 95 * Lock support. | 95 * Lock support. |
| 96 */ | 96 */ |
| 97 PyThread_type_lock PyThread_allocate_lock(void) | 97 PyThread_type_lock PyThread_allocate_lock(void) |
| 98 { | 98 { |
| 99 struct lock *lock; | 99 struct lock *lock; |
| 100 extern char *malloc(size_t); | 100 extern char *malloc(size_t); |
| 101 | 101 |
| 102 dprintf(("PyThread_allocate_lock called\n")); | 102 dprintf(("PyThread_allocate_lock called\n")); |
| 103 if (!initialized) | 103 if (!initialized) |
| 104 PyThread_init_thread(); | 104 PyThread_init_thread(); |
| 105 | 105 |
| 106 lock = (struct lock *) malloc(sizeof(struct lock)); | 106 lock = (struct lock *) malloc(sizeof(struct lock)); |
| 107 lock->lock_locked = 0; | 107 lock->lock_locked = 0; |
| 108 (void) mon_create(&lock->lock_monitor); | 108 (void) mon_create(&lock->lock_monitor); |
| 109 (void) cv_create(&lock->lock_condvar, lock->lock_monitor); | 109 (void) cv_create(&lock->lock_condvar, lock->lock_monitor); |
| 110 dprintf(("PyThread_allocate_lock() -> %p\n", lock)); | 110 dprintf(("PyThread_allocate_lock() -> %p\n", lock)); |
| 111 return (PyThread_type_lock) lock; | 111 return (PyThread_type_lock) lock; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void PyThread_free_lock(PyThread_type_lock lock) | 114 void PyThread_free_lock(PyThread_type_lock lock) |
| 115 { | 115 { |
| 116 dprintf(("PyThread_free_lock(%p) called\n", lock)); | 116 dprintf(("PyThread_free_lock(%p) called\n", lock)); |
| 117 mon_destroy(((struct lock *) lock)->lock_monitor); | 117 mon_destroy(((struct lock *) lock)->lock_monitor); |
| 118 free((char *) lock); | 118 free((char *) lock); |
| 119 } | 119 } |
| 120 | 120 |
| 121 int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) | 121 int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) |
| 122 { | 122 { |
| 123 int success; | 123 int success; |
| 124 | 124 |
| 125 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); | 125 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); |
| 126 success = 0; | 126 success = 0; |
| 127 | 127 |
| 128 (void) mon_enter(((struct lock *) lock)->lock_monitor); | 128 (void) mon_enter(((struct lock *) lock)->lock_monitor); |
| 129 if (waitflag) | 129 if (waitflag) |
| 130 while (((struct lock *) lock)->lock_locked) | 130 while (((struct lock *) lock)->lock_locked) |
| 131 cv_wait(((struct lock *) lock)->lock_condvar); | 131 cv_wait(((struct lock *) lock)->lock_condvar); |
| 132 if (!((struct lock *) lock)->lock_locked) { | 132 if (!((struct lock *) lock)->lock_locked) { |
| 133 success = 1; | 133 success = 1; |
| 134 ((struct lock *) lock)->lock_locked = 1; | 134 ((struct lock *) lock)->lock_locked = 1; |
| 135 } | 135 } |
| 136 cv_broadcast(((struct lock *) lock)->lock_condvar); | 136 cv_broadcast(((struct lock *) lock)->lock_condvar); |
| 137 mon_exit(((struct lock *) lock)->lock_monitor); | 137 mon_exit(((struct lock *) lock)->lock_monitor); |
| 138 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); | 138 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); |
| 139 return success; | 139 return success; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void PyThread_release_lock(PyThread_type_lock lock) | 142 void PyThread_release_lock(PyThread_type_lock lock) |
| 143 { | 143 { |
| 144 dprintf(("PyThread_release_lock(%p) called\n", lock)); | 144 dprintf(("PyThread_release_lock(%p) called\n", lock)); |
| 145 (void) mon_enter(((struct lock *) lock)->lock_monitor); | 145 (void) mon_enter(((struct lock *) lock)->lock_monitor); |
| 146 ((struct lock *) lock)->lock_locked = 0; | 146 ((struct lock *) lock)->lock_locked = 0; |
| 147 cv_broadcast(((struct lock *) lock)->lock_condvar); | 147 cv_broadcast(((struct lock *) lock)->lock_condvar); |
| 148 mon_exit(((struct lock *) lock)->lock_monitor); | 148 mon_exit(((struct lock *) lock)->lock_monitor); |
| 149 } | 149 } |
