Skip to content

Commit 1bd8ced

Browse files
author
tim_one
committed
Style guide & consistency changes. No semantic changes.
git-svn-id: http://svn.python.org/projects/python/trunk@37563 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 9082463 commit 1bd8ced

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

Python/pystate.c

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */

Python/thread.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ static struct key *keyhead = NULL;
157157
static int nkeys = 0;
158158
static PyThread_type_lock keymutex = NULL;
159159

160-
static struct key *find_key(int key, void *value)
160+
static struct key *
161+
find_key(int key, void *value)
161162
{
162163
struct key *p;
163164
long id = PyThread_get_thread_ident();
@@ -180,14 +181,16 @@ static struct key *find_key(int key, void *value)
180181
return p;
181182
}
182183

183-
int PyThread_create_key(void)
184+
int
185+
PyThread_create_key(void)
184186
{
185187
if (keymutex == NULL)
186188
keymutex = PyThread_allocate_lock();
187189
return ++nkeys;
188190
}
189191

190-
void PyThread_delete_key(int key)
192+
void
193+
PyThread_delete_key(int key)
191194
{
192195
struct key *p, **q;
193196
PyThread_acquire_lock(keymutex, 1);
@@ -204,7 +207,8 @@ void PyThread_delete_key(int key)
204207
PyThread_release_lock(keymutex);
205208
}
206209

207-
int PyThread_set_key_value(int key, void *value)
210+
int
211+
PyThread_set_key_value(int key, void *value)
208212
{
209213
struct key *p = find_key(key, value);
210214
if (p == NULL)
@@ -213,7 +217,8 @@ int PyThread_set_key_value(int key, void *value)
213217
return 0;
214218
}
215219

216-
void *PyThread_get_key_value(int key)
220+
void *
221+
PyThread_get_key_value(int key)
217222
{
218223
struct key *p = find_key(key, NULL);
219224
if (p == NULL)
@@ -222,7 +227,8 @@ void *PyThread_get_key_value(int key)
222227
return p->value;
223228
}
224229

225-
void PyThread_delete_key_value(int key)
230+
void
231+
PyThread_delete_key_value(int key)
226232
{
227233
long id = PyThread_get_thread_ident();
228234
struct key *p, **q;

0 commit comments

Comments
 (0)