| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -388,33 +388,37 @@ static int autoTLSkey = 0; | |||
| 388 | 388 | /* Internal initialization/finalization functions called by | |
| 389 | 389 | Py_Initialize/Py_Finalize | |
| 390 | 390 | */ | |
| 391 | - void _PyGILState_Init(PyInterpreterState *i, PyThreadState *t) | ||
| 391 | + void | ||
| 392 | + _PyGILState_Init(PyInterpreterState *i, PyThreadState *t) | ||
| 392 | 393 | { | |
| 393 | - assert(i && t); /* must init with a valid states */ | ||
| 394 | + assert(i && t); /* must init with valid states */ | ||
| 394 | 395 | autoTLSkey = PyThread_create_key(); | |
| 395 | 396 | autoInterpreterState = i; | |
| 396 | 397 | /* Now stash the thread state for this thread in TLS */ | |
| 397 | 398 | 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 */ | ||
| 399 | 400 | t->gilstate_counter = 1; | |
| 400 | 401 | } | |
| 401 | 402 | ||
| 402 | - void _PyGILState_Fini(void) | ||
| 403 | + void | ||
| 404 | + _PyGILState_Fini(void) | ||
| 403 | 405 | { | |
| 404 | 406 | PyThread_delete_key(autoTLSkey); | |
| 405 | 407 | autoTLSkey = 0; | |
| 406 | 408 | autoInterpreterState = NULL;; | |
| 407 | 409 | } | |
| 408 | 410 | ||
| 409 | 411 | /* The public functions */ | |
| 410 | - PyThreadState *PyGILState_GetThisThreadState(void) | ||
| 412 | + PyThreadState * | ||
| 413 | + PyGILState_GetThisThreadState(void) | ||
| 411 | 414 | { | |
| 412 | - if (autoInterpreterState==NULL || autoTLSkey==0) | ||
| 415 | + if (autoInterpreterState == NULL || autoTLSkey == 0) | ||
| 413 | 416 | return NULL; | |
| 414 | - return (PyThreadState *) PyThread_get_key_value(autoTLSkey); | ||
| 417 | + return (PyThreadState *)PyThread_get_key_value(autoTLSkey); | ||
| 415 | 418 | } | |
| 416 | 419 | ||
| 417 | - PyGILState_STATE PyGILState_Ensure(void) | ||
| 420 | + PyGILState_STATE | ||
| 421 | + PyGILState_Ensure(void) | ||
| 418 | 422 | { | |
| 419 | 423 | int current; | |
| 420 | 424 | PyThreadState *tcur; | |
@@ -425,58 +429,60 @@ PyGILState_STATE PyGILState_Ensure(void) | |||
| 425 | 429 | */ | |
| 426 | 430 | assert(autoInterpreterState); /* Py_Initialize() hasn't been called! */ | |
| 427 | 431 | tcur = PyThread_get_key_value(autoTLSkey); | |
| 428 | - if (tcur==NULL) { | ||
| 432 | + if (tcur == NULL) { | ||
| 429 | 433 | /* Create a new thread state for this thread */ | |
| 430 | 434 | tcur = PyThreadState_New(autoInterpreterState); | |
| 431 | - if (tcur==NULL) | ||
| 435 | + if (tcur == NULL) | ||
| 432 | 436 | Py_FatalError("Couldn't create thread-state for new thread"); | |
| 433 | 437 | PyThread_set_key_value(autoTLSkey, (void *)tcur); | |
| 434 | 438 | current = 0; /* new thread state is never current */ | |
| 435 | - } else | ||
| 439 | + } | ||
| 440 | + else | ||
| 436 | 441 | current = PyThreadState_IsCurrent(tcur); | |
| 437 | - if (!current) | ||
| 442 | + if (current == 0) | ||
| 438 | 443 | PyEval_RestoreThread(tcur); | |
| 439 | 444 | /* Update our counter in the thread-state - no need for locks: | |
| 440 | 445 | - tcur will remain valid as we hold the GIL. | |
| 441 | 446 | - the counter is safe as we are the only thread "allowed" | |
| 442 | 447 | to modify this value | |
| 443 | 448 | */ | |
| 444 | - tcur->gilstate_counter++; | ||
| 449 | + ++tcur->gilstate_counter; | ||
| 445 | 450 | return current ? PyGILState_LOCKED : PyGILState_UNLOCKED; | |
| 446 | 451 | } | |
| 447 | 452 | ||
| 448 | - void PyGILState_Release(PyGILState_STATE oldstate) | ||
| 453 | + void | ||
| 454 | + PyGILState_Release(PyGILState_STATE oldstate) | ||
| 449 | 455 | { | |
| 450 | 456 | PyThreadState *tcur = PyThread_get_key_value(autoTLSkey); | |
| 451 | - if (tcur==NULL) | ||
| 457 | + if (tcur == NULL) | ||
| 452 | 458 | Py_FatalError("auto-releasing thread-state, " | |
| 453 | 459 | "but no thread-state for this thread"); | |
| 454 | 460 | /* We must hold the GIL and have our thread state current */ | |
| 455 | 461 | /* XXX - remove the check - the assert should be fine, | |
| 456 | 462 | but while this is very new (April 2003), the extra check | |
| 457 | 463 | by release-only users can't hurt. | |
| 458 | 464 | */ | |
| 459 | - if (!PyThreadState_IsCurrent(tcur)) | ||
| 465 | + if (! PyThreadState_IsCurrent(tcur)) | ||
| 460 | 466 | 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 */ | ||
| 464 | 470 | ||
| 465 | 471 | /* If we are about to destroy this thread-state, we must | |
| 466 | 472 | clear it while the lock is held, as destructors may run | |
| 467 | 473 | */ | |
| 468 | - if (tcur->gilstate_counter==0) { | ||
| 474 | + if (tcur->gilstate_counter == 0) { | ||
| 469 | 475 | /* can't have been locked when we created it */ | |
| 470 | - assert(oldstate==PyGILState_UNLOCKED); | ||
| 476 | + assert(oldstate == PyGILState_UNLOCKED); | ||
| 471 | 477 | PyThreadState_Clear(tcur); | |
| 472 | 478 | } | |
| 473 | 479 | ||
| 474 | 480 | /* Release the lock if necessary */ | |
| 475 | - if (oldstate==PyGILState_UNLOCKED) | ||
| 481 | + if (oldstate == PyGILState_UNLOCKED) | ||
| 476 | 482 | PyEval_ReleaseThread(tcur); | |
| 477 | 483 | ||
| 478 | 484 | /* Now complete destruction of the thread if necessary */ | |
| 479 | - if (tcur->gilstate_counter==0) { | ||
| 485 | + if (tcur->gilstate_counter == 0) { | ||
| 480 | 486 | /* Delete this thread from our TLS */ | |
| 481 | 487 | PyThread_delete_key_value(autoTLSkey); | |
| 482 | 488 | /* Delete the thread-state */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -157,7 +157,8 @@ static struct key *keyhead = NULL; | |||
| 157 | 157 | static int nkeys = 0; | |
| 158 | 158 | static PyThread_type_lock keymutex = NULL; | |
| 159 | 159 | ||
| 160 | - static struct key *find_key(int key, void *value) | ||
| 160 | + static struct key * | ||
| 161 | + find_key(int key, void *value) | ||
| 161 | 162 | { | |
| 162 | 163 | struct key *p; | |
| 163 | 164 | long id = PyThread_get_thread_ident(); | |
@@ -180,14 +181,16 @@ static struct key *find_key(int key, void *value) | |||
| 180 | 181 | return p; | |
| 181 | 182 | } | |
| 182 | 183 | ||
| 183 | - int PyThread_create_key(void) | ||
| 184 | + int | ||
| 185 | + PyThread_create_key(void) | ||
| 184 | 186 | { | |
| 185 | 187 | if (keymutex == NULL) | |
| 186 | 188 | keymutex = PyThread_allocate_lock(); | |
| 187 | 189 | return ++nkeys; | |
| 188 | 190 | } | |
| 189 | 191 | ||
| 190 | - void PyThread_delete_key(int key) | ||
| 192 | + void | ||
| 193 | + PyThread_delete_key(int key) | ||
| 191 | 194 | { | |
| 192 | 195 | struct key *p, **q; | |
| 193 | 196 | PyThread_acquire_lock(keymutex, 1); | |
@@ -204,7 +207,8 @@ void PyThread_delete_key(int key) | |||
| 204 | 207 | PyThread_release_lock(keymutex); | |
| 205 | 208 | } | |
| 206 | 209 | ||
| 207 | - int PyThread_set_key_value(int key, void *value) | ||
| 210 | + int | ||
| 211 | + PyThread_set_key_value(int key, void *value) | ||
| 208 | 212 | { | |
| 209 | 213 | struct key *p = find_key(key, value); | |
| 210 | 214 | if (p == NULL) | |
@@ -213,7 +217,8 @@ int PyThread_set_key_value(int key, void *value) | |||
| 213 | 217 | return 0; | |
| 214 | 218 | } | |
| 215 | 219 | ||
| 216 | - void *PyThread_get_key_value(int key) | ||
| 220 | + void * | ||
| 221 | + PyThread_get_key_value(int key) | ||
| 217 | 222 | { | |
| 218 | 223 | struct key *p = find_key(key, NULL); | |
| 219 | 224 | if (p == NULL) | |
@@ -222,7 +227,8 @@ void *PyThread_get_key_value(int key) | |||
| 222 | 227 | return p->value; | |
| 223 | 228 | } | |
| 224 | 229 | ||
| 225 | - void PyThread_delete_key_value(int key) | ||
| 230 | + void | ||
| 231 | + PyThread_delete_key_value(int key) | ||
| 226 | 232 | { | |
| 227 | 233 | long id = PyThread_get_thread_ident(); | |
| 228 | 234 | struct key *p, **q; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments