annotate Python/thread_os2.h @ 13210:ff243b0f16ee legacy-trunk

Trent Mick <trentm@activestate.com>: The common technique for printing out a pointer has been to cast to a long and use the "%lx" printf modifier. This is incorrect on Win64 where casting to a long truncates the pointer. The "%p" formatter should be used instead. The problem as stated by Tim: > Unfortunately, the C committee refused to define what %p conversion "looks > like" -- they explicitly allowed it to be implementation-defined. Older > versions of Microsoft C even stuck a colon in the middle of the address (in > the days of segment+offset addressing)! The result is that the hex value of a pointer will maybe/maybe not have a 0x prepended to it. Notes on the patch: There are two main classes of changes: - in the various repr() functions that print out pointers - debugging printf's in the various thread_*.h files (these are why the patch is large) Closes SourceForge patch #100505.
author Fred Drake <fdrake@acm.org>
date Fri, 30 Jun 2000 15:01:00 +0000
parents 877d23bd5bdc
children 916fb024ce94
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
41 long PyThread_get_thread_ident(void);
2649
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 */
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
47 static void PyThread__init_thread(void)
2649
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 */
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
54 int PyThread_start_new_thread(void (*func)(void *), void *arg)
2649
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
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
59 aThread = _beginthread(func,NULL,65536,arg);
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
70 long PyThread_get_thread_ident(void)
2649
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)
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
76 PyThread_init_thread();
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
82 static void do_PyThread_exit_thread(int no_cleanup)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
84 dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident()));
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
93 void PyThread_exit_thread(void)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
95 do_PyThread_exit_thread(0);
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
98 void PyThread__exit_thread(void)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
100 do_PyThread_exit_thread(1);
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
104 static void do_PyThread_exit_prog(int status, int no_cleanup)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
106 dprintf(("PyThread_exit_prog(%d) called\n", status));
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
114 void PyThread_exit_prog(int status)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
116 do_PyThread_exit_prog(status, 0);
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
119 void PyThread__exit_prog _P1(int status)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
121 do_PyThread_exit_prog(status, 1);
2649
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 */
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
130 PyThread_type_lock PyThread_allocate_lock(void)
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
135 dprintf(("PyThread_allocate_lock called\n"));
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 if (!initialized)
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
137 PyThread_init_thread();
2649
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
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
144 dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock));
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
146 return (PyThread_type_lock) aLock;
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
149 void PyThread_free_lock(PyThread_type_lock aLock)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 {
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
151 dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock));
2649
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 */
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
162 int PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag)
2649
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
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
169 dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(),
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
170 aLock, waitflag));
2649
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);
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
173 if( tid == PyThread_get_thread_ident() ) { /* if we own this lock */
2649
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
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
184 dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n",
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
185 PyThread_get_thread_ident(),aLock, waitflag, success));
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
190 void PyThread_release_lock(PyThread_type_lock aLock)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 {
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
192 dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock));
2649
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 ) {
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
195 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n",
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
196 PyThread_get_thread_ident(), aLock, GetLastError()));
2649
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 */
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
203 PyThread_type_sema PyThread_allocate_sema(int value)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
205 return (PyThread_type_sema) 0;
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
208 void PyThread_free_sema(PyThread_type_sema aSemaphore)
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
213 int PyThread_down_sema(PyThread_type_sema aSemaphore, int waitflag)
2649
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
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
218 void PyThread_up_sema(PyThread_type_sema aSemaphore)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 {
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
220 dprintf(("%ld: PyThread_up_sema(%p)\n", PyThread_get_thread_ident(), aSemaphore));
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 }