annotate Python/thread_os2.h @ 24042:63fbbed10714 legacy-trunk

Simplify HTTPSConnection constructor. See discussion in SF bug 458463.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Fri, 28 Jun 2002 23:38:14 +0000
parents 5cbcfde3ad55
children b5837b8f3b2c
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 /* This code implemented by cvale@netcom.com */
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 #define INCL_DOSPROCESS
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #define INCL_DOSSEMAPHORES
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 #include "os2.h"
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 #include "limits.h"
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 #include "process.h"
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
10 #if defined(PYCC_GCC)
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
11 #include <sys/builtin.h>
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
12 #include <sys/fmutex.h>
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
13 #else
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
14 long PyThread_get_thread_ident(void);
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
15 #endif
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 /*
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 * Initialization of the C package, should not be needed.
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
20 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
21 PyThread__init_thread(void)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 /*
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 * Thread support.
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 */
20468
ebfd87e87884 Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
28 long
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
29 PyThread_start_new_thread(void (*func)(void *), void *arg)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 {
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 int aThread;
20468
ebfd87e87884 Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
32 int success = 0;
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
34 aThread = _beginthread(func,NULL,65536,arg);
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 if( aThread == -1 ) {
20468
ebfd87e87884 Partial patch from SF #452266, by Jason Petrone.
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
37 success = -1;
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 fprintf(stderr,"aThread failed == %d",aThread);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 dprintf(("_beginthread failed. return %ld\n", errno));
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
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 return success;
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
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
45 long
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
46 PyThread_get_thread_ident(void)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 {
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
48 #if !defined(PYCC_GCC)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 PPIB pib;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 PTIB tib;
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
51 #endif
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
52
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 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
54 PyThread_init_thread();
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
56 #if defined(PYCC_GCC)
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
57 return _gettid();
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
58 #else
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 DosGetInfoBlocks(&tib,&pib);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 return tib->tib_ptib2->tib2_ultid;
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
61 #endif
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
64 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
65 do_PyThread_exit_thread(int no_cleanup)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
67 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
68 if (!initialized)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 if (no_cleanup)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 _exit(0);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 else
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 exit(0);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 _endthread();
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
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
76 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
77 PyThread_exit_thread(void)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
79 do_PyThread_exit_thread(0);
2649
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
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
82 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
83 PyThread__exit_thread(void)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
85 do_PyThread_exit_thread(1);
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
87
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 #ifndef NO_EXIT_PROG
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
89 static void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
90 do_PyThread_exit_prog(int status, int no_cleanup)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
92 dprintf(("PyThread_exit_prog(%d) called\n", status));
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 if (!initialized)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 if (no_cleanup)
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 _exit(status);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 else
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 exit(status);
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
99
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
100 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
101 PyThread_exit_prog(int status)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
103 do_PyThread_exit_prog(status, 0);
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
105
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
106 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
107 PyThread__exit_prog(int status)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 {
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
109 do_PyThread_exit_prog(status, 1);
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 #endif /* NO_EXIT_PROG */
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 /*
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
114 * Lock support. This is implemented with an event semaphore and critical
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
115 * sections to make it behave more like a posix mutex than its OS/2
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
116 * counterparts.
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 */
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
118
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
119 typedef struct os2_lock_t {
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
120 int is_set;
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
121 HEV changed;
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
122 } *type_os2_lock;
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
123
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
124 PyThread_type_lock
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
125 PyThread_allocate_lock(void)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 {
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
127 #if defined(PYCC_GCC)
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
128 _fmutex *sem = malloc(sizeof(_fmutex));
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
129 if (!initialized)
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
130 PyThread_init_thread();
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
131 dprintf(("%ld: PyThread_allocate_lock() -> %lx\n",
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
132 PyThread_get_thread_ident(),
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
133 (long)sem));
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
134 if (_fmutex_create(sem, 0)) {
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
135 free(sem);
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
136 sem = NULL;
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
137 }
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
138 return (PyThread_type_lock) sem;
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
139 #else
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 APIRET rc;
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
141 type_os2_lock lock = (type_os2_lock)malloc(sizeof(struct os2_lock_t));
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
142
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
143 dprintf(("PyThread_allocate_lock called\n"));
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 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
145 PyThread_init_thread();
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
146
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
147 lock->is_set = 0;
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
148
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
149 DosCreateEventSem(NULL, &lock->changed, 0, 0);
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
150
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
151 dprintf(("%ld: PyThread_allocate_lock() -> %p\n",
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
152 PyThread_get_thread_ident(),
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
153 lock->changed));
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
155 return (PyThread_type_lock) lock;
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
156 #endif
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
158
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
159 void
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
160 PyThread_free_lock(PyThread_type_lock aLock)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 {
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
162 #if !defined(PYCC_GCC)
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
163 type_os2_lock lock = (type_os2_lock)aLock;
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
164 #endif
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
165
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
166 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
167
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
168 #if defined(PYCC_GCC)
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
169 if (aLock) {
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
170 _fmutex_close((_fmutex *)aLock);
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
171 free((_fmutex *)aLock);
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
172 }
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
173 #else
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
174 DosCloseEventSem(lock->changed);
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
175 free(aLock);
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
176 #endif
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 }
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 /*
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 * Return 1 on success if the lock was acquired
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 *
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
182 * and 0 if the lock was not acquired.
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 */
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
184 int
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
185 PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 {
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
187 #if !defined(PYCC_GCC)
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
188 int done = 0;
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
189 ULONG count;
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 PID pid = 0;
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 TID tid = 0;
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
192 type_os2_lock lock = (type_os2_lock)aLock;
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
193 #endif
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
194
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
195 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
196 aLock, waitflag));
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
197
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
198 #if defined(PYCC_GCC)
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
199 /* always successful if the lock doesn't exist */
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
200 if (aLock && _fmutex_request((_fmutex *)aLock, waitflag ? 0 : _FMR_NOWAIT))
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
201 return 0;
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
202 #else
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
203 while (!done) {
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
204 /* if the lock is currently set, we have to wait for the state to change */
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
205 if (lock->is_set) {
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
206 if (!waitflag)
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
207 return 0;
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
208 DosWaitEventSem(lock->changed, SEM_INDEFINITE_WAIT);
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
209 }
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
210
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
211 /*
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
212 * enter a critical section and try to get the semaphore. If
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
213 * it is still locked, we will try again.
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
214 */
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
215 if (DosEnterCritSec())
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
216 return 0;
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
217
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
218 if (!lock->is_set) {
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
219 lock->is_set = 1;
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
220 DosResetEventSem(lock->changed, &count);
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
221 done = 1;
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 }
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
223
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
224 DosExitCritSec();
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 }
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
226 #endif
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
227
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
228 return 1;
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 }
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
230
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
231 void PyThread_release_lock(PyThread_type_lock aLock)
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 {
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
233 #if defined(PYCC_GCC)
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
234 type_os2_lock lock = (type_os2_lock)aLock;
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
235 #endif
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
236
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
237 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
238
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
239 #if defined(PYCC_GCC)
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
240 if (aLock)
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
241 _fmutex_release((_fmutex *)aLock);
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
242 #else
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
243 if (!lock->is_set) {
13210
ff243b0f16ee Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 9679
diff changeset
244 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
245 PyThread_get_thread_ident(), aLock, GetLastError()));
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
246 return;
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 }
20782
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
248
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
249
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
250 if (DosEnterCritSec()) {
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
251 dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n",
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
252 PyThread_get_thread_ident(), aLock, GetLastError()));
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
253 return;
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
254 }
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
255
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
256 lock->is_set = 0;
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
257 DosPostEventSem(lock->changed);
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
258
b1d9029e09d1 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Tim Peters <tim.peters@gmail.com>
parents: 20468
diff changeset
259 DosExitCritSec();
22054
5cbcfde3ad55 OS/2 EMX port changes (Python part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21766
diff changeset
260 #endif
2649
063a96b49b3e OS/2 thread support
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 }