@@ -388,33 +388,37 @@ static int autoTLSkey = 0;
388388/* Internal initialization/finalization functions called by
389389 Py_Initialize/Py_Finalize
390390*/
391- void _PyGILState_Init (PyInterpreterState * i , PyThreadState * t )
391+ void
392+ _PyGILState_Init (PyInterpreterState * i , PyThreadState * t )
392393{
393- assert (i && t ); /* must init with a valid states */
394+ assert (i && t ); /* must init with valid states */
394395 autoTLSkey = PyThread_create_key ();
395396 autoInterpreterState = i ;
396397 /* Now stash the thread state for this thread in TLS */
397398 PyThread_set_key_value (autoTLSkey , (void * )t );
398- assert (t -> gilstate_counter == 0 ); /* must be a new thread state */
399+ assert (t -> gilstate_counter == 0 ); /* must be a new thread state */
399400 t -> gilstate_counter = 1 ;
400401}
401402
402- void _PyGILState_Fini (void )
403+ void
404+ _PyGILState_Fini (void )
403405{
404406 PyThread_delete_key (autoTLSkey );
405407 autoTLSkey = 0 ;
406408 autoInterpreterState = NULL ;;
407409}
408410
409411/* The public functions */
410- PyThreadState * PyGILState_GetThisThreadState (void )
412+ PyThreadState *
413+ PyGILState_GetThisThreadState (void )
411414{
412- if (autoInterpreterState == NULL || autoTLSkey == 0 )
415+ if (autoInterpreterState == NULL || autoTLSkey == 0 )
413416 return NULL ;
414- return (PyThreadState * ) PyThread_get_key_value (autoTLSkey );
417+ return (PyThreadState * )PyThread_get_key_value (autoTLSkey );
415418}
416419
417- PyGILState_STATE PyGILState_Ensure (void )
420+ PyGILState_STATE
421+ PyGILState_Ensure (void )
418422{
419423 int current ;
420424 PyThreadState * tcur ;
@@ -425,58 +429,60 @@ PyGILState_STATE PyGILState_Ensure(void)
425429 */
426430 assert (autoInterpreterState ); /* Py_Initialize() hasn't been called! */
427431 tcur = PyThread_get_key_value (autoTLSkey );
428- if (tcur == NULL ) {
432+ if (tcur == NULL ) {
429433 /* Create a new thread state for this thread */
430434 tcur = PyThreadState_New (autoInterpreterState );
431- if (tcur == NULL )
435+ if (tcur == NULL )
432436 Py_FatalError ("Couldn't create thread-state for new thread" );
433437 PyThread_set_key_value (autoTLSkey , (void * )tcur );
434438 current = 0 ; /* new thread state is never current */
435- } else
439+ }
440+ else
436441 current = PyThreadState_IsCurrent (tcur );
437- if (! current )
442+ if (current == 0 )
438443 PyEval_RestoreThread (tcur );
439444 /* Update our counter in the thread-state - no need for locks:
440445 - tcur will remain valid as we hold the GIL.
441446 - the counter is safe as we are the only thread "allowed"
442447 to modify this value
443448 */
444- tcur -> gilstate_counter ++ ;
449+ ++ tcur -> gilstate_counter ;
445450 return current ? PyGILState_LOCKED : PyGILState_UNLOCKED ;
446451}
447452
448- void PyGILState_Release (PyGILState_STATE oldstate )
453+ void
454+ PyGILState_Release (PyGILState_STATE oldstate )
449455{
450456 PyThreadState * tcur = PyThread_get_key_value (autoTLSkey );
451- if (tcur == NULL )
457+ if (tcur == NULL )
452458 Py_FatalError ("auto-releasing thread-state, "
453459 "but no thread-state for this thread" );
454460 /* We must hold the GIL and have our thread state current */
455461 /* XXX - remove the check - the assert should be fine,
456462 but while this is very new (April 2003), the extra check
457463 by release-only users can't hurt.
458464 */
459- if (!PyThreadState_IsCurrent (tcur ))
465+ if (! PyThreadState_IsCurrent (tcur ))
460466 Py_FatalError ("This thread state must be current when releasing" );
461- assert (PyThreadState_IsCurrent (tcur ));
462- tcur -> gilstate_counter -= 1 ;
463- assert (tcur -> gilstate_counter >= 0 ); /* illegal counter value */
467+ assert (PyThreadState_IsCurrent (tcur ));
468+ -- tcur -> gilstate_counter ;
469+ assert (tcur -> gilstate_counter >= 0 ); /* illegal counter value */
464470
465471 /* If we are about to destroy this thread-state, we must
466472 clear it while the lock is held, as destructors may run
467473 */
468- if (tcur -> gilstate_counter == 0 ) {
474+ if (tcur -> gilstate_counter == 0 ) {
469475 /* can't have been locked when we created it */
470- assert (oldstate == PyGILState_UNLOCKED );
476+ assert (oldstate == PyGILState_UNLOCKED );
471477 PyThreadState_Clear (tcur );
472478 }
473479
474480 /* Release the lock if necessary */
475- if (oldstate == PyGILState_UNLOCKED )
481+ if (oldstate == PyGILState_UNLOCKED )
476482 PyEval_ReleaseThread (tcur );
477483
478484 /* Now complete destruction of the thread if necessary */
479- if (tcur -> gilstate_counter == 0 ) {
485+ if (tcur -> gilstate_counter == 0 ) {
480486 /* Delete this thread from our TLS */
481487 PyThread_delete_key_value (autoTLSkey );
482488 /* Delete the thread-state */
0 commit comments