@@ -28,85 +28,86 @@ PyThread__init_thread(void)
2828long
2929PyThread_start_new_thread (void (* func )(void * ), void * arg )
3030{
31- int aThread ;
32- int success = 0 ;
31+ int aThread ;
32+ int success = 0 ;
3333
34- aThread = _beginthread (func ,NULL ,65536 ,arg );
34+ aThread = _beginthread (func ,NULL ,65536 ,arg );
3535
36- if ( aThread == -1 ) {
37- success = -1 ;
38- fprintf (stderr ,"aThread failed == %d" ,aThread );
39- dprintf (("_beginthread failed. return %ld\n" , errno ));
40- }
36+ if ( aThread == -1 ) {
37+ success = -1 ;
38+ fprintf (stderr , "aThread failed == %d" , aThread );
39+ dprintf (("_beginthread failed. return %ld\n" , errno ));
40+ }
4141
42- return success ;
42+ return success ;
4343}
4444
4545long
4646PyThread_get_thread_ident (void )
4747{
4848#if !defined(PYCC_GCC )
49- PPIB pib ;
50- PTIB tib ;
49+ PPIB pib ;
50+ PTIB tib ;
5151#endif
5252
53- if (!initialized )
54- PyThread_init_thread ();
55-
53+ if (!initialized )
54+ PyThread_init_thread ();
55+
5656#if defined(PYCC_GCC )
57- return _gettid ();
57+ return _gettid ();
5858#else
59- DosGetInfoBlocks (& tib ,& pib );
60- return tib -> tib_ptib2 -> tib2_ultid ;
59+ DosGetInfoBlocks (& tib , & pib );
60+ return tib -> tib_ptib2 -> tib2_ultid ;
6161#endif
6262}
6363
6464static void
6565do_PyThread_exit_thread (int no_cleanup )
6666{
67- dprintf (("%ld: PyThread_exit_thread called\n" , PyThread_get_thread_ident ()));
68- if (!initialized )
69- if (no_cleanup )
70- _exit (0 );
71- else
72- exit (0 );
73- _endthread ();
67+ dprintf (("%ld: PyThread_exit_thread called\n" ,
68+ PyThread_get_thread_ident ()));
69+ if (!initialized )
70+ if (no_cleanup )
71+ _exit (0 );
72+ else
73+ exit (0 );
74+ _endthread ();
7475}
7576
7677void
7778PyThread_exit_thread (void )
7879{
79- do_PyThread_exit_thread (0 );
80+ do_PyThread_exit_thread (0 );
8081}
8182
8283void
8384PyThread__exit_thread (void )
8485{
85- do_PyThread_exit_thread (1 );
86+ do_PyThread_exit_thread (1 );
8687}
8788
8889#ifndef NO_EXIT_PROG
8990static void
9091do_PyThread_exit_prog (int status , int no_cleanup )
9192{
92- dprintf (("PyThread_exit_prog(%d) called\n" , status ));
93- if (!initialized )
94- if (no_cleanup )
95- _exit (status );
96- else
97- exit (status );
93+ dprintf (("PyThread_exit_prog(%d) called\n" , status ));
94+ if (!initialized )
95+ if (no_cleanup )
96+ _exit (status );
97+ else
98+ exit (status );
9899}
99100
100101void
101102PyThread_exit_prog (int status )
102103{
103- do_PyThread_exit_prog (status , 0 );
104+ do_PyThread_exit_prog (status , 0 );
104105}
105106
106107void
107108PyThread__exit_prog (int status )
108109{
109- do_PyThread_exit_prog (status , 1 );
110+ do_PyThread_exit_prog (status , 1 );
110111}
111112#endif /* NO_EXIT_PROG */
112113
@@ -117,62 +118,63 @@ PyThread__exit_prog(int status)
117118 */
118119
119120typedef struct os2_lock_t {
120- int is_set ;
121- HEV changed ;
121+ int is_set ;
122+ HEV changed ;
122123} * type_os2_lock ;
123124
124125PyThread_type_lock
125126PyThread_allocate_lock (void )
126127{
127128#if defined(PYCC_GCC )
128- _fmutex * sem = malloc (sizeof (_fmutex ));
129- if (!initialized )
130- PyThread_init_thread ();
131- dprintf (("%ld: PyThread_allocate_lock() -> %lx\n" ,
132- PyThread_get_thread_ident (),
133- (long )sem ));
134- if (_fmutex_create (sem , 0 )) {
135- free (sem );
136- sem = NULL ;
137- }
138- return (PyThread_type_lock ) sem ;
129+ _fmutex * sem = malloc (sizeof (_fmutex ));
130+ if (!initialized )
131+ PyThread_init_thread ();
132+ dprintf (("%ld: PyThread_allocate_lock() -> %lx\n" ,
133+ PyThread_get_thread_ident (),
134+ (long )sem ));
135+ if (_fmutex_create (sem , 0 )) {
136+ free (sem );
137+ sem = NULL ;
138+ }
139+ return (PyThread_type_lock )sem ;
139140#else
140- APIRET rc ;
141- type_os2_lock lock = (type_os2_lock )malloc (sizeof (struct os2_lock_t ));
141+ APIRET rc ;
142+ type_os2_lock lock = (type_os2_lock )malloc (sizeof (struct os2_lock_t ));
142143
143- dprintf (("PyThread_allocate_lock called\n" ));
144- if (!initialized )
145- PyThread_init_thread ();
144+ dprintf (("PyThread_allocate_lock called\n" ));
145+ if (!initialized )
146+ PyThread_init_thread ();
146147
147- lock -> is_set = 0 ;
148+ lock -> is_set = 0 ;
148149
149- DosCreateEventSem (NULL , & lock -> changed , 0 , 0 );
150+ DosCreateEventSem (NULL , & lock -> changed , 0 , 0 );
150151
151- dprintf (("%ld: PyThread_allocate_lock() -> %p\n" ,
152- PyThread_get_thread_ident (),
153- lock -> changed ));
152+ dprintf (("%ld: PyThread_allocate_lock() -> %p\n" ,
153+ PyThread_get_thread_ident (),
154+ lock -> changed ));
154155
155- return (PyThread_type_lock ) lock ;
156+ return (PyThread_type_lock )lock ;
156157#endif
157158}
158159
159160void
160161PyThread_free_lock (PyThread_type_lock aLock )
161162{
162163#if !defined(PYCC_GCC )
163- type_os2_lock lock = (type_os2_lock )aLock ;
164+ type_os2_lock lock = (type_os2_lock )aLock ;
164165#endif
165166
166- dprintf (("%ld: PyThread_free_lock(%p) called\n" , PyThread_get_thread_ident (),aLock ));
167+ dprintf (("%ld: PyThread_free_lock(%p) called\n" ,
168+ PyThread_get_thread_ident (),aLock ));
167169
168170#if defined(PYCC_GCC )
169- if (aLock ) {
170- _fmutex_close ((_fmutex * )aLock );
171- free ((_fmutex * )aLock );
172- }
171+ if (aLock ) {
172+ _fmutex_close ((_fmutex * )aLock );
173+ free ((_fmutex * )aLock );
174+ }
173175#else
174- DosCloseEventSem (lock -> changed );
175- free (aLock );
176+ DosCloseEventSem (lock -> changed );
177+ free (aLock );
176178#endif
177179}
178180
@@ -185,77 +187,86 @@ int
185187PyThread_acquire_lock (PyThread_type_lock aLock , int waitflag )
186188{
187189#if !defined(PYCC_GCC )
188- int done = 0 ;
189- ULONG count ;
190- PID pid = 0 ;
191- TID tid = 0 ;
192- type_os2_lock lock = (type_os2_lock )aLock ;
190+ int done = 0 ;
191+ ULONG count ;
192+ PID pid = 0 ;
193+ TID tid = 0 ;
194+ type_os2_lock lock = (type_os2_lock )aLock ;
193195#endif
194196
195- dprintf (("%ld: PyThread_acquire_lock(%p, %d) called\n" , PyThread_get_thread_ident (),
196- aLock , waitflag ));
197+ dprintf (("%ld: PyThread_acquire_lock(%p, %d) called\n" ,
198+ PyThread_get_thread_ident (),
199+ aLock ,
200+ waitflag ));
197201
198202#if defined(PYCC_GCC )
199- /* always successful if the lock doesn't exist */
200- if (aLock && _fmutex_request ((_fmutex * )aLock , waitflag ? 0 : _FMR_NOWAIT ))
201- return 0 ;
203+ /* always successful if the lock doesn't exist */
204+ if (aLock &&
205+ _fmutex_request ((_fmutex * )aLock , waitflag ? 0 : _FMR_NOWAIT ))
206+ return 0 ;
202207#else
203- while (!done ) {
204- /* if the lock is currently set, we have to wait for the state to change */
205- if (lock -> is_set ) {
206- if (!waitflag )
207- return 0 ;
208- DosWaitEventSem (lock -> changed , SEM_INDEFINITE_WAIT );
209- }
210-
211- /*
212- * enter a critical section and try to get the semaphore. If
213- * it is still locked, we will try again.
214- */
215- if (DosEnterCritSec ())
216- return 0 ;
217-
218- if (!lock -> is_set ) {
219- lock -> is_set = 1 ;
220- DosResetEventSem (lock -> changed , & count );
221- done = 1 ;
222- }
223-
224- DosExitCritSec ();
225- }
208+ while (!done ) {
209+ /* if the lock is currently set, we have to wait for
210+ * the state to change
211+ */
212+ if (lock -> is_set ) {
213+ if (!waitflag )
214+ return 0 ;
215+ DosWaitEventSem (lock -> changed , SEM_INDEFINITE_WAIT );
216+ }
217+
218+ /* enter a critical section and try to get the semaphore. If
219+ * it is still locked, we will try again.
220+ */
221+ if (DosEnterCritSec ())
222+ return 0 ;
223+
224+ if (!lock -> is_set ) {
225+ lock -> is_set = 1 ;
226+ DosResetEventSem (lock -> changed , & count );
227+ done = 1 ;
228+ }
229+
230+ DosExitCritSec ();
231+ }
226232#endif
227233
228- return 1 ;
234+ return 1 ;
229235}
230236
231237void PyThread_release_lock (PyThread_type_lock aLock )
232238{
233239#if !defined(PYCC_GCC )
234- type_os2_lock lock = (type_os2_lock )aLock ;
240+ type_os2_lock lock = (type_os2_lock )aLock ;
235241#endif
236242
237- dprintf (("%ld: PyThread_release_lock(%p) called\n" , PyThread_get_thread_ident (),aLock ));
243+ dprintf (("%ld: PyThread_release_lock(%p) called\n" ,
244+ PyThread_get_thread_ident (),
245+ aLock ));
238246
239247#if defined(PYCC_GCC )
240- if (aLock )
241- _fmutex_release ((_fmutex * )aLock );
248+ if (aLock )
249+ _fmutex_release ((_fmutex * )aLock );
242250#else
243- if (!lock -> is_set ) {
244- dprintf (("%ld: Could not PyThread_release_lock(%p) error: %l\n" ,
245- PyThread_get_thread_ident (), aLock , GetLastError ()));
246- return ;
247- }
248-
249-
250- if (DosEnterCritSec ()) {
251- dprintf (("%ld: Could not PyThread_release_lock(%p) error: %l\n" ,
252- PyThread_get_thread_ident (), aLock , GetLastError ()));
253- return ;
254- }
255-
256- lock -> is_set = 0 ;
257- DosPostEventSem (lock -> changed );
258-
259- DosExitCritSec ();
251+ if (!lock -> is_set ) {
252+ dprintf (("%ld: Could not PyThread_release_lock(%p) error: %l\n" ,
253+ PyThread_get_thread_ident (),
254+ aLock ,
255+ GetLastError ()));
256+ return ;
257+ }
258+
259+ if (DosEnterCritSec ()) {
260+ dprintf (("%ld: Could not PyThread_release_lock(%p) error: %l\n" ,
261+ PyThread_get_thread_ident (),
262+ aLock ,
263+ GetLastError ()));
264+ return ;
265+ }
266+
267+ lock -> is_set = 0 ;
268+ DosPostEventSem (lock -> changed );
269+
270+ DosExitCritSec ();
260271#endif
261272}
0 commit comments