diff options
-rw-r--r-- | Include/pythread.h | 7 | ||||
-rw-r--r-- | Python/thread_beos.h | 70 | ||||
-rw-r--r-- | Python/thread_cthread.h | 46 | ||||
-rw-r--r-- | Python/thread_foobar.h | 34 | ||||
-rw-r--r-- | Python/thread_lwp.h | 31 | ||||
-rw-r--r-- | Python/thread_nt.h | 53 | ||||
-rw-r--r-- | Python/thread_os2.h | 27 | ||||
-rw-r--r-- | Python/thread_pth.h | 87 | ||||
-rw-r--r-- | Python/thread_pthread.h | 98 | ||||
-rw-r--r-- | Python/thread_sgi.h | 44 | ||||
-rw-r--r-- | Python/thread_solaris.h | 60 |
11 files changed, 0 insertions, 557 deletions
diff --git a/Include/pythread.h b/Include/pythread.h index 514cdea..b1504b6 100644 --- a/Include/pythread.h +++ b/Include/pythread.h @@ -25,13 +25,6 @@ DL_IMPORT(int) PyThread_acquire_lock(PyThread_type_lock, int); #define NOWAIT_LOCK 0 DL_IMPORT(void) PyThread_release_lock(PyThread_type_lock); -DL_IMPORT(PyThread_type_sema) PyThread_allocate_sema(int); -DL_IMPORT(void) PyThread_free_sema(PyThread_type_sema); -DL_IMPORT(int) PyThread_down_sema(PyThread_type_sema, int); -#define WAIT_SEMA 1 -#define NOWAIT_SEMA 0 -DL_IMPORT(void) PyThread_up_sema(PyThread_type_sema); - #ifndef NO_EXIT_PROG DL_IMPORT(void) PyThread_exit_prog(int); DL_IMPORT(void) PyThread__PyThread_exit_prog(int); diff --git a/Python/thread_beos.h b/Python/thread_beos.h index 74eab2e..82f99de 100644 --- a/Python/thread_beos.h +++ b/Python/thread_beos.h @@ -285,73 +285,3 @@ void PyThread_release_lock( PyThread_type_lock lock ) return; } } - -/* ---------------------------------------------------------------------- - * Semaphore support. - * - * Guido says not to implement this because it's not used anywhere; - * I'll do it anyway, you never know when it might be handy, and it's - * easy... - */ -PyThread_type_sema PyThread_allocate_sema( int value ) -{ - sem_id sema; - - dprintf(("PyThread_allocate_sema called\n")); - - sema = create_sem( value, "python semaphore" ); - if( sema < B_NO_ERROR ) { - /* TODO: that's bad, raise an exception */ - return 0; - } - - dprintf(("PyThread_allocate_sema() -> %p\n", sema)); - return (PyThread_type_sema) sema; -} - -void PyThread_free_sema( PyThread_type_sema sema ) -{ - status_t retval; - - dprintf(("PyThread_free_sema(%p) called\n", sema)); - - retval = delete_sem( (sem_id)sema ); - if( retval != B_NO_ERROR ) { - /* TODO: that's bad, raise an exception */ - return; - } -} - -int PyThread_down_sema( PyThread_type_sema sema, int waitflag ) -{ - status_t retval; - - dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag)); - - if( waitflag ) { - retval = acquire_sem( (sem_id)sema ); - } else { - retval = acquire_sem_etc( (sem_id)sema, 1, B_TIMEOUT, 0 ); - } - - if( retval != B_NO_ERROR ) { - /* TODO: that's bad, raise an exception */ - return 0; - } - - dprintf(("PyThread_down_sema(%p) return\n", sema)); - return -1; -} - -void PyThread_up_sema( PyThread_type_sema sema ) -{ - status_t retval; - - dprintf(("PyThread_up_sema(%p)\n", sema)); - - retval = release_sem( (sem_id)sema ); - if( retval != B_NO_ERROR ) { - /* TODO: that's bad, raise an exception */ - return; - } -} diff --git a/Python/thread_cthread.h b/Python/thread_cthread.h index ccd774d..ca776c6 100644 --- a/Python/thread_cthread.h +++ b/Python/thread_cthread.h @@ -154,49 +154,3 @@ PyThread_release_lock(PyThread_type_lock lock) dprintf(("PyThread_release_lock(%p) called\n", lock)); mutex_unlock((mutex_t )lock); } - -/* - * Semaphore support. - * - * This implementation is ripped directly from the pthreads implementation. - * Which is to say that it is 100% non-functional at this time. - * - * Assuming the page is still up, documentation can be found at: - * - * http://www.doc.ic.ac.uk/~mac/manuals/solaris-manual-pages/solaris/usr/man/man2/_lwp_sema_wait.2.html - * - * Looking at the man page, it seems that one could easily implement a - * semaphore using a condition. - * - */ -PyThread_type_sema -PyThread_allocate_sema(int value) -{ - char *sema = 0; - dprintf(("PyThread_allocate_sema called\n")); - if (!initialized) - PyThread_init_thread(); - - dprintf(("PyThread_allocate_sema() -> %p\n", sema)); - return (PyThread_type_sema) sema; -} - -void -PyThread_free_sema(PyThread_type_sema sema) -{ - dprintf(("PyThread_free_sema(%p) called\n", sema)); -} - -int -PyThread_down_sema(PyThread_type_sema sema, int waitflag) -{ - dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag)); - dprintf(("PyThread_down_sema(%p) return\n", sema)); - return -1; -} - -void -PyThread_up_sema(PyThread_type_sema sema) -{ - dprintf(("PyThread_up_sema(%p)\n", sema)); -} diff --git a/Python/thread_foobar.h b/Python/thread_foobar.h index 4baf7e7..67491a1 100644 --- a/Python/thread_foobar.h +++ b/Python/thread_foobar.h @@ -113,37 +113,3 @@ PyThread_release_lock(PyThread_type_lock lock) { dprintf(("PyThread_release_lock(%p) called\n", lock)); } - -/* - * Semaphore support. - */ -PyThread_type_sema -PyThread_allocate_sema(int value) -{ - dprintf(("PyThread_allocate_sema called\n")); - if (!initialized) - PyThread_init_thread(); - - dprintf(("PyThread_allocate_sema() -> %p\n", sema)); - return (PyThread_type_sema) sema; -} - -void -PyThread_free_sema(PyThread_type_sema sema) -{ - dprintf(("PyThread_free_sema(%p) called\n", sema)); -} - -int -PyThread_down_sema(PyThread_type_sema sema, int waitflag) -{ - dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag)); - dprintf(("PyThread_down_sema(%p) return\n", sema)); - return -1; -} - -void -PyThread_up_sema(PyThread_type_sema sema) -{ - dprintf(("PyThread_up_sema(%p)\n", sema)); -} diff --git a/Python/thread_lwp.h b/Python/thread_lwp.h index f6e6885..e93d65a 100644 --- a/Python/thread_lwp.h +++ b/Python/thread_lwp.h @@ -147,34 +147,3 @@ void PyThread_release_lock(PyThread_type_lock lock) cv_broadcast(((struct lock *) lock)->lock_condvar); mon_exit(((struct lock *) lock)->lock_monitor); } - -/* - * Semaphore support. - */ -PyThread_type_sema PyThread_allocate_sema(int value) -{ - PyThread_type_sema sema = 0; - dprintf(("PyThread_allocate_sema called\n")); - if (!initialized) - PyThread_init_thread(); - - dprintf(("PyThread_allocate_sema() -> %p\n", sema)); - return (PyThread_type_sema) sema; -} - -void PyThread_free_sema(PyThread_type_sema sema) -{ - dprintf(("PyThread_free_sema(%p) called\n", sema)); -} - -int PyThread_down_sema(PyThread_type_sema sema, int waitflag) -{ - dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag)); - dprintf(("PyThread_down_sema(%p) return\n", sema)); - return -1; -} - -void PyThread_up_sema(PyThread_type_sema sema) -{ - dprintf(("PyThread_up_sema(%p)\n", sema)); -} diff --git a/Python/thread_nt.h b/Python/thread_nt.h index 6eac020..0192707 100644 --- a/Python/thread_nt.h +++ b/Python/thread_nt.h @@ -319,56 +319,3 @@ void PyThread_release_lock(PyThread_type_lock aLock) if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock))) dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock, GetLastError())); } - -/* - * Semaphore support. - */ -PyThread_type_sema PyThread_allocate_sema(int value) -{ - HANDLE aSemaphore; - - dprintf(("%ld: PyThread_allocate_sema called\n", PyThread_get_thread_ident())); - if (!initialized) - PyThread_init_thread(); - - aSemaphore = CreateSemaphore( NULL, /* Security attributes */ - value, /* Initial value */ - INT_MAX, /* Maximum value */ - NULL); /* Name of semaphore */ - - dprintf(("%ld: PyThread_allocate_sema() -> %p\n", PyThread_get_thread_ident(), aSemaphore)); - - return (PyThread_type_sema) aSemaphore; -} - -void PyThread_free_sema(PyThread_type_sema aSemaphore) -{ - dprintf(("%ld: PyThread_free_sema(%p) called\n", PyThread_get_thread_ident(), aSemaphore)); - - CloseHandle((HANDLE) aSemaphore); -} - -/* - XXX must do something about waitflag - */ -int PyThread_down_sema(PyThread_type_sema aSemaphore, int waitflag) -{ - DWORD waitResult; - - dprintf(("%ld: PyThread_down_sema(%p) called\n", PyThread_get_thread_ident(), aSemaphore)); - - waitResult = WaitForSingleObject( (HANDLE) aSemaphore, INFINITE); - - dprintf(("%ld: PyThread_down_sema(%p) return: %l\n", PyThread_get_thread_ident(), aSemaphore, waitResult)); - return 0; -} - -void PyThread_up_sema(PyThread_type_sema aSemaphore) -{ - ReleaseSemaphore( - (HANDLE) aSemaphore, /* Handle of semaphore */ - 1, /* increment count by one */ - NULL); /* not interested in previous count */ - - dprintf(("%ld: PyThread_up_sema(%p)\n", PyThread_get_thread_ident(), aSemaphore)); -} diff --git a/Python/thread_os2.h b/Python/thread_os2.h index cfd0834..a35f3e9 100644 --- a/Python/thread_os2.h +++ b/Python/thread_os2.h @@ -209,30 +209,3 @@ void PyThread_release_lock(PyThread_type_lock aLock) DosExitCritSec(); } - -/* - * Semaphore support. - */ -PyThread_type_sema -PyThread_allocate_sema(int value) -{ - return (PyThread_type_sema) 0; -} - -void -PyThread_free_sema(PyThread_type_sema aSemaphore) -{ - -} - -int -PyThread_down_sema(PyThread_type_sema aSemaphore, int waitflag) -{ - return -1; -} - -void -PyThread_up_sema(PyThread_type_sema aSemaphore) -{ - dprintf(("%ld: PyThread_up_sema(%p)\n", PyThread_get_thread_ident(), aSemaphore)); -} diff --git a/Python/thread_pth.h b/Python/thread_pth.h index 71e0d04..3b97981 100644 --- a/Python/thread_pth.h +++ b/Python/thread_pth.h @@ -206,90 +206,3 @@ void PyThread_release_lock(PyThread_type_lock lock) status = pth_cond_notify( &thelock->lock_released, 0 ); CHECK_STATUS("pth_cond_notify"); } - -/* - * Semaphore support. - */ - -struct semaphore { - pth_mutex_t mutex; - pth_cond_t cond; - int value; -}; - -PyThread_type_sema PyThread_allocate_sema(int value) -{ - struct semaphore *sema; - int status, error = 0; - - dprintf(("PyThread_allocate_sema called\n")); - if (!initialized) - PyThread_init_thread(); - - sema = (struct semaphore *) malloc(sizeof(struct semaphore)); - if (sema != NULL) { - sema->value = value; - status = pth_mutex_init(&sema->mutex); - CHECK_STATUS("pth_mutex_init"); - status = pth_cond_init(&sema->cond); - CHECK_STATUS("pth_mutex_init"); - if (error) { - free((void *) sema); - sema = NULL; - } - } - dprintf(("PyThread_allocate_sema() -> %p\n", sema)); - return (PyThread_type_sema) sema; -} - -void PyThread_free_sema(PyThread_type_sema sema) -{ - struct semaphore *thesema = (struct semaphore *) sema; - - dprintf(("PyThread_free_sema(%p) called\n", sema)); - free((void *) thesema); -} - -int PyThread_down_sema(PyThread_type_sema sema, int waitflag) -{ - int status, error = 0, success; - struct semaphore *thesema = (struct semaphore *) sema; - - dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag)); - status = pth_mutex_acquire(&thesema->mutex, !waitflag, NULL); - CHECK_STATUS("pth_mutex_acquire"); - if (waitflag) { - while (!error && thesema->value <= 0) { - status = pth_cond_await(&thesema->cond, - &thesema->mutex, NULL); - CHECK_STATUS("pth_cond_await"); - } - } - if (error) - success = 0; - else if (thesema->value > 0) { - thesema->value--; - success = 1; - } - else - success = 0; - status = pth_mutex_release(&thesema->mutex); - CHECK_STATUS("pth_mutex_release"); - dprintf(("PyThread_down_sema(%p) return\n", sema)); - return success; -} - -void PyThread_up_sema(PyThread_type_sema sema) -{ - int status, error = 0; - struct semaphore *thesema = (struct semaphore *) sema; - - dprintf(("PyThread_up_sema(%p)\n", sema)); - status = pth_mutex_acquire(&thesema->mutex, 0, NULL); - CHECK_STATUS("pth_mutex_acquire"); - thesema->value++; - status = pth_cond_notify(&thesema->cond, 1); - CHECK_STATUS("pth_cond_notify"); - status = pth_mutex_release(&thesema->mutex); - CHECK_STATUS("pth_mutex_release"); -} diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 771e22e..6e92128 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -405,101 +405,3 @@ PyThread_release_lock(PyThread_type_lock lock) status = pthread_cond_signal( &thelock->lock_released ); CHECK_STATUS("pthread_cond_signal"); } - -/* - * Semaphore support. - */ - -struct semaphore { - pthread_mutex_t mutex; - pthread_cond_t cond; - int value; -}; - -PyThread_type_sema -PyThread_allocate_sema(int value) -{ - struct semaphore *sema; - int status, error = 0; - - dprintf(("PyThread_allocate_sema called\n")); - if (!initialized) - PyThread_init_thread(); - - sema = (struct semaphore *) malloc(sizeof(struct semaphore)); - if (sema != NULL) { - sema->value = value; - status = pthread_mutex_init(&sema->mutex, - pthread_mutexattr_default); - CHECK_STATUS("pthread_mutex_init"); - status = pthread_cond_init(&sema->cond, - pthread_condattr_default); - CHECK_STATUS("pthread_cond_init"); - if (error) { - free((void *) sema); - sema = NULL; - } - } - dprintf(("PyThread_allocate_sema() -> %p\n", sema)); - return (PyThread_type_sema) sema; -} - -void -PyThread_free_sema(PyThread_type_sema sema) -{ - int status, error = 0; - struct semaphore *thesema = (struct semaphore *) sema; - - dprintf(("PyThread_free_sema(%p) called\n", sema)); - status = pthread_cond_destroy(&thesema->cond); - CHECK_STATUS("pthread_cond_destroy"); - status = pthread_mutex_destroy(&thesema->mutex); - CHECK_STATUS("pthread_mutex_destroy"); - free((void *) thesema); -} - -int -PyThread_down_sema(PyThread_type_sema sema, int waitflag) -{ - int status, error = 0, success; - struct semaphore *thesema = (struct semaphore *) sema; - - dprintf(("PyThread_down_sema(%p, %d) called\n", sema, waitflag)); - status = pthread_mutex_lock(&thesema->mutex); - CHECK_STATUS("pthread_mutex_lock"); - if (waitflag) { - while (!error && thesema->value <= 0) { - status = pthread_cond_wait(&thesema->cond, - &thesema->mutex); - CHECK_STATUS("pthread_cond_wait"); - } - } - if (error) - success = 0; - else if (thesema->value > 0) { - thesema->value--; - success = 1; - } - else - success = 0; - status = pthread_mutex_unlock(&thesema->mutex); - CHECK_STATUS("pthread_mutex_unlock"); - dprintf(("PyThread_down_sema(%p) return\n", sema)); - return success; -} - -void -PyThread_up_sema(PyThread_type_sema sema) -{ - int status, error = 0; - struct semaphore *thesema = (struct semaphore *) sema; - - dprintf(("PyThread_up_sema(%p)\n", sema)); - status = pthread_mutex_lock(&thesema->mutex); - CHECK_STATUS("pthread_mutex_lock"); - thesema->value++; - status = pthread_cond_signal(&thesema->cond); - CHECK_STATUS("pthread_cond_signal"); - status = pthread_mutex_unlock(&thesema->mutex); - CHECK_STATUS("pthread_mutex_unlock"); -} diff --git a/Python/thread_sgi.h b/Python/thread_sgi.h index eda7972..0fceb21 100644 --- a/Python/thread_sgi.h +++ b/Python/thread_sgi.h @@ -379,50 +379,6 @@ void PyThread_release_lock(PyThread_type_lock lock) } /* - * Semaphore support. - */ -PyThread_type_sema PyThread_allocate_sema(int value) -{ - usema_t *sema; - dprintf(("PyThread_allocate_sema called\n")); - if (!initialized) - PyThread_init_thread(); - - if ((sema = usnewsema(shared_arena, value)) == NULL) - perror("usnewsema"); - dprintf(("PyThread_allocate_sema() -> %p\n", sema)); - return (PyThread_type_sema) sema; -} - -void PyThread_free_sema(PyThread_type_sema sema) -{ - dprintf(("PyThread_free_sema(%p) called\n", sema)); - usfreesema((usema_t *) sema, shared_arena); -} - -int PyThread_down_sema(PyThread_type_sema sema, int waitflag) -{ - int success; - - dprintf(("PyThread_down_sema(%p) called\n", sema)); - if (waitflag) - success = uspsema((usema_t *) sema); - else - success = uscpsema((usema_t *) sema); - if (success < 0) - perror(waitflag ? "uspsema" : "uscpsema"); - dprintf(("PyThread_down_sema(%p) return\n", sema)); - return success; -} - -void PyThread_up_sema(PyThread_type_sema sema) -{ - dprintf(("PyThread_up_sema(%p)\n", sema)); - if (usvsema((usema_t *) sema) < 0) - perror("usvsema"); -} - -/* * Per-thread data ("key") support. */ diff --git a/Python/thread_solaris.h b/Python/thread_solaris.h index 8e24126..d3512d4 100644 --- a/Python/thread_solaris.h +++ b/Python/thread_solaris.h @@ -174,63 +174,3 @@ PyThread_release_lock(PyThread_type_lock lock) if (mutex_unlock((mutex_t *) lock)) perror("mutex_unlock"); } - -/* - * Semaphore support. - */ -PyThread_type_sema -PyThread_allocate_sema(int value) -{ - sema_t *sema; - dprintf(("PyThread_allocate_sema called\n")); - if (!initialized) - PyThread_init_thread(); - - sema = (sema_t *) malloc(sizeof(sema_t)); - if (sema_init(sema, value, USYNC_THREAD, 0)) { - perror("sema_init"); - free((void *) sema); - sema = 0; - } - dprintf(("PyThread_allocate_sema() -> %p\n", sema)); - return (PyThread_type_sema) sema; -} - -void -PyThread_free_sema(PyThread_type_sema sema) -{ - dprintf(("PyThread_free_sema(%p) called\n", sema)); - if (sema_destroy((sema_t *) sema)) - perror("sema_destroy"); - free((void *) sema); -} - -int -PyThread_down_sema(PyThread_type_sema sema, int waitflag) -{ - int success; - - dprintf(("PyThread_down_sema(%p) called\n", sema)); - if (waitflag) - success = sema_wait((sema_t *) sema); - else - success = sema_trywait((sema_t *) sema); - if (success < 0) { - if (errno == EBUSY) - success = 0; - else - perror("sema_wait"); - } - else - success = !success; - dprintf(("PyThread_down_sema(%p) return %d\n", sema, success)); - return success; -} - -void -PyThread_up_sema(PyThread_type_sema sema) -{ - dprintf(("PyThread_up_sema(%p)\n", sema)); - if (sema_post((sema_t *) sema)) - perror("sema_post"); -} |