Changeset 391 for python/trunk/Python/thread_os2.h
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Python/thread_os2.h
r2 r391 17 17 /* default thread stack size of 64kB */ 18 18 #if !defined(THREAD_STACK_SIZE) 19 #define THREAD_STACK_SIZE0x1000020 #endif 21 22 #define OS2_STACKSIZE(x) 19 #define THREAD_STACK_SIZE 0x10000 20 #endif 21 22 #define OS2_STACKSIZE(x) (x ? x : THREAD_STACK_SIZE) 23 23 24 24 /* … … 36 36 PyThread_start_new_thread(void (*func)(void *), void *arg) 37 37 { 38 39 40 41 42 43 44 45 46 47 48 49 38 int thread_id; 39 40 thread_id = _beginthread(func, 41 NULL, 42 OS2_STACKSIZE(_pythread_stacksize), 43 arg); 44 45 if (thread_id == -1) { 46 dprintf(("_beginthread failed. return %ld\n", errno)); 47 } 48 49 return thread_id; 50 50 } 51 51 … … 54 54 { 55 55 #if !defined(PYCC_GCC) 56 PPIB pib; 57 PTIB tib; 58 #endif 59 60 if (!initialized) 61 PyThread_init_thread(); 62 63 #if defined(PYCC_GCC) 64 return _gettid(); 65 #else 66 DosGetInfoBlocks(&tib, &pib); 67 return tib->tib_ptib2->tib2_ultid; 68 #endif 69 } 70 71 static void 72 do_PyThread_exit_thread(int no_cleanup) 73 { 74 dprintf(("%ld: PyThread_exit_thread called\n", 75 PyThread_get_thread_ident())); 76 if (!initialized) 77 if (no_cleanup) 78 _exit(0); 79 else 80 exit(0); 81 _endthread(); 82 } 83 84 void 56 PPIB pib; 57 PTIB tib; 58 #endif 59 60 if (!initialized) 61 PyThread_init_thread(); 62 63 #if defined(PYCC_GCC) 64 return _gettid(); 65 #else 66 DosGetInfoBlocks(&tib, &pib); 67 return tib->tib_ptib2->tib2_ultid; 68 #endif 69 } 70 71 void 85 72 PyThread_exit_thread(void) 86 73 { 87 do_PyThread_exit_thread(0); 88 } 89 90 void 91 PyThread__exit_thread(void) 92 { 93 do_PyThread_exit_thread(1); 94 } 95 96 #ifndef NO_EXIT_PROG 97 static void 98 do_PyThread_exit_prog(int status, int no_cleanup) 99 { 100 dprintf(("PyThread_exit_prog(%d) called\n", status)); 101 if (!initialized) 102 if (no_cleanup) 103 _exit(status); 104 else 105 exit(status); 106 } 107 108 void 109 PyThread_exit_prog(int status) 110 { 111 do_PyThread_exit_prog(status, 0); 112 } 113 114 void 115 PyThread__exit_prog(int status) 116 { 117 do_PyThread_exit_prog(status, 1); 118 } 119 #endif /* NO_EXIT_PROG */ 74 dprintf(("%ld: PyThread_exit_thread called\n", 75 PyThread_get_thread_ident())); 76 if (!initialized) 77 exit(0); 78 _endthread(); 79 } 120 80 121 81 /* 122 82 * Lock support. This is implemented with an event semaphore and critical 123 * sections to make it behave more like a posix mutex than its OS/2 83 * sections to make it behave more like a posix mutex than its OS/2 124 84 * counterparts. 125 85 */ 126 86 127 87 typedef struct os2_lock_t { 128 129 88 int is_set; 89 HEV changed; 130 90 } *type_os2_lock; 131 91 132 PyThread_type_lock 92 PyThread_type_lock 133 93 PyThread_allocate_lock(void) 134 94 { 135 95 #if defined(PYCC_GCC) 136 137 138 139 140 141 142 143 144 145 146 147 #else 148 149 150 151 152 153 154 155 156 157 158 159 dprintf(("%ld: PyThread_allocate_lock() -> %p\n", 160 PyThread_get_thread_ident(), 161 162 163 164 #endif 165 } 166 167 void 96 _fmutex *sem = malloc(sizeof(_fmutex)); 97 if (!initialized) 98 PyThread_init_thread(); 99 dprintf(("%ld: PyThread_allocate_lock() -> %lx\n", 100 PyThread_get_thread_ident(), 101 (long)sem)); 102 if (_fmutex_create(sem, 0)) { 103 free(sem); 104 sem = NULL; 105 } 106 return (PyThread_type_lock)sem; 107 #else 108 APIRET rc; 109 type_os2_lock lock = (type_os2_lock)malloc(sizeof(struct os2_lock_t)); 110 111 dprintf(("PyThread_allocate_lock called\n")); 112 if (!initialized) 113 PyThread_init_thread(); 114 115 lock->is_set = 0; 116 117 DosCreateEventSem(NULL, &lock->changed, 0, 0); 118 119 dprintf(("%ld: PyThread_allocate_lock() -> %p\n", 120 PyThread_get_thread_ident(), 121 lock->changed)); 122 123 return (PyThread_type_lock)lock; 124 #endif 125 } 126 127 void 168 128 PyThread_free_lock(PyThread_type_lock aLock) 169 129 { 170 130 #if !defined(PYCC_GCC) 171 172 #endif 173 174 175 176 177 #if defined(PYCC_GCC) 178 179 180 181 182 #else 183 184 131 type_os2_lock lock = (type_os2_lock)aLock; 132 #endif 133 134 dprintf(("%ld: PyThread_free_lock(%p) called\n", 135 PyThread_get_thread_ident(),aLock)); 136 137 #if defined(PYCC_GCC) 138 if (aLock) { 139 _fmutex_close((_fmutex *)aLock); 140 free((_fmutex *)aLock); 141 } 142 #else 143 DosCloseEventSem(lock->changed); 144 free(aLock); 185 145 #endif 186 146 } … … 191 151 * and 0 if the lock was not acquired. 192 152 */ 193 int 153 int 194 154 PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) 195 155 { 196 156 #if !defined(PYCC_GCC) 197 198 199 200 201 202 #endif 203 204 205 206 207 208 209 #if defined(PYCC_GCC) 210 211 212 213 214 #else 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 #endif 240 241 157 int done = 0; 158 ULONG count; 159 PID pid = 0; 160 TID tid = 0; 161 type_os2_lock lock = (type_os2_lock)aLock; 162 #endif 163 164 dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", 165 PyThread_get_thread_ident(), 166 aLock, 167 waitflag)); 168 169 #if defined(PYCC_GCC) 170 /* always successful if the lock doesn't exist */ 171 if (aLock && 172 _fmutex_request((_fmutex *)aLock, waitflag ? 0 : _FMR_NOWAIT)) 173 return 0; 174 #else 175 while (!done) { 176 /* if the lock is currently set, we have to wait for 177 * the state to change 178 */ 179 if (lock->is_set) { 180 if (!waitflag) 181 return 0; 182 DosWaitEventSem(lock->changed, SEM_INDEFINITE_WAIT); 183 } 184 185 /* enter a critical section and try to get the semaphore. If 186 * it is still locked, we will try again. 187 */ 188 if (DosEnterCritSec()) 189 return 0; 190 191 if (!lock->is_set) { 192 lock->is_set = 1; 193 DosResetEventSem(lock->changed, &count); 194 done = 1; 195 } 196 197 DosExitCritSec(); 198 } 199 #endif 200 201 return 1; 242 202 } 243 203 … … 246 206 { 247 207 #if !defined(PYCC_GCC) 248 249 #endif 250 251 252 253 254 255 #if defined(PYCC_GCC) 256 257 258 #else 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 208 type_os2_lock lock = (type_os2_lock)aLock; 209 #endif 210 211 dprintf(("%ld: PyThread_release_lock(%p) called\n", 212 PyThread_get_thread_ident(), 213 aLock)); 214 215 #if defined(PYCC_GCC) 216 if (aLock) 217 _fmutex_release((_fmutex *)aLock); 218 #else 219 if (!lock->is_set) { 220 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", 221 PyThread_get_thread_ident(), 222 aLock, 223 GetLastError())); 224 return; 225 } 226 227 if (DosEnterCritSec()) { 228 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", 229 PyThread_get_thread_ident(), 230 aLock, 231 GetLastError())); 232 return; 233 } 234 235 lock->is_set = 0; 236 DosPostEventSem(lock->changed); 237 238 DosExitCritSec(); 279 239 #endif 280 240 } 281 241 282 242 /* minimum/maximum thread stack sizes supported */ 283 #define THREAD_MIN_STACKSIZE 0x8000/* 32kB */284 #define THREAD_MAX_STACKSIZE 0x2000000/* 32MB */243 #define THREAD_MIN_STACKSIZE 0x8000 /* 32kB */ 244 #define THREAD_MAX_STACKSIZE 0x2000000 /* 32MB */ 285 245 286 246 /* set the thread stack size. … … 290 250 _pythread_os2_set_stacksize(size_t size) 291 251 { 292 293 294 295 296 297 298 299 300 301 302 303 304 305 } 306 307 #define THREAD_SET_STACKSIZE(x) 252 /* set to default */ 253 if (size == 0) { 254 _pythread_stacksize = 0; 255 return 0; 256 } 257 258 /* valid range? */ 259 if (size >= THREAD_MIN_STACKSIZE && size < THREAD_MAX_STACKSIZE) { 260 _pythread_stacksize = size; 261 return 0; 262 } 263 264 return -1; 265 } 266 267 #define THREAD_SET_STACKSIZE(x) _pythread_os2_set_stacksize(x)
Note:
See TracChangeset
for help on using the changeset viewer.