Mercurial > cpython-lru_cache-weakref
annotate Python/thread_nt.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 | 404156092f78 |
| children | 916fb024ce94 |
| rev | line source |
|---|---|
| 2152 | 1 /*********************************************************** |
| 2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, | |
| 3 The Netherlands. | |
| 4 | |
| 5 All Rights Reserved | |
| 6 | |
|
4503
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, |
| 2152 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
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 |
| 2152 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
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. |
| 2152 | 16 |
|
4503
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. |
| 2152 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 32 /* This code implemented by Dag.Gruneau@elsa.preseco.comm.se */ | |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
33 /* Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru */ |
| 2152 | 34 |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
35 #include <windows.h> |
|
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
36 #include <limits.h> |
|
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
37 #include <process.h> |
| 2152 | 38 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
39 typedef struct NRMUTEX { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
40 LONG owned ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
41 DWORD thread_id ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
42 HANDLE hevent ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
43 } NRMUTEX, *PNRMUTEX ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
44 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
45 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
46 typedef PVOID WINAPI interlocked_cmp_xchg_t(PVOID *dest, PVOID exc, PVOID comperand) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
47 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
48 /* Sorry mate, but we haven't got InterlockedCompareExchange in Win95! */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
49 static PVOID WINAPI interlocked_cmp_xchg(PVOID *dest, PVOID exc, PVOID comperand) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
50 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
51 static LONG spinlock = 0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
52 PVOID result ; |
| 12661 | 53 DWORD dwSleep = 0; |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
54 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
55 /* Acqire spinlock (yielding control to other threads if cant aquire for the moment) */ |
| 12661 | 56 while(InterlockedExchange(&spinlock, 1)) |
| 57 { | |
| 58 // Using Sleep(0) can cause a priority inversion. | |
| 59 // Sleep(0) only yields the processor if there's | |
| 60 // another thread of the same priority that's | |
| 61 // ready to run. If a high-priority thread is | |
| 62 // trying to acquire the lock, which is held by | |
| 63 // a low-priority thread, then the low-priority | |
| 64 // thread may never get scheduled and hence never | |
| 65 // free the lock. NT attempts to avoid priority | |
| 66 // inversions by temporarily boosting the priority | |
| 67 // of low-priority runnable threads, but the problem | |
| 68 // can still occur if there's a medium-priority | |
| 69 // thread that's always runnable. If Sleep(1) is used, | |
| 70 // then the thread unconditionally yields the CPU. We | |
| 71 // only do this for the second and subsequent even | |
| 72 // iterations, since a millisecond is a long time to wait | |
| 73 // if the thread can be scheduled in again sooner | |
| 74 // (~100,000 instructions). | |
| 75 // Avoid priority inversion: 0, 1, 0, 1,... | |
| 76 Sleep(dwSleep); | |
| 77 dwSleep = !dwSleep; | |
| 78 } | |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
79 result = *dest ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
80 if (result == comperand) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
81 *dest = exc ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
82 /* Release spinlock */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
83 spinlock = 0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
84 return result ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
85 } ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
86 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
87 static interlocked_cmp_xchg_t *ixchg ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
88 BOOL InitializeNonRecursiveMutex(PNRMUTEX mutex) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
89 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
90 if (!ixchg) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
91 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
92 /* Sorely, Win95 has no InterlockedCompareExchange API (Win98 has), so we have to use emulation */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
93 HANDLE kernel = GetModuleHandle("kernel32.dll") ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
94 if (!kernel || (ixchg = (interlocked_cmp_xchg_t *)GetProcAddress(kernel, "InterlockedCompareExchange")) == NULL) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
95 ixchg = interlocked_cmp_xchg ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
96 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
97 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
98 mutex->owned = -1 ; /* No threads have entered NonRecursiveMutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
99 mutex->thread_id = 0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
100 mutex->hevent = CreateEvent(NULL, FALSE, FALSE, NULL) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
101 return mutex->hevent != NULL ; /* TRUE if the mutex is created */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
102 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
103 |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12661
diff
changeset
|
104 #ifdef InterlockedCompareExchange |
|
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12661
diff
changeset
|
105 #undef InterlockedCompareExchange |
|
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12661
diff
changeset
|
106 #endif |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
107 #define InterlockedCompareExchange(dest,exchange,comperand) (ixchg((dest), (exchange), (comperand))) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
108 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
109 VOID DeleteNonRecursiveMutex(PNRMUTEX mutex) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
110 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
111 /* No in-use check */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
112 CloseHandle(mutex->hevent) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
113 mutex->hevent = NULL ; /* Just in case */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
114 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
115 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
116 DWORD EnterNonRecursiveMutex(PNRMUTEX mutex, BOOL wait) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
117 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
118 /* Assume that the thread waits successfully */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
119 DWORD ret ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
120 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
121 /* InterlockedIncrement(&mutex->owned) == 0 means that no thread currently owns the mutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
122 if (!wait) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
123 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
124 if (InterlockedCompareExchange((PVOID *)&mutex->owned, (PVOID)0, (PVOID)-1) != (PVOID)-1) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
125 return WAIT_TIMEOUT ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
126 ret = WAIT_OBJECT_0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
127 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
128 else |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
129 ret = InterlockedIncrement(&mutex->owned) ? |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
130 /* Some thread owns the mutex, let's wait... */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
131 WaitForSingleObject(mutex->hevent, INFINITE) : WAIT_OBJECT_0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
132 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
133 mutex->thread_id = GetCurrentThreadId() ; /* We own it */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
134 return ret ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
135 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
136 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
137 BOOL LeaveNonRecursiveMutex(PNRMUTEX mutex) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
138 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
139 /* We don't own the mutex */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
140 mutex->thread_id = 0 ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
141 return |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
142 InterlockedDecrement(&mutex->owned) < 0 || |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
143 SetEvent(mutex->hevent) ; /* Other threads are waiting, wake one on them up */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
144 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
145 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
146 PNRMUTEX AllocNonRecursiveMutex() |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
147 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
148 PNRMUTEX mutex = (PNRMUTEX)malloc(sizeof(NRMUTEX)) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
149 if (mutex && !InitializeNonRecursiveMutex(mutex)) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
150 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
151 free(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
152 mutex = NULL ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
153 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
154 return mutex ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
155 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
156 |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
157 void FreeNonRecursiveMutex(PNRMUTEX mutex) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
158 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
159 if (mutex) |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
160 { |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
161 DeleteNonRecursiveMutex(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
162 free(mutex) ; |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
163 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
164 } |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
165 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
166 long PyThread_get_thread_ident(void); |
| 2152 | 167 |
| 168 /* | |
| 169 * Change all headers to pure ANSI as no one will use K&R style on an | |
| 170 * NT | |
| 171 */ | |
| 172 | |
| 173 /* | |
| 174 * Initialization of the C package, should not be needed. | |
| 175 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
176 static void PyThread__init_thread(void) |
| 2152 | 177 { |
| 178 } | |
| 179 | |
| 180 /* | |
| 181 * Thread support. | |
| 182 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
183 int PyThread_start_new_thread(void (*func)(void *), void *arg) |
| 2152 | 184 { |
|
13138
404156092f78
- workaround to make 1.6 build under MSVC 5.0. hopefully,
Fredrik Lundh <fredrik@pythonware.com>
parents:
13096
diff
changeset
|
185 #if _MSC_VER >= 1200 |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12661
diff
changeset
|
186 INT_PTR rv; |
|
13138
404156092f78
- workaround to make 1.6 build under MSVC 5.0. hopefully,
Fredrik Lundh <fredrik@pythonware.com>
parents:
13096
diff
changeset
|
187 #else |
|
404156092f78
- workaround to make 1.6 build under MSVC 5.0. hopefully,
Fredrik Lundh <fredrik@pythonware.com>
parents:
13096
diff
changeset
|
188 unsigned long rv; |
|
404156092f78
- workaround to make 1.6 build under MSVC 5.0. hopefully,
Fredrik Lundh <fredrik@pythonware.com>
parents:
13096
diff
changeset
|
189 #endif |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
190 int success = 0; |
| 2152 | 191 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
192 dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident())); |
| 2152 | 193 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
194 PyThread_init_thread(); |
| 2152 | 195 |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
196 rv = _beginthread(func, 0, arg); /* use default stack size */ |
| 2152 | 197 |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
198 if (rv != -1) { |
| 2152 | 199 success = 1; |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
12661
diff
changeset
|
200 dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n", PyThread_get_thread_ident(), rv)); |
| 2152 | 201 } |
| 202 | |
| 203 return success; | |
| 204 } | |
| 205 | |
| 206 /* | |
| 207 * Return the thread Id instead of an handle. The Id is said to uniquely identify the | |
| 208 * thread in the system | |
| 209 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
210 long PyThread_get_thread_ident(void) |
| 2152 | 211 { |
| 212 if (!initialized) | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
213 PyThread_init_thread(); |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
214 |
| 2152 | 215 return GetCurrentThreadId(); |
| 216 } | |
| 217 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
218 static void do_PyThread_exit_thread(int no_cleanup) |
| 2152 | 219 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
220 dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident())); |
| 2152 | 221 if (!initialized) |
| 222 if (no_cleanup) | |
| 223 _exit(0); | |
| 224 else | |
| 225 exit(0); | |
|
6029
68f2d7704180
Use _beginthread() and _endthread() in favor of CreateThread() and
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
226 _endthread(); |
| 2152 | 227 } |
| 228 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
229 void PyThread_exit_thread(void) |
| 2152 | 230 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
231 do_PyThread_exit_thread(0); |
| 2152 | 232 } |
| 233 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
234 void PyThread__exit_thread(void) |
| 2152 | 235 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
236 do_PyThread_exit_thread(1); |
| 2152 | 237 } |
| 238 | |
| 239 #ifndef NO_EXIT_PROG | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
240 static void do_PyThread_exit_prog(int status, int no_cleanup) |
| 2152 | 241 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
242 dprintf(("PyThread_exit_prog(%d) called\n", status)); |
| 2152 | 243 if (!initialized) |
| 244 if (no_cleanup) | |
| 245 _exit(status); | |
| 246 else | |
| 247 exit(status); | |
| 248 } | |
| 249 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
250 void PyThread_exit_prog(int status) |
| 2152 | 251 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
252 do_PyThread_exit_prog(status, 0); |
| 2152 | 253 } |
| 254 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
255 void PyThread__exit_prog _P1(int status) |
| 2152 | 256 { |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
257 do_PyThread_exit_prog(status, 1); |
| 2152 | 258 } |
| 259 #endif /* NO_EXIT_PROG */ | |
| 260 | |
| 261 /* | |
| 262 * Lock support. It has too be implemented as semaphores. | |
| 263 * I [Dag] tried to implement it with mutex but I could find a way to | |
| 264 * tell whether a thread already own the lock or not. | |
| 265 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
266 PyThread_type_lock PyThread_allocate_lock(void) |
| 2152 | 267 { |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
268 PNRMUTEX aLock; |
| 2152 | 269 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
270 dprintf(("PyThread_allocate_lock called\n")); |
| 2152 | 271 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
272 PyThread_init_thread(); |
| 2152 | 273 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
274 aLock = AllocNonRecursiveMutex() ; |
| 2152 | 275 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
276 dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock)); |
| 2152 | 277 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
278 return (PyThread_type_lock) aLock; |
| 2152 | 279 } |
| 280 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
281 void PyThread_free_lock(PyThread_type_lock aLock) |
| 2152 | 282 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
283 dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2152 | 284 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
285 FreeNonRecursiveMutex(aLock) ; |
| 2152 | 286 } |
| 287 | |
| 288 /* | |
| 289 * Return 1 on success if the lock was acquired | |
| 290 * | |
| 291 * and 0 if the lock was not acquired. This means a 0 is returned | |
| 292 * if the lock has already been acquired by this thread! | |
| 293 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
294 int PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) |
| 2152 | 295 { |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
296 int success ; |
| 2152 | 297 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
298 dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(),aLock, waitflag)); |
| 2152 | 299 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
300 success = aLock && EnterNonRecursiveMutex((PNRMUTEX) aLock, (waitflag == 1 ? INFINITE : 0)) == WAIT_OBJECT_0 ; |
| 2152 | 301 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
302 dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n", PyThread_get_thread_ident(),aLock, waitflag, success)); |
| 2152 | 303 |
| 304 return success; | |
| 305 } | |
| 306 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
307 void PyThread_release_lock(PyThread_type_lock aLock) |
| 2152 | 308 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
309 dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); |
| 2152 | 310 |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
311 if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock))) |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
312 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock, GetLastError())); |
| 2152 | 313 } |
| 314 | |
| 315 /* | |
| 316 * Semaphore support. | |
| 317 */ | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
318 PyThread_type_sema PyThread_allocate_sema(int value) |
| 2152 | 319 { |
| 320 HANDLE aSemaphore; | |
| 321 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
322 dprintf(("%ld: PyThread_allocate_sema called\n", PyThread_get_thread_ident())); |
| 2152 | 323 if (!initialized) |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
324 PyThread_init_thread(); |
| 2152 | 325 |
| 326 aSemaphore = CreateSemaphore( NULL, /* Security attributes */ | |
|
12584
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
327 value, /* Initial value */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
328 INT_MAX, /* Maximum value */ |
|
cde4da18c4fa
Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
329 NULL); /* Name of semaphore */ |
| 2152 | 330 |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
331 dprintf(("%ld: PyThread_allocate_sema() -> %p\n", PyThread_get_thread_ident(), aSemaphore)); |
| 2152 | 332 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
333 return (PyThread_type_sema) aSemaphore; |
| 2152 | 334 } |
| 335 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
336 void PyThread_free_sema(PyThread_type_sema aSemaphore) |
| 2152 | 337 { |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
338 dprintf(("%ld: PyThread_free_sema(%p) called\n", PyThread_get_thread_ident(), aSemaphore)); |
| 2152 | 339 |
| 340 CloseHandle((HANDLE) aSemaphore); | |
| 341 } | |
| 342 | |
|
4371
c277ee8c669c
Sjoerd's thread changes (including down_sema typo fix).
Guido van Rossum <guido@python.org>
parents:
2152
diff
changeset
|
343 /* |
|
c277ee8c669c
Sjoerd's thread changes (including down_sema typo fix).
Guido van Rossum <guido@python.org>
parents:
2152
diff
changeset
|
344 XXX must do something about waitflag |
|
c277ee8c669c
Sjoerd's thread changes (including down_sema typo fix).
Guido van Rossum <guido@python.org>
parents:
2152
diff
changeset
|
345 */ |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
346 int PyThread_down_sema(PyThread_type_sema aSemaphore, int waitflag) |
| 2152 | 347 { |
| 348 DWORD waitResult; | |
| 349 | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
350 dprintf(("%ld: PyThread_down_sema(%p) called\n", PyThread_get_thread_ident(), aSemaphore)); |
| 2152 | 351 |
| 352 waitResult = WaitForSingleObject( (HANDLE) aSemaphore, INFINITE); | |
| 353 | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
354 dprintf(("%ld: PyThread_down_sema(%p) return: %l\n", PyThread_get_thread_ident(), aSemaphore, waitResult)); |
|
4371
c277ee8c669c
Sjoerd's thread changes (including down_sema typo fix).
Guido van Rossum <guido@python.org>
parents:
2152
diff
changeset
|
355 return 0; |
| 2152 | 356 } |
| 357 | |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
6029
diff
changeset
|
358 void PyThread_up_sema(PyThread_type_sema aSemaphore) |
| 2152 | 359 { |
| 360 ReleaseSemaphore( | |
| 361 (HANDLE) aSemaphore, /* Handle of semaphore */ | |
| 362 1, /* increment count by one */ | |
| 363 NULL); /* not interested in previous count */ | |
| 364 | |
|
13210
ff243b0f16ee
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
13138
diff
changeset
|
365 dprintf(("%ld: PyThread_up_sema(%p)\n", PyThread_get_thread_ident(), aSemaphore)); |
| 2152 | 366 } |
