@@ -300,98 +300,6 @@ PyThread_hang_thread(void)
300300 }
301301}
302302
303- /*
304- * Lock support. It has to be implemented as semaphores.
305- * I [Dag] tried to implement it with mutex but I could find a way to
306- * tell whether a thread already own the lock or not.
307- */
308- PyThread_type_lock
309- PyThread_allocate_lock (void )
310- {
311- PNRMUTEX mutex ;
312-
313- if (!initialized )
314- PyThread_init_thread ();
315-
316- mutex = AllocNonRecursiveMutex () ;
317-
318- PyThread_type_lock aLock = (PyThread_type_lock ) mutex ;
319- assert (aLock );
320-
321- return aLock ;
322- }
323-
324- void
325- PyThread_free_lock (PyThread_type_lock aLock )
326- {
327- FreeNonRecursiveMutex (aLock ) ;
328- }
329-
330- // WaitForSingleObject() accepts timeout in milliseconds in the range
331- // [0; 0xFFFFFFFE] (DWORD type). INFINITE value (0xFFFFFFFF) means no
332- // timeout. 0xFFFFFFFE milliseconds is around 49.7 days.
333- const DWORD TIMEOUT_MS_MAX = 0xFFFFFFFE ;
334-
335- /*
336- * Return 1 on success if the lock was acquired
337- *
338- * and 0 if the lock was not acquired. This means a 0 is returned
339- * if the lock has already been acquired by this thread!
340- */
341- PyLockStatus
342- PyThread_acquire_lock_timed (PyThread_type_lock aLock ,
343- PY_TIMEOUT_T microseconds , int intr_flag )
344- {
345- assert (aLock );
346-
347- /* Fow now, intr_flag does nothing on Windows, and lock acquires are
348- * uninterruptible. */
349- PyLockStatus success ;
350- PY_TIMEOUT_T milliseconds ;
351-
352- if (microseconds >= 0 ) {
353- milliseconds = microseconds / 1000 ;
354- // Round milliseconds away from zero
355- if (microseconds % 1000 > 0 ) {
356- milliseconds ++ ;
357- }
358- if (milliseconds > (PY_TIMEOUT_T )TIMEOUT_MS_MAX ) {
359- // bpo-41710: PyThread_acquire_lock_timed() cannot report timeout
360- // overflow to the caller, so clamp the timeout to
361- // [0, TIMEOUT_MS_MAX] milliseconds.
362- //
363- // _thread.Lock.acquire() and _thread.RLock.acquire() raise an
364- // OverflowError if microseconds is greater than PY_TIMEOUT_MAX.
365- milliseconds = TIMEOUT_MS_MAX ;
366- }
367- assert (milliseconds != INFINITE );
368- }
369- else {
370- milliseconds = INFINITE ;
371- }
372-
373- if (EnterNonRecursiveMutex ((PNRMUTEX )aLock ,
374- (DWORD )milliseconds ) == WAIT_OBJECT_0 ) {
375- success = PY_LOCK_ACQUIRED ;
376- }
377- else {
378- success = PY_LOCK_FAILURE ;
379- }
380-
381- return success ;
382- }
383- int
384- PyThread_acquire_lock (PyThread_type_lock aLock , int waitflag )
385- {
386- return PyThread_acquire_lock_timed (aLock , waitflag ? -1 : 0 , 0 );
387- }
388-
389- void
390- PyThread_release_lock (PyThread_type_lock aLock )
391- {
392- assert (aLock );
393- (void )LeaveNonRecursiveMutex ((PNRMUTEX ) aLock );
394- }
395303
396304/* minimum/maximum thread stack sizes supported */
397305#define THREAD_MIN_STACKSIZE 0x8000 /* 32 KiB */
0 commit comments