annotate Python/thread_nt.h @ 3964:fcfec6a810ba legacy-trunk

Added casts from unsigned char to char when calling rds_object() on frozen code.
author Guido van Rossum <guido@python.org>
date Thu, 08 Aug 1996 18:52:59 +0000
parents 1a52351a00b2
children c277ee8c669c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2152
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 The Netherlands.
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 distribution of the software without specific, written prior permission.
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 ******************************************************************/
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 /* This code implemented by Dag.Gruneau@elsa.preseco.comm.se */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 #include "windows.h"
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #include "limits.h"
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 long get_thread_ident(void);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /*
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 * Change all headers to pure ANSI as no one will use K&R style on an
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 * NT
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 /*
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 * Initialization of the C package, should not be needed.
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 static void _init_thread(void)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 /*
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 * Thread support.
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 int start_new_thread(void (*func)(void *), void *arg)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 HANDLE aThread;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 DWORD aThreadId;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 int success = 0; /* init not needed when SOLARIS_THREADS and */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 /* C_THREADS implemented properly */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 dprintf(("%ld: start_new_thread called\n", get_thread_ident()));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 if (!initialized)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 init_thread();
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
57
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 aThread = CreateThread(
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 NULL, /* No security attributes */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 0, /* use default stack size */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 (LPTHREAD_START_ROUTINE) func, /* thread function */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 (LPVOID) arg, /* argument to thread function */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 0, /* use the default creation flags */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 &aThreadId); /* returns the thread identifier */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 if (aThread != NULL) {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 CloseHandle(aThread); /* We do not want to have any zombies hanging around */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 success = 1;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 dprintf(("%ld: start_new_thread succeeded: %ld\n", get_thread_ident(), aThreadId));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
71
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 return success;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 /*
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 * Return the thread Id instead of an handle. The Id is said to uniquely identify the
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 * thread in the system
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 long get_thread_ident(void)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 if (!initialized)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 init_thread();
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 return GetCurrentThreadId();
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 static void do_exit_thread(int no_cleanup)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 dprintf(("%ld: exit_thread called\n", get_thread_ident()));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 if (!initialized)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 if (no_cleanup)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 _exit(0);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 else
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 exit(0);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 ExitThread(0);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
97
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 void exit_thread(void)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 do_exit_thread(0);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 void _exit_thread(void)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 do_exit_thread(1);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
107
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 #ifndef NO_EXIT_PROG
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 static void do_exit_prog(int status, int no_cleanup)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 dprintf(("exit_prog(%d) called\n", status));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 if (!initialized)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 if (no_cleanup)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 _exit(status);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 else
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 exit(status);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 void exit_prog(int status)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 do_exit_prog(status, 0);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 void _exit_prog _P1(int status)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 do_exit_prog(status, 1);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 #endif /* NO_EXIT_PROG */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 /*
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 * Lock support. It has too be implemented as semaphores.
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 * I [Dag] tried to implement it with mutex but I could find a way to
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 * tell whether a thread already own the lock or not.
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 type_lock allocate_lock(void)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 HANDLE aLock;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 dprintf(("allocate_lock called\n"));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 if (!initialized)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 init_thread();
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
142
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 aLock = CreateSemaphore(NULL, /* Security attributes */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 1, /* Initial value */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 1, /* Maximum value */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 NULL);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 /* Name of semaphore */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
148
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 dprintf(("%ld: allocate_lock() -> %lx\n", get_thread_ident(), (long)aLock));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
150
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 return (type_lock) aLock;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
153
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 void free_lock(type_lock aLock)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 dprintf(("%ld: free_lock(%lx) called\n", get_thread_ident(),(long)aLock));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
157
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 CloseHandle((HANDLE) aLock);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
160
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 /*
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 * Return 1 on success if the lock was acquired
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 *
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 * and 0 if the lock was not acquired. This means a 0 is returned
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 * if the lock has already been acquired by this thread!
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 int acquire_lock(type_lock aLock, int waitflag)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 int success = 1;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 DWORD waitResult;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
171
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 dprintf(("%ld: acquire_lock(%lx, %d) called\n", get_thread_ident(),(long)aLock, waitflag));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
173
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 waitResult = WaitForSingleObject((HANDLE) aLock, (waitflag == 1 ? INFINITE : 0));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 if (waitResult != WAIT_OBJECT_0) {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 success = 0; /* We failed */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
179
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 dprintf(("%ld: acquire_lock(%lx, %d) -> %d\n", get_thread_ident(),(long)aLock, waitflag, success));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
181
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 return success;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
184
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 void release_lock(type_lock aLock)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 dprintf(("%ld: release_lock(%lx) called\n", get_thread_ident(),(long)aLock));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
188
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 if (!ReleaseSemaphore(
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 (HANDLE) aLock, /* Handle of semaphore */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 1, /* increment count by one */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 NULL)) /* not interested in previous count */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 dprintf(("%ld: Could not release_lock(%lx) error: %l\n", get_thread_ident(), (long)aLock, GetLastError()));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
197
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 /*
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 * Semaphore support.
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 type_sema allocate_sema(int value)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 HANDLE aSemaphore;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
204
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 dprintf(("%ld: allocate_sema called\n", get_thread_ident()));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 if (!initialized)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 init_thread();
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
208
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 aSemaphore = CreateSemaphore( NULL, /* Security attributes */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 value, /* Initial value */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 INT_MAX, /* Maximum value */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 NULL); /* Name of semaphore */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
213
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 dprintf(("%ld: allocate_sema() -> %lx\n", get_thread_ident(), (long)aSemaphore));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
215
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 return (type_sema) aSemaphore;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
218
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 void free_sema(type_sema aSemaphore)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 dprintf(("%ld: free_sema(%lx) called\n", get_thread_ident(), (long)aSemaphore));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
222
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 CloseHandle((HANDLE) aSemaphore);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
225
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 void down_sema(type_sema aSemaphore)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 DWORD waitResult;
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 dprintf(("%ld: down_sema(%lx) called\n", get_thread_ident(), (long)aSemaphore));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
231
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 waitResult = WaitForSingleObject( (HANDLE) aSemaphore, INFINITE);
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
233
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 dprintf(("%ld: down_sema(%lx) return: %l\n", get_thread_ident(),(long) aSemaphore, waitResult));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 }
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
236
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 void up_sema(type_sema aSemaphore)
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 {
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 ReleaseSemaphore(
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 (HANDLE) aSemaphore, /* Handle of semaphore */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 1, /* increment count by one */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 NULL); /* not interested in previous count */
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
243
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 dprintf(("%ld: up_sema(%lx)\n", get_thread_ident(), (long)aSemaphore));
1a52351a00b2 nt thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 }