annotate Python/thread_os2.h @ 5758:bfe9ba74c19e legacy-trunk

Fix problem discovered by Greg McFarlane: when an imported module replaces its own entry in sys.module, reference count errors ensue; even if there is no reference count problem, it would be preferable for the import to yield the new thing in sys.modules anyway (if only because that's what later imports will yield). This opens the road to an official hack to implement a __getattr__ like feature for modules: stick an instance in sys.modules[__name__].
author Guido van Rossum <guido@python.org>
date Thu, 10 Jul 1997 18:00:45 +0000
parents 65d2d8e67da3
children 5e31d381fa47
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4371
diff changeset
30 ******************************************************************/
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* This code implemented by cvale@netcom.com */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #define INCL_DOSPROCESS
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #define INCL_DOSSEMAPHORES
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 #include "os2.h"
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 #include "limits.h"
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 #include "process.h"
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 long get_thread_ident(void);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 /*
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 * Initialization of the C package, should not be needed.
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 static void _init_thread(void)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 /*
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 * Thread support.
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 int start_new_thread(void (*func)(void *), void *arg)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 int aThread;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 int success = 1;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
58
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 aThread = _beginthread(func,4096,arg);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 if( aThread == -1 ) {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 success = 0;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 fprintf(stderr,"aThread failed == %d",aThread);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 dprintf(("_beginthread failed. return %ld\n", errno));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 return success;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 long get_thread_ident(void)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 PPIB pib;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 PTIB tib;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 if (!initialized)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 init_thread();
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
77
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 DosGetInfoBlocks(&tib,&pib);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 return tib->tib_ptib2->tib2_ultid;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 static void do_exit_thread(int no_cleanup)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 dprintf(("%ld: exit_thread called\n", get_thread_ident()));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 if (!initialized)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 if (no_cleanup)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 _exit(0);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 else
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 exit(0);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 _endthread();
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 void exit_thread(void)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 do_exit_thread(0);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
97
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 void _exit_thread(void)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 do_exit_thread(1);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 #ifndef NO_EXIT_PROG
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 static void do_exit_prog(int status, int no_cleanup)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 dprintf(("exit_prog(%d) called\n", status));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 if (!initialized)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 if (no_cleanup)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 _exit(status);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 else
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 exit(status);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 void exit_prog(int status)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 do_exit_prog(status, 0);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 void _exit_prog _P1(int status)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 do_exit_prog(status, 1);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 #endif /* NO_EXIT_PROG */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
124
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 /*
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 * Lock support. It has too be implemented as semaphores.
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 * I [Dag] tried to implement it with mutex but I could find a way to
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 * tell whether a thread already own the lock or not.
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 type_lock allocate_lock(void)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 HMTX aLock;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 APIRET rc;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
134
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 dprintf(("allocate_lock called\n"));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 if (!initialized)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 init_thread();
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 DosCreateMutexSem(NULL, /* Sem name */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 &aLock, /* the semaphone */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 0, /* shared ? */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 0); /* initial state */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
143
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 dprintf(("%ld: allocate_lock() -> %lx\n", get_thread_ident(), (long)aLock));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 return (type_lock) aLock;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
148
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 void free_lock(type_lock aLock)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 dprintf(("%ld: free_lock(%lx) called\n", get_thread_ident(),(long)aLock));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
152
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 DosCloseMutexSem((HMTX)aLock);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
155
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 /*
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 * Return 1 on success if the lock was acquired
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 *
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 * and 0 if the lock was not acquired. This means a 0 is returned
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 * if the lock has already been acquired by this thread!
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 int acquire_lock(type_lock aLock, int waitflag)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 int success = 1;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 ULONG rc, count;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 PID pid = 0;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 TID tid = 0;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
168
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 dprintf(("%ld: acquire_lock(%lx, %d) called\n", get_thread_ident(),
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 (long)aLock, waitflag));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
171
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 DosQueryMutexSem((HMTX)aLock,&pid,&tid,&count);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 if( tid == get_thread_ident() ) { /* if we own this lock */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 success = 0;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 } else {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 rc = DosRequestMutexSem((HMTX) aLock,
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 (waitflag == 1 ? SEM_INDEFINITE_WAIT : 0));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
178
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 if( rc != 0) {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 success = 0; /* We failed */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
183
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 dprintf(("%ld: acquire_lock(%lx, %d) -> %d\n",
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 get_thread_ident(),(long)aLock, waitflag, success));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
186
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 return success;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
189
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 void release_lock(type_lock aLock)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 dprintf(("%ld: release_lock(%lx) called\n", get_thread_ident(),(long)aLock));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
193
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 if ( DosReleaseMutexSem( (HMTX) aLock ) != 0 ) {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 dprintf(("%ld: Could not release_lock(%lx) error: %l\n",
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 get_thread_ident(), (long)aLock, GetLastError()));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
199
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 /*
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 * Semaphore support.
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 type_sema allocate_sema(int value)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 return (type_sema) 0;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
207
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 void free_sema(type_sema aSemaphore)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
210
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
212
4371
c277ee8c669c Sjoerd's thread changes (including down_sema typo fix).
Guido van Rossum <guido@python.org>
parents: 2649
diff changeset
213 void down_sema(type_sema aSemaphore, int waitflag)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
217
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 void up_sema(type_sema aSemaphore)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 dprintf(("%ld: up_sema(%lx)\n", get_thread_ident(), (long)aSemaphore));
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 }