Mercurial > cpython-lru_cache-weakref
annotate Python/thread_os2.h @ 13446:23f9689ace50 legacy-trunk
Get rid of unused vars in builtin_unicode (they were causing
legit warnings).
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Sun, 09 Jul 2000 02:11:18 +0000 |
| parents | 916fb024ce94 |
| children | 5b727ab37092 |
| rev | line source |
|---|---|
| 2649 | 1 /*********************************************************** |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
3 The Netherlands. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
4 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
5 All Rights Reserved |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
6 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
7 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
8 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
9 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
10 All rights reserved. |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
11 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
12 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13210
diff
changeset
|
13 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 2649 | 14 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
15 ******************************************************************/ |
| 2649 | 16 |
| 17 /* This code implemented by cvale@netcom.com */ | |
| 18 | |
| 19 #define INCL_DOSPROCESS | |
| 20 #define INCL_DOSSEMAPHORES | |
| 21 #include "os2.h" | |
| 22 #include "limits.h" | |
| 23 | |
| 24 #include "process.h" | |
| 25 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
26 long PyThread_get_thread_ident(void); |
| 2649 | 27 |
| 28 | |
| 29 /* | |
| 30 * Initialization of the C package, should not be needed. | |
| 31 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
32 static void PyThread__init_thread(void) |
| 2649 | 33 { |
| 34 } | |
| 35 | |
| 36 /* | |
| 37 * Thread support. | |
| 38 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
39 int PyThread_start_new_thread(void (*func)(void *), void *arg) |
| 2649 | 40 { |
| 41 int aThread; | |
| 42 int success = 1; | |
| 43 | |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
44 aThread = _beginthread(func,NULL,65536,arg); |
| 2649 | 45 |
| 46 if( aThread == -1 ) { | |
| 47 success = 0; | |
| 48 fprintf(stderr,"aThread failed == %d",aThread); | |
| 49 dprintf(("_beginthread failed. return %ld\n", errno)); | |
| 50 } | |
| 51 | |
| 52 return success; | |
| 53 } | |
| 54 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
55 long PyThread_get_thread_ident(void) |
| 2649 | 56 { |
| 57 PPIB pib; | |
| 58 PTIB tib; | |
| 59 | |
| 60 if (!initialized) | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
61 PyThread_init_thread(); |
| 2649 | 62 |
| 63 DosGetInfoBlocks(&tib,&pib); | |
| 64 return tib->tib_ptib2->tib2_ultid; | |
| 65 } | |
| 66 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
67 static void do_PyThread_exit_thread(int no_cleanup) |
| 2649 | 68 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
69 dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident())); |
| 2649 | 70 if (!initialized) |
| 71 if (no_cleanup) | |
| 72 _exit(0); | |
| 73 else | |
| 74 exit(0); | |
| 75 _endthread(); | |
| 76 } | |
| 77 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
78 void PyThread_exit_thread(void) |
| 2649 | 79 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
80 do_PyThread_exit_thread(0); |
| 2649 | 81 } |
| 82 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
83 void PyThread__exit_thread(void) |
| 2649 | 84 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
85 do_PyThread_exit_thread(1); |
| 2649 | 86 } |
| 87 | |
| 88 #ifndef NO_EXIT_PROG | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
89 static void do_PyThread_exit_prog(int status, int no_cleanup) |
| 2649 | 90 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
91 dprintf(("PyThread_exit_prog(%d) called\n", status)); |
| 2649 | 92 if (!initialized) |
| 93 if (no_cleanup) | |
| 94 _exit(status); | |
| 95 else | |
| 96 exit(status); | |
| 97 } | |
| 98 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
99 void PyThread_exit_prog(int status) |
| 2649 | 100 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
101 do_PyThread_exit_prog(status, 0); |
| 2649 | 102 } |
| 103 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
104 void PyThread__exit_prog _P1(int status) |
| 2649 | 105 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
106 do_PyThread_exit_prog(status, 1); |
| 2649 | 107 } |
| 108 #endif /* NO_EXIT_PROG */ | |
| 109 | |
| 110 /* | |
| 111 * Lock support. It has too be implemented as semaphores. | |
| 112 * I [Dag] tried to implement it with mutex but I could find a way to | |
| 113 * tell whether a thread already own the lock or not. | |
| 114 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
115 PyThread_type_lock PyThread_allocate_lock(void) |
| 2649 | 116 { |
| 117 HMTX aLock; | |
| 118 APIRET rc; | |
| 119 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
120 dprintf(("PyThread_allocate_lock called\n")); |
| 2649 | 121 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
122 PyThread_init_thread(); |
| 2649 | 123 |
| 124 DosCreateMutexSem(NULL, /* Sem name */ | |
| 125 &aLock, /* the semaphone */ | |
| 126 0, /* shared ? */ | |
| 127 0); /* initial state */ | |
| 128 | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
129 dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock)); |
| 2649 | 130 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
131 return (PyThread_type_lock) aLock; |
| 2649 | 132 } |
| 133 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
134 void PyThread_free_lock(PyThread_type_lock aLock) |
| 2649 | 135 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
136 dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2649 | 137 |
| 138 DosCloseMutexSem((HMTX)aLock); | |
| 139 } | |
| 140 | |
| 141 /* | |
| 142 * Return 1 on success if the lock was acquired | |
| 143 * | |
| 144 * and 0 if the lock was not acquired. This means a 0 is returned | |
| 145 * if the lock has already been acquired by this thread! | |
| 146 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
147 int PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) |
| 2649 | 148 { |
| 149 int success = 1; | |
| 150 ULONG rc, count; | |
| 151 PID pid = 0; | |
| 152 TID tid = 0; | |
| 153 | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
154 dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(), |
|
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
155 aLock, waitflag)); |
| 2649 | 156 |
| 157 DosQueryMutexSem((HMTX)aLock,&pid,&tid,&count); | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
158 if( tid == PyThread_get_thread_ident() ) { /* if we own this lock */ |
| 2649 | 159 success = 0; |
| 160 } else { | |
| 161 rc = DosRequestMutexSem((HMTX) aLock, | |
| 162 (waitflag == 1 ? SEM_INDEFINITE_WAIT : 0)); | |
| 163 | |
| 164 if( rc != 0) { | |
| 165 success = 0; /* We failed */ | |
| 166 } | |
| 167 } | |
| 168 | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
169 dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n", |
|
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
170 PyThread_get_thread_ident(),aLock, waitflag, success)); |
| 2649 | 171 |
| 172 return success; | |
| 173 } | |
| 174 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
175 void PyThread_release_lock(PyThread_type_lock aLock) |
| 2649 | 176 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
177 dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2649 | 178 |
| 179 if ( DosReleaseMutexSem( (HMTX) aLock ) != 0 ) { | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
180 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", |
|
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
181 PyThread_get_thread_ident(), aLock, GetLastError())); |
| 2649 | 182 } |
| 183 } | |
| 184 | |
| 185 /* | |
| 186 * Semaphore support. | |
| 187 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
188 PyThread_type_sema PyThread_allocate_sema(int value) |
| 2649 | 189 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
190 return (PyThread_type_sema) 0; |
| 2649 | 191 } |
| 192 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
193 void PyThread_free_sema(PyThread_type_sema aSemaphore) |
| 2649 | 194 { |
| 195 | |
| 196 } | |
| 197 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
198 int PyThread_down_sema(PyThread_type_sema aSemaphore, int waitflag) |
| 2649 | 199 { |
|
4371
c277ee8c669c
Sjoerd's thread changes (including down_sema typo fix).
Guido van Rossum <guido@python.org>
parents:
2649
diff
changeset
|
200 return -1; |
| 2649 | 201 } |
| 202 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
203 void PyThread_up_sema(PyThread_type_sema aSemaphore) |
| 2649 | 204 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
205 dprintf(("%ld: PyThread_up_sema(%p)\n", PyThread_get_thread_ident(), aSemaphore)); |
| 2649 | 206 } |
