~ubuntu-branches/ubuntu/oneiric/python2.5/oneiric

« back to all changes in this revision

Viewing changes to Python/thread.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-12-21 08:57:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081221085749-bijjr25h8na5jdsu
Tags: 2.5.3-0ubuntu1
* New upstream version.
* Regenerate the included documentation.
* Add an option --install-layout=deb, which is ignored for 2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
264
264
static struct key *
265
265
find_key(int key, void *value)
266
266
{
267
 
        struct key *p;
 
267
        struct key *p, *prev_p;
268
268
        long id = PyThread_get_thread_ident();
269
269
 
270
270
        if (!keymutex)
271
271
                return NULL;
272
272
        PyThread_acquire_lock(keymutex, 1);
 
273
        prev_p = NULL;
273
274
        for (p = keyhead; p != NULL; p = p->next) {
274
275
                if (p->id == id && p->key == key)
275
276
                        goto Done;
 
277
                /* Sanity check.  These states should never happen but if
 
278
                 * they do we must abort.  Otherwise we'll end up spinning in
 
279
                 * in a tight loop with the lock held.  A similar check is done
 
280
                 * in pystate.c tstate_delete_common().  */
 
281
                if (p == prev_p)
 
282
                        Py_FatalError("tls find_key: small circular list(!)");
 
283
                prev_p = p;
 
284
                if (p->next == keyhead)
 
285
                        Py_FatalError("tls find_key: circular list(!)");
276
286
        }
277
287
        if (value == NULL) {
278
288
                assert(p == NULL);
381
391
        PyThread_release_lock(keymutex);
382
392
}
383
393
 
 
394
/* Forget everything not associated with the current thread id.
 
395
 * This function is called from PyOS_AfterFork().  It is necessary
 
396
 * because other thread ids which were in use at the time of the fork
 
397
 * may be reused for new threads created in the forked process.
 
398
 */
 
399
void
 
400
PyThread_ReInitTLS(void)
 
401
{
 
402
        long id = PyThread_get_thread_ident();
 
403
        struct key *p, **q;
 
404
 
 
405
        if (!keymutex)
 
406
                return;
 
407
        
 
408
        /* As with interpreter_lock in PyEval_ReInitThreads()
 
409
           we just create a new lock without freeing the old one */
 
410
        keymutex = PyThread_allocate_lock();
 
411
 
 
412
        /* Delete all keys which do not match the current thread id */
 
413
        q = &keyhead;
 
414
        while ((p = *q) != NULL) {
 
415
                if (p->id != id) {
 
416
                        *q = p->next;
 
417
                        free((void *)p);
 
418
                        /* NB This does *not* free p->value! */
 
419
                }
 
420
                else
 
421
                        q = &p->next;
 
422
        }
 
423
}
 
424
 
384
425
#endif /* Py_HAVE_NATIVE_TLS */