Mercurial > cpython-lru_cache-weakref
view Python/thread_pth.h @ 64085:4df0d2a13aa1 3.1
Merged revisions 81214,82302,82465,83090-83091,84097,84099 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r81214 | brett.cannon | 2010-05-16 00:20:16 +0200 (dim., 16 mai 2010) | 2 lines
A test was not guaranteeing cleanup in the face of an exception.
................
r82302 | benjamin.peterson | 2010-06-28 00:37:28 +0200 (lun., 28 juin 2010) | 15 lines
Merged revisions 81380 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81380 | brett.cannon | 2010-05-20 13:37:55 -0500 (Thu, 20 May 2010) | 8 lines
Turned out that if you used explicit relative import syntax
(e.g. from .os import sep) and it failed, import would still try the implicit
relative import semantics of an absolute import (from os import sep). That's
not right, so when level is negative, only do explicit relative import
semantics.
Fixes issue #7902. Thanks to Meador Inge for the patch.
........
................
r82465 | brett.cannon | 2010-07-03 03:32:48 +0200 (sam., 03 juil. 2010) | 3 lines
Make test_import a little bit more robust for cleaning up after itself in the
face of a failure.
................
r83090 | brett.cannon | 2010-07-23 16:03:16 +0200 (ven., 23 juil. 2010) | 4 lines
Explicitly test relative imports by reusing importlib tests.
Closes issue 8392. Thanks Virgil Dupras for the initial patch.
................
r83091 | brett.cannon | 2010-07-23 16:45:19 +0200 (ven., 23 juil. 2010) | 1 line
Stop shadowing a test class.
................
r84097 | florent.xicluna | 2010-08-16 20:41:19 +0200 (lun., 16 août 2010) | 1 line
Use test.support and unittest features. Fix duplicated test (bad merge in r79033). Fix comment for issue #7902.
................
r84099 | florent.xicluna | 2010-08-16 21:03:05 +0200 (lun., 16 août 2010) | 1 line
I get it wrong in r84097: s/relative/absolute/
................
| author | Florent Xicluna <florent.xicluna@gmail.com> |
|---|---|
| date | Mon, 16 Aug 2010 22:40:45 +0000 |
| parents | f197407bdba2 |
| children | b36cb4602e21 |
line wrap: on
line source
/* GNU pth threads interface http://www.gnu.org/software/pth 2000-05-03 Andy Dustman <andy@dustman.net> Adapted from Posix threads interface 12 May 1997 -- david arnold <davida@pobox.com> */ #include <stdlib.h> #include <string.h> #include <pth.h> /* A pth mutex isn't sufficient to model the Python lock type * because pth mutexes can be acquired multiple times by the * same thread. * * The pth_lock struct implements a Python lock as a "locked?" bit * and a <condition, mutex> pair. In general, if the bit can be acquired * instantly, it is, else the pair is used to block the thread until the * bit is cleared. */ typedef struct { char locked; /* 0=unlocked, 1=locked */ /* a <cond, mutex> pair to handle an acquire of a locked lock */ pth_cond_t lock_released; pth_mutex_t mut; } pth_lock; #define CHECK_STATUS(name) if (status == -1) { printf("%d ", status); perror(name); error = 1; } pth_attr_t PyThread_attr; /* * Initialization. */ static void PyThread__init_thread(void) { pth_init(); PyThread_attr = pth_attr_new(); pth_attr_set(PyThread_attr, PTH_ATTR_STACK_SIZE, 1<<18); pth_attr_set(PyThread_attr, PTH_ATTR_JOINABLE, FALSE); } /* * Thread support. */ long PyThread_start_new_thread(void (*func)(void *), void *arg) { pth_t th; dprintf(("PyThread_start_new_thread called\n")); if (!initialized) PyThread_init_thread(); th = pth_spawn(PyThread_attr, (void* (*)(void *))func, (void *)arg ); return th; } long PyThread_get_thread_ident(void) { volatile pth_t threadid; if (!initialized) PyThread_init_thread(); /* Jump through some hoops for Alpha OSF/1 */ threadid = pth_self(); return (long) *(long *) &threadid; } static void do_PyThread_exit_thread(int no_cleanup) { dprintf(("PyThread_exit_thread called\n")); if (!initialized) { if (no_cleanup) _exit(0); else exit(0); } } void PyThread_exit_thread(void) { do_PyThread_exit_thread(0); } void PyThread__exit_thread(void) { do_PyThread_exit_thread(1); } #ifndef NO_EXIT_PROG static void do_PyThread_exit_prog(int status, int no_cleanup) { dprintf(("PyThread_exit_prog(%d) called\n", status)); if (!initialized) if (no_cleanup) _exit(status); else exit(status); } void PyThread_exit_prog(int status) { do_PyThread_exit_prog(status, 0); } void PyThread__exit_prog(int status) { do_PyThread_exit_prog(status, 1); } #endif /* NO_EXIT_PROG */ /* * Lock support. */ PyThread_type_lock PyThread_allocate_lock(void) { pth_lock *lock; int status, error = 0; dprintf(("PyThread_allocate_lock called\n")); if (!initialized) PyThread_init_thread(); lock = (pth_lock *) malloc(sizeof(pth_lock)); memset((void *)lock, '\0', sizeof(pth_lock)); if (lock) { lock->locked = 0; status = pth_mutex_init(&lock->mut); CHECK_STATUS("pth_mutex_init"); status = pth_cond_init(&lock->lock_released); CHECK_STATUS("pth_cond_init"); if (error) { free((void *)lock); lock = NULL; } } dprintf(("PyThread_allocate_lock() -> %p\n", lock)); return (PyThread_type_lock) lock; } void PyThread_free_lock(PyThread_type_lock lock) { pth_lock *thelock = (pth_lock *)lock; dprintf(("PyThread_free_lock(%p) called\n", lock)); free((void *)thelock); } int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) { int success; pth_lock *thelock = (pth_lock *)lock; int status, error = 0; dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); status = pth_mutex_acquire(&thelock->mut, !waitflag, NULL); CHECK_STATUS("pth_mutex_acquire[1]"); success = thelock->locked == 0; if (success) thelock->locked = 1; status = pth_mutex_release( &thelock->mut ); CHECK_STATUS("pth_mutex_release[1]"); if ( !success && waitflag ) { /* continue trying until we get the lock */ /* mut must be locked by me -- part of the condition * protocol */ status = pth_mutex_acquire( &thelock->mut, !waitflag, NULL ); CHECK_STATUS("pth_mutex_acquire[2]"); while ( thelock->locked ) { status = pth_cond_await(&thelock->lock_released, &thelock->mut, NULL); CHECK_STATUS("pth_cond_await"); } thelock->locked = 1; status = pth_mutex_release( &thelock->mut ); CHECK_STATUS("pth_mutex_release[2]"); success = 1; } if (error) success = 0; dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); return success; } void PyThread_release_lock(PyThread_type_lock lock) { pth_lock *thelock = (pth_lock *)lock; int status, error = 0; dprintf(("PyThread_release_lock(%p) called\n", lock)); status = pth_mutex_acquire( &thelock->mut, 0, NULL ); CHECK_STATUS("pth_mutex_acquire[3]"); thelock->locked = 0; status = pth_mutex_release( &thelock->mut ); CHECK_STATUS("pth_mutex_release[3]"); /* wake up someone (anyone, if any) waiting on the lock */ status = pth_cond_notify( &thelock->lock_released, 0 ); CHECK_STATUS("pth_cond_notify"); }
