Mercurial > cpython-lru_cache-weakref
annotate Python/thread_os2.h @ 13210:ff243b0f16ee legacy-trunk
Trent Mick <trentm@activestate.com>:
The common technique for printing out a pointer has been to cast to a long
and use the "%lx" printf modifier. This is incorrect on Win64 where casting
to a long truncates the pointer. The "%p" formatter should be used instead.
The problem as stated by Tim:
> Unfortunately, the C committee refused to define what %p conversion "looks
> like" -- they explicitly allowed it to be implementation-defined. Older
> versions of Microsoft C even stuck a colon in the middle of the address (in
> the days of segment+offset addressing)!
The result is that the hex value of a pointer will maybe/maybe not have a 0x
prepended to it.
Notes on the patch:
There are two main classes of changes:
- in the various repr() functions that print out pointers
- debugging printf's in the various thread_*.h files (these are why the
patch is large)
Closes SourceForge patch #100505.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Fri, 30 Jun 2000 15:01:00 +0000 |
| parents | 877d23bd5bdc |
| children | 916fb024ce94 |
| 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 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
15 permission. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
16 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 2649 | 29 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4371
diff
changeset
|
30 ******************************************************************/ |
| 2649 | 31 |
| 32 /* This code implemented by cvale@netcom.com */ | |
| 33 | |
| 34 #define INCL_DOSPROCESS | |
| 35 #define INCL_DOSSEMAPHORES | |
| 36 #include "os2.h" | |
| 37 #include "limits.h" | |
| 38 | |
| 39 #include "process.h" | |
| 40 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
41 long PyThread_get_thread_ident(void); |
| 2649 | 42 |
| 43 | |
| 44 /* | |
| 45 * Initialization of the C package, should not be needed. | |
| 46 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
47 static void PyThread__init_thread(void) |
| 2649 | 48 { |
| 49 } | |
| 50 | |
| 51 /* | |
| 52 * Thread support. | |
| 53 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
54 int PyThread_start_new_thread(void (*func)(void *), void *arg) |
| 2649 | 55 { |
| 56 int aThread; | |
| 57 int success = 1; | |
| 58 | |
|
6626
5e31d381fa47
os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
59 aThread = _beginthread(func,NULL,65536,arg); |
| 2649 | 60 |
| 61 if( aThread == -1 ) { | |
| 62 success = 0; | |
| 63 fprintf(stderr,"aThread failed == %d",aThread); | |
| 64 dprintf(("_beginthread failed. return %ld\n", errno)); | |
| 65 } | |
| 66 | |
| 67 return success; | |
| 68 } | |
| 69 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
70 long PyThread_get_thread_ident(void) |
| 2649 | 71 { |
| 72 PPIB pib; | |
| 73 PTIB tib; | |
| 74 | |
| 75 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
|
76 PyThread_init_thread(); |
| 2649 | 77 |
| 78 DosGetInfoBlocks(&tib,&pib); | |
| 79 return tib->tib_ptib2->tib2_ultid; | |
| 80 } | |
| 81 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
82 static void do_PyThread_exit_thread(int no_cleanup) |
| 2649 | 83 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
84 dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident())); |
| 2649 | 85 if (!initialized) |
| 86 if (no_cleanup) | |
| 87 _exit(0); | |
| 88 else | |
| 89 exit(0); | |
| 90 _endthread(); | |
| 91 } | |
| 92 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
93 void PyThread_exit_thread(void) |
| 2649 | 94 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
95 do_PyThread_exit_thread(0); |
| 2649 | 96 } |
| 97 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
98 void PyThread__exit_thread(void) |
| 2649 | 99 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
100 do_PyThread_exit_thread(1); |
| 2649 | 101 } |
| 102 | |
| 103 #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
|
104 static void do_PyThread_exit_prog(int status, int no_cleanup) |
| 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 dprintf(("PyThread_exit_prog(%d) called\n", status)); |
| 2649 | 107 if (!initialized) |
| 108 if (no_cleanup) | |
| 109 _exit(status); | |
| 110 else | |
| 111 exit(status); | |
| 112 } | |
| 113 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
114 void PyThread_exit_prog(int status) |
| 2649 | 115 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
116 do_PyThread_exit_prog(status, 0); |
| 2649 | 117 } |
| 118 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
119 void PyThread__exit_prog _P1(int status) |
| 2649 | 120 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
121 do_PyThread_exit_prog(status, 1); |
| 2649 | 122 } |
| 123 #endif /* NO_EXIT_PROG */ | |
| 124 | |
| 125 /* | |
| 126 * Lock support. It has too be implemented as semaphores. | |
| 127 * I [Dag] tried to implement it with mutex but I could find a way to | |
| 128 * tell whether a thread already own the lock or not. | |
| 129 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
130 PyThread_type_lock PyThread_allocate_lock(void) |
| 2649 | 131 { |
| 132 HMTX aLock; | |
| 133 APIRET rc; | |
| 134 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
135 dprintf(("PyThread_allocate_lock called\n")); |
| 2649 | 136 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
|
137 PyThread_init_thread(); |
| 2649 | 138 |
| 139 DosCreateMutexSem(NULL, /* Sem name */ | |
| 140 &aLock, /* the semaphone */ | |
| 141 0, /* shared ? */ | |
| 142 0); /* initial state */ | |
| 143 | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
144 dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock)); |
| 2649 | 145 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
146 return (PyThread_type_lock) aLock; |
| 2649 | 147 } |
| 148 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
149 void PyThread_free_lock(PyThread_type_lock aLock) |
| 2649 | 150 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
151 dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2649 | 152 |
| 153 DosCloseMutexSem((HMTX)aLock); | |
| 154 } | |
| 155 | |
| 156 /* | |
| 157 * Return 1 on success if the lock was acquired | |
| 158 * | |
| 159 * and 0 if the lock was not acquired. This means a 0 is returned | |
| 160 * if the lock has already been acquired by this thread! | |
| 161 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
162 int PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) |
| 2649 | 163 { |
| 164 int success = 1; | |
| 165 ULONG rc, count; | |
| 166 PID pid = 0; | |
| 167 TID tid = 0; | |
| 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) called\n", PyThread_get_thread_ident(), |
|
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
170 aLock, waitflag)); |
| 2649 | 171 |
| 172 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
|
173 if( tid == PyThread_get_thread_ident() ) { /* if we own this lock */ |
| 2649 | 174 success = 0; |
| 175 } else { | |
| 176 rc = DosRequestMutexSem((HMTX) aLock, | |
| 177 (waitflag == 1 ? SEM_INDEFINITE_WAIT : 0)); | |
| 178 | |
| 179 if( rc != 0) { | |
| 180 success = 0; /* We failed */ | |
| 181 } | |
| 182 } | |
| 183 | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
184 dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n", |
|
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
185 PyThread_get_thread_ident(),aLock, waitflag, success)); |
| 2649 | 186 |
| 187 return success; | |
| 188 } | |
| 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 void PyThread_release_lock(PyThread_type_lock aLock) |
| 2649 | 191 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
192 dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2649 | 193 |
| 194 if ( DosReleaseMutexSem( (HMTX) aLock ) != 0 ) { | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
195 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
|
196 PyThread_get_thread_ident(), aLock, GetLastError())); |
| 2649 | 197 } |
| 198 } | |
| 199 | |
| 200 /* | |
| 201 * Semaphore support. | |
| 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 PyThread_type_sema PyThread_allocate_sema(int value) |
| 2649 | 204 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
205 return (PyThread_type_sema) 0; |
| 2649 | 206 } |
| 207 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
208 void PyThread_free_sema(PyThread_type_sema aSemaphore) |
| 2649 | 209 { |
| 210 | |
| 211 } | |
| 212 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
213 int PyThread_down_sema(PyThread_type_sema aSemaphore, int waitflag) |
| 2649 | 214 { |
|
4371
c277ee8c669c
Sjoerd's thread changes (including down_sema typo fix).
Guido van Rossum <guido@python.org>
parents:
2649
diff
changeset
|
215 return -1; |
| 2649 | 216 } |
| 217 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
218 void PyThread_up_sema(PyThread_type_sema aSemaphore) |
| 2649 | 219 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
9679
diff
changeset
|
220 dprintf(("%ld: PyThread_up_sema(%p)\n", PyThread_get_thread_ident(), aSemaphore)); |
| 2649 | 221 } |
