aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-02-11 01:42:33 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-02-11 01:52:08 +0300
commit24d7abf3b5ce5026214f0cf1a0d518e30cb8ef76 (patch)
tree69788f265db20e7c04a8ffc72b91ba317242aff8 /contrib
parent325df06adaf943db9b88c447759e311dda6cd88e (diff)
downloadydb-24d7abf3b5ce5026214f0cf1a0d518e30cb8ef76.tar.gz
Intermediate changes
Diffstat (limited to 'contrib')
-rw-r--r--contrib/tools/python/src/Python/thread.c14
-rw-r--r--contrib/tools/python/src/Python/thread_atheos.h259
-rw-r--r--contrib/tools/python/src/Python/thread_beos.h248
-rw-r--r--contrib/tools/python/src/Python/thread_lwp.h113
-rw-r--r--contrib/tools/python/src/Python/thread_os2.h267
-rw-r--r--contrib/tools/python/src/Python/thread_pth.h178
-rw-r--r--contrib/tools/python/src/Python/thread_sgi.h259
7 files changed, 7 insertions, 1331 deletions
diff --git a/contrib/tools/python/src/Python/thread.c b/contrib/tools/python/src/Python/thread.c
index aa4190cb08..48beda0512 100644
--- a/contrib/tools/python/src/Python/thread.c
+++ b/contrib/tools/python/src/Python/thread.c
@@ -101,7 +101,7 @@ PyThread_init_thread(void)
static size_t _pythread_stacksize = 0;
#ifdef SGI_THREADS
-#include "thread_sgi.h"
+#error #include "thread_sgi.h"
#endif
#ifdef SOLARIS_THREADS
@@ -109,11 +109,11 @@ static size_t _pythread_stacksize = 0;
#endif
#ifdef SUN_LWP
-#include "thread_lwp.h"
+#error #include "thread_lwp.h"
#endif
#ifdef HAVE_PTH
-#include "thread_pth.h"
+#error #include "thread_pth.h"
#undef _POSIX_THREADS
#endif
@@ -130,19 +130,19 @@ static size_t _pythread_stacksize = 0;
#endif
#ifdef OS2_THREADS
-#include "thread_os2.h"
+#error #include "thread_os2.h"
#endif
#ifdef BEOS_THREADS
-#include "thread_beos.h"
+#error #include "thread_beos.h"
#endif
#ifdef PLAN9_THREADS
-#include "thread_plan9.h"
+#error #include "thread_plan9.h"
#endif
#ifdef ATHEOS_THREADS
-#include "thread_atheos.h"
+#error #include "thread_atheos.h"
#endif
/*
diff --git a/contrib/tools/python/src/Python/thread_atheos.h b/contrib/tools/python/src/Python/thread_atheos.h
deleted file mode 100644
index 230594f144..0000000000
--- a/contrib/tools/python/src/Python/thread_atheos.h
+++ /dev/null
@@ -1,259 +0,0 @@
-/* Threading for AtheOS.
- Based on thread_beos.h. */
-
-#include <atheos/threads.h>
-#include <atheos/semaphore.h>
-#include <atheos/atomic.h>
-#include <errno.h>
-#include <string.h>
-
-/* Missing decl from threads.h */
-extern int exit_thread(int);
-
-
-/* Undefine FASTLOCK to play with simple semaphores. */
-#define FASTLOCK
-
-
-#ifdef FASTLOCK
-
-/* Use an atomic counter and a semaphore for maximum speed. */
-typedef struct fastmutex {
- sem_id sem;
- atomic_t count;
-} fastmutex_t;
-
-
-static int fastmutex_create(const char *name, fastmutex_t * mutex);
-static int fastmutex_destroy(fastmutex_t * mutex);
-static int fastmutex_lock(fastmutex_t * mutex);
-static int fastmutex_timedlock(fastmutex_t * mutex, bigtime_t timeout);
-static int fastmutex_unlock(fastmutex_t * mutex);
-
-
-static int fastmutex_create(const char *name, fastmutex_t * mutex)
-{
- mutex->count = 0;
- mutex->sem = create_semaphore(name, 0, 0);
- return (mutex->sem < 0) ? -1 : 0;
-}
-
-
-static int fastmutex_destroy(fastmutex_t * mutex)
-{
- if (fastmutex_timedlock(mutex, 0) == 0 || errno == EWOULDBLOCK) {
- return delete_semaphore(mutex->sem);
- }
- return 0;
-}
-
-
-static int fastmutex_lock(fastmutex_t * mutex)
-{
- atomic_t prev = atomic_add(&mutex->count, 1);
- if (prev > 0)
- return lock_semaphore(mutex->sem);
- return 0;
-}
-
-
-static int fastmutex_timedlock(fastmutex_t * mutex, bigtime_t timeout)
-{
- atomic_t prev = atomic_add(&mutex->count, 1);
- if (prev > 0)
- return lock_semaphore_x(mutex->sem, 1, 0, timeout);
- return 0;
-}
-
-
-static int fastmutex_unlock(fastmutex_t * mutex)
-{
- atomic_t prev = atomic_add(&mutex->count, -1);
- if (prev > 1)
- return unlock_semaphore(mutex->sem);
- return 0;
-}
-
-
-#endif /* FASTLOCK */
-
-
-/*
- * Initialization.
- *
- */
-static void PyThread__init_thread(void)
-{
- /* Do nothing. */
- return;
-}
-
-
-/*
- * Thread support.
- *
- */
-
-static atomic_t thread_count = 0;
-
-long PyThread_start_new_thread(void (*func) (void *), void *arg)
-{
- status_t success = -1;
- thread_id tid;
- char name[OS_NAME_LENGTH];
- atomic_t this_thread;
-
- dprintf(("PyThread_start_new_thread called\n"));
-
- this_thread = atomic_add(&thread_count, 1);
- PyOS_snprintf(name, sizeof(name), "python thread (%d)", this_thread);
-
- tid = spawn_thread(name, func, NORMAL_PRIORITY, 0, arg);
- if (tid < 0) {
- dprintf(("PyThread_start_new_thread spawn_thread failed: %s\n", strerror(errno)));
- } else {
- success = resume_thread(tid);
- if (success < 0) {
- dprintf(("PyThread_start_new_thread resume_thread failed: %s\n", strerror(errno)));
- }
- }
-
- return (success < 0 ? -1 : tid);
-}
-
-
-long PyThread_get_thread_ident(void)
-{
- return get_thread_id(NULL);
-}
-
-
-void PyThread_exit_thread(void)
-{
- dprintf(("PyThread_exit_thread called\n"));
-
- /* Thread-safe way to read a variable without a mutex: */
- if (atomic_add(&thread_count, 0) == 0) {
- /* No threads around, so exit main(). */
- exit(0);
- } else {
- /* We're a thread */
- exit_thread(0);
- }
-}
-
-
-/*
- * Lock support.
- *
- */
-
-static atomic_t lock_count = 0;
-
-PyThread_type_lock PyThread_allocate_lock(void)
-{
-#ifdef FASTLOCK
- fastmutex_t *lock;
-#else
- sem_id sema;
-#endif
- char name[OS_NAME_LENGTH];
- atomic_t this_lock;
-
- dprintf(("PyThread_allocate_lock called\n"));
-
-#ifdef FASTLOCK
- lock = (fastmutex_t *) malloc(sizeof(fastmutex_t));
- if (lock == NULL) {
- dprintf(("PyThread_allocate_lock failed: out of memory\n"));
- return (PyThread_type_lock) NULL;
- }
-#endif
- this_lock = atomic_add(&lock_count, 1);
- PyOS_snprintf(name, sizeof(name), "python lock (%d)", this_lock);
-
-#ifdef FASTLOCK
- if (fastmutex_create(name, lock) < 0) {
- dprintf(("PyThread_allocate_lock failed: %s\n",
- strerror(errno)));
- free(lock);
- lock = NULL;
- }
- dprintf(("PyThread_allocate_lock()-> %p\n", lock));
- return (PyThread_type_lock) lock;
-#else
- sema = create_semaphore(name, 1, 0);
- if (sema < 0) {
- dprintf(("PyThread_allocate_lock failed: %s\n",
- strerror(errno)));
- sema = 0;
- }
- dprintf(("PyThread_allocate_lock()-> %p\n", sema));
- return (PyThread_type_lock) sema;
-#endif
-}
-
-
-void PyThread_free_lock(PyThread_type_lock lock)
-{
- dprintf(("PyThread_free_lock(%p) called\n", lock));
-
-#ifdef FASTLOCK
- if (fastmutex_destroy((fastmutex_t *) lock) < 0) {
- dprintf(("PyThread_free_lock(%p) failed: %s\n", lock,
- strerror(errno)));
- }
- free(lock);
-#else
- if (delete_semaphore((sem_id) lock) < 0) {
- dprintf(("PyThread_free_lock(%p) failed: %s\n", lock,
- strerror(errno)));
- }
-#endif
-}
-
-
-int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
-{
- int retval;
-
- dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock,
- waitflag));
-
-#ifdef FASTLOCK
- if (waitflag)
- retval = fastmutex_lock((fastmutex_t *) lock);
- else
- retval = fastmutex_timedlock((fastmutex_t *) lock, 0);
-#else
- if (waitflag)
- retval = lock_semaphore((sem_id) lock);
- else
- retval = lock_semaphore_x((sem_id) lock, 1, 0, 0);
-#endif
- if (retval < 0) {
- dprintf(("PyThread_acquire_lock(%p, %d) failed: %s\n",
- lock, waitflag, strerror(errno)));
- }
- dprintf(("PyThread_acquire_lock(%p, %d)-> %d\n", lock, waitflag,
- retval));
- return retval < 0 ? 0 : 1;
-}
-
-
-void PyThread_release_lock(PyThread_type_lock lock)
-{
- dprintf(("PyThread_release_lock(%p) called\n", lock));
-
-#ifdef FASTLOCK
- if (fastmutex_unlock((fastmutex_t *) lock) < 0) {
- dprintf(("PyThread_release_lock(%p) failed: %s\n", lock,
- strerror(errno)));
- }
-#else
- if (unlock_semaphore((sem_id) lock) < 0) {
- dprintf(("PyThread_release_lock(%p) failed: %s\n", lock,
- strerror(errno)));
- }
-#endif
-}
diff --git a/contrib/tools/python/src/Python/thread_beos.h b/contrib/tools/python/src/Python/thread_beos.h
deleted file mode 100644
index 65dc470bcd..0000000000
--- a/contrib/tools/python/src/Python/thread_beos.h
+++ /dev/null
@@ -1,248 +0,0 @@
-#include <kernel/OS.h>
-#include <support/SupportDefs.h>
-#include <errno.h>
-
-/* ----------------------------------------------------------------------
- * Fast locking mechanism described by Benoit Schillings (benoit@be.com)
- * in the Be Developer's Newsletter, Issue #26 (http://www.be.com/).
- */
-typedef struct benaphore {
- sem_id _sem;
- int32 _atom;
-} benaphore_t;
-
-static status_t benaphore_create( const char *name, benaphore_t *ben );
-static status_t benaphore_destroy( benaphore_t *ben );
-static status_t benaphore_lock( benaphore_t *ben );
-static status_t benaphore_timedlock( benaphore_t *ben, bigtime_t micros );
-static status_t benaphore_unlock( benaphore_t *ben );
-
-static status_t benaphore_create( const char *name, benaphore_t *ben )
-{
- if( ben != NULL ) {
- ben->_atom = 0;
- ben->_sem = create_sem( 0, name );
-
- if( ben->_sem < B_NO_ERROR ) {
- return B_BAD_SEM_ID;
- }
- } else {
- return EFAULT;
- }
-
- return EOK;
-}
-
-static status_t benaphore_destroy( benaphore_t *ben )
-{
- if( ben->_sem >= B_NO_ERROR ) {
- status_t retval = benaphore_timedlock( ben, 0 );
-
- if( retval == EOK || retval == EWOULDBLOCK ) {
- status_t del_retval = delete_sem( ben->_sem );
-
- return del_retval;
- }
- }
-
- return B_BAD_SEM_ID;
-}
-
-static status_t benaphore_lock( benaphore_t *ben )
-{
- int32 prev = atomic_add( &(ben->_atom), 1 );
-
- if( prev > 0 ) {
- return acquire_sem( ben->_sem );
- }
-
- return EOK;
-}
-
-static status_t benaphore_timedlock( benaphore_t *ben, bigtime_t micros )
-{
- int32 prev = atomic_add( &(ben->_atom), 1 );
-
- if( prev > 0 ) {
- status_t retval = acquire_sem_etc( ben->_sem, 1, B_TIMEOUT, micros );
-
- switch( retval ) {
- case B_WOULD_BLOCK: /* Fall through... */
- case B_TIMED_OUT:
- return EWOULDBLOCK;
- break;
- case B_OK:
- return EOK;
- break;
- default:
- return retval;
- break;
- }
- }
-
- return EOK;
-}
-
-static status_t benaphore_unlock( benaphore_t *ben )
-{
- int32 prev = atomic_add( &(ben->_atom), -1 );
-
- if( prev > 1 ) {
- return release_sem( ben->_sem );
- }
-
- return EOK;
-}
-
-/* ----------------------------------------------------------------------
- * Initialization.
- */
-static void PyThread__init_thread( void )
-{
- /* Do nothing. */
- return;
-}
-
-/* ----------------------------------------------------------------------
- * Thread support.
- *
- * Only ANSI C, renamed functions here; you can't use K&R on BeOS,
- * and there's no legacy thread module to support.
- */
-
-static int32 thread_count = 0;
-
-long PyThread_start_new_thread( void (*func)(void *), void *arg )
-{
- status_t success = 0;
- thread_id tid;
- char name[B_OS_NAME_LENGTH];
- int32 this_thread;
-
- dprintf(("PyThread_start_new_thread called\n"));
-
- /* We are so very thread-safe... */
- this_thread = atomic_add( &thread_count, 1 );
- PyOS_snprintf(name, sizeof(name),
- "python thread (%d)", this_thread );
-
- tid = spawn_thread( (thread_func)func, name,
- B_NORMAL_PRIORITY, arg );
- if( tid > B_NO_ERROR ) {
- success = resume_thread( tid );
- }
-
- return ( success == B_NO_ERROR ? tid : -1 );
-}
-
-long PyThread_get_thread_ident( void )
-{
- /* Presumed to return the current thread's ID... */
- thread_id tid;
- tid = find_thread( NULL );
-
- return ( tid != B_NAME_NOT_FOUND ? tid : -1 );
-}
-
-void PyThread_exit_thread( void )
-{
- int32 threads;
-
- dprintf(("PyThread_exit_thread called\n"));
-
- /* Thread-safe way to read a variable without a mutex: */
- threads = atomic_add( &thread_count, 0 );
-
- if( threads == 0 ) {
- /* No threads around, so exit main(). */
- exit(0);
- } else {
- /* Oh, we're a thread, let's try to exit gracefully... */
- exit_thread( B_NO_ERROR );
- }
-}
-
-/* ----------------------------------------------------------------------
- * Lock support.
- */
-
-static int32 lock_count = 0;
-
-PyThread_type_lock PyThread_allocate_lock( void )
-{
- benaphore_t *lock;
- status_t retval;
- char name[B_OS_NAME_LENGTH];
- int32 this_lock;
-
- dprintf(("PyThread_allocate_lock called\n"));
-
- lock = (benaphore_t *)malloc( sizeof( benaphore_t ) );
- if( lock == NULL ) {
- /* TODO: that's bad, raise MemoryError */
- return (PyThread_type_lock)NULL;
- }
-
- this_lock = atomic_add( &lock_count, 1 );
- PyOS_snprintf(name, sizeof(name), "python lock (%d)", this_lock);
-
- retval = benaphore_create( name, lock );
- if( retval != EOK ) {
- /* TODO: that's bad, raise an exception */
- return (PyThread_type_lock)NULL;
- }
-
- dprintf(("PyThread_allocate_lock() -> %p\n", lock));
- return (PyThread_type_lock) lock;
-}
-
-void PyThread_free_lock( PyThread_type_lock lock )
-{
- status_t retval;
-
- dprintf(("PyThread_free_lock(%p) called\n", lock));
-
- retval = benaphore_destroy( (benaphore_t *)lock );
- if( retval != EOK ) {
- /* TODO: that's bad, raise an exception */
- return;
- }
-}
-
-int PyThread_acquire_lock( PyThread_type_lock lock, int waitflag )
-{
- int success;
- status_t retval;
-
- dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
-
- if( waitflag ) {
- retval = benaphore_lock( (benaphore_t *)lock );
- } else {
- retval = benaphore_timedlock( (benaphore_t *)lock, 0 );
- }
-
- if( retval == EOK ) {
- success = 1;
- } else {
- success = 0;
-
- /* TODO: that's bad, raise an exception */
- }
-
- dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
- return success;
-}
-
-void PyThread_release_lock( PyThread_type_lock lock )
-{
- status_t retval;
-
- dprintf(("PyThread_release_lock(%p) called\n", lock));
-
- retval = benaphore_unlock( (benaphore_t *)lock );
- if( retval != EOK ) {
- /* TODO: that's bad, raise an exception */
- return;
- }
-}
diff --git a/contrib/tools/python/src/Python/thread_lwp.h b/contrib/tools/python/src/Python/thread_lwp.h
deleted file mode 100644
index ba7b37ad7e..0000000000
--- a/contrib/tools/python/src/Python/thread_lwp.h
+++ /dev/null
@@ -1,113 +0,0 @@
-
-#include <stdlib.h>
-#include <lwp/lwp.h>
-#include <lwp/stackdep.h>
-
-#define STACKSIZE 1000 /* stacksize for a thread */
-#define NSTACKS 2 /* # stacks to be put in cache initially */
-
-struct lock {
- int lock_locked;
- cv_t lock_condvar;
- mon_t lock_monitor;
-};
-
-
-/*
- * Initialization.
- */
-static void PyThread__init_thread(void)
-{
- lwp_setstkcache(STACKSIZE, NSTACKS);
-}
-
-/*
- * Thread support.
- */
-
-
-long PyThread_start_new_thread(void (*func)(void *), void *arg)
-{
- thread_t tid;
- int success;
- dprintf(("PyThread_start_new_thread called\n"));
- if (!initialized)
- PyThread_init_thread();
- success = lwp_create(&tid, func, MINPRIO, 0, lwp_newstk(), 1, arg);
- return success < 0 ? -1 : 0;
-}
-
-long PyThread_get_thread_ident(void)
-{
- thread_t tid;
- if (!initialized)
- PyThread_init_thread();
- if (lwp_self(&tid) < 0)
- return -1;
- return tid.thread_id;
-}
-
-void PyThread_exit_thread(void)
-{
- dprintf(("PyThread_exit_thread called\n"));
- if (!initialized)
- exit(0);
- lwp_destroy(SELF);
-}
-
-/*
- * Lock support.
- */
-PyThread_type_lock PyThread_allocate_lock(void)
-{
- struct lock *lock;
- extern char *malloc(size_t);
-
- dprintf(("PyThread_allocate_lock called\n"));
- if (!initialized)
- PyThread_init_thread();
-
- lock = (struct lock *) malloc(sizeof(struct lock));
- lock->lock_locked = 0;
- (void) mon_create(&lock->lock_monitor);
- (void) cv_create(&lock->lock_condvar, lock->lock_monitor);
- dprintf(("PyThread_allocate_lock() -> %p\n", lock));
- return (PyThread_type_lock) lock;
-}
-
-void PyThread_free_lock(PyThread_type_lock lock)
-{
- dprintf(("PyThread_free_lock(%p) called\n", lock));
- mon_destroy(((struct lock *) lock)->lock_monitor);
- free((char *) lock);
-}
-
-int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
-{
- int success;
-
- dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
- success = 0;
-
- (void) mon_enter(((struct lock *) lock)->lock_monitor);
- if (waitflag)
- while (((struct lock *) lock)->lock_locked)
- cv_wait(((struct lock *) lock)->lock_condvar);
- if (!((struct lock *) lock)->lock_locked) {
- success = 1;
- ((struct lock *) lock)->lock_locked = 1;
- }
- cv_broadcast(((struct lock *) lock)->lock_condvar);
- mon_exit(((struct lock *) lock)->lock_monitor);
- dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
- return success;
-}
-
-void PyThread_release_lock(PyThread_type_lock lock)
-{
- dprintf(("PyThread_release_lock(%p) called\n", lock));
- (void) mon_enter(((struct lock *) lock)->lock_monitor);
- ((struct lock *) lock)->lock_locked = 0;
- cv_broadcast(((struct lock *) lock)->lock_condvar);
- mon_exit(((struct lock *) lock)->lock_monitor);
-}
diff --git a/contrib/tools/python/src/Python/thread_os2.h b/contrib/tools/python/src/Python/thread_os2.h
deleted file mode 100644
index 1b264b5ad5..0000000000
--- a/contrib/tools/python/src/Python/thread_os2.h
+++ /dev/null
@@ -1,267 +0,0 @@
-/* This code implemented by cvale@netcom.com */
-
-#define INCL_DOSPROCESS
-#define INCL_DOSSEMAPHORES
-#include "os2.h"
-#include "limits.h"
-
-#include "process.h"
-
-#if defined(PYCC_GCC)
-#include <sys/builtin.h>
-#include <sys/fmutex.h>
-#else
-long PyThread_get_thread_ident(void);
-#endif
-
-/* default thread stack size of 64kB */
-#if !defined(THREAD_STACK_SIZE)
-#define THREAD_STACK_SIZE 0x10000
-#endif
-
-#define OS2_STACKSIZE(x) (x ? x : THREAD_STACK_SIZE)
-
-/*
- * Initialization of the C package, should not be needed.
- */
-static void
-PyThread__init_thread(void)
-{
-}
-
-/*
- * Thread support.
- */
-long
-PyThread_start_new_thread(void (*func)(void *), void *arg)
-{
- int thread_id;
-
- thread_id = _beginthread(func,
- NULL,
- OS2_STACKSIZE(_pythread_stacksize),
- arg);
-
- if (thread_id == -1) {
- dprintf(("_beginthread failed. return %ld\n", errno));
- }
-
- return thread_id;
-}
-
-long
-PyThread_get_thread_ident(void)
-{
-#if !defined(PYCC_GCC)
- PPIB pib;
- PTIB tib;
-#endif
-
- if (!initialized)
- PyThread_init_thread();
-
-#if defined(PYCC_GCC)
- return _gettid();
-#else
- DosGetInfoBlocks(&tib, &pib);
- return tib->tib_ptib2->tib2_ultid;
-#endif
-}
-
-void
-PyThread_exit_thread(void)
-{
- dprintf(("%ld: PyThread_exit_thread called\n",
- PyThread_get_thread_ident()));
- if (!initialized)
- exit(0);
- _endthread();
-}
-
-/*
- * Lock support. This is implemented with an event semaphore and critical
- * sections to make it behave more like a posix mutex than its OS/2
- * counterparts.
- */
-
-typedef struct os2_lock_t {
- int is_set;
- HEV changed;
-} *type_os2_lock;
-
-PyThread_type_lock
-PyThread_allocate_lock(void)
-{
-#if defined(PYCC_GCC)
- _fmutex *sem = malloc(sizeof(_fmutex));
- if (!initialized)
- PyThread_init_thread();
- dprintf(("%ld: PyThread_allocate_lock() -> %lx\n",
- PyThread_get_thread_ident(),
- (long)sem));
- if (_fmutex_create(sem, 0)) {
- free(sem);
- sem = NULL;
- }
- return (PyThread_type_lock)sem;
-#else
- APIRET rc;
- type_os2_lock lock = (type_os2_lock)malloc(sizeof(struct os2_lock_t));
-
- dprintf(("PyThread_allocate_lock called\n"));
- if (!initialized)
- PyThread_init_thread();
-
- lock->is_set = 0;
-
- DosCreateEventSem(NULL, &lock->changed, 0, 0);
-
- dprintf(("%ld: PyThread_allocate_lock() -> %p\n",
- PyThread_get_thread_ident(),
- lock->changed));
-
- return (PyThread_type_lock)lock;
-#endif
-}
-
-void
-PyThread_free_lock(PyThread_type_lock aLock)
-{
-#if !defined(PYCC_GCC)
- type_os2_lock lock = (type_os2_lock)aLock;
-#endif
-
- dprintf(("%ld: PyThread_free_lock(%p) called\n",
- PyThread_get_thread_ident(),aLock));
-
-#if defined(PYCC_GCC)
- if (aLock) {
- _fmutex_close((_fmutex *)aLock);
- free((_fmutex *)aLock);
- }
-#else
- DosCloseEventSem(lock->changed);
- free(aLock);
-#endif
-}
-
-/*
- * Return 1 on success if the lock was acquired
- *
- * and 0 if the lock was not acquired.
- */
-int
-PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag)
-{
-#if !defined(PYCC_GCC)
- int done = 0;
- ULONG count;
- PID pid = 0;
- TID tid = 0;
- type_os2_lock lock = (type_os2_lock)aLock;
-#endif
-
- dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n",
- PyThread_get_thread_ident(),
- aLock,
- waitflag));
-
-#if defined(PYCC_GCC)
- /* always successful if the lock doesn't exist */
- if (aLock &&
- _fmutex_request((_fmutex *)aLock, waitflag ? 0 : _FMR_NOWAIT))
- return 0;
-#else
- while (!done) {
- /* if the lock is currently set, we have to wait for
- * the state to change
- */
- if (lock->is_set) {
- if (!waitflag)
- return 0;
- DosWaitEventSem(lock->changed, SEM_INDEFINITE_WAIT);
- }
-
- /* enter a critical section and try to get the semaphore. If
- * it is still locked, we will try again.
- */
- if (DosEnterCritSec())
- return 0;
-
- if (!lock->is_set) {
- lock->is_set = 1;
- DosResetEventSem(lock->changed, &count);
- done = 1;
- }
-
- DosExitCritSec();
- }
-#endif
-
- return 1;
-}
-
-void
-PyThread_release_lock(PyThread_type_lock aLock)
-{
-#if !defined(PYCC_GCC)
- type_os2_lock lock = (type_os2_lock)aLock;
-#endif
-
- dprintf(("%ld: PyThread_release_lock(%p) called\n",
- PyThread_get_thread_ident(),
- aLock));
-
-#if defined(PYCC_GCC)
- if (aLock)
- _fmutex_release((_fmutex *)aLock);
-#else
- if (!lock->is_set) {
- dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n",
- PyThread_get_thread_ident(),
- aLock,
- GetLastError()));
- return;
- }
-
- if (DosEnterCritSec()) {
- dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n",
- PyThread_get_thread_ident(),
- aLock,
- GetLastError()));
- return;
- }
-
- lock->is_set = 0;
- DosPostEventSem(lock->changed);
-
- DosExitCritSec();
-#endif
-}
-
-/* minimum/maximum thread stack sizes supported */
-#define THREAD_MIN_STACKSIZE 0x8000 /* 32kB */
-#define THREAD_MAX_STACKSIZE 0x2000000 /* 32MB */
-
-/* set the thread stack size.
- * Return 0 if size is valid, -1 otherwise.
- */
-static int
-_pythread_os2_set_stacksize(size_t size)
-{
- /* set to default */
- if (size == 0) {
- _pythread_stacksize = 0;
- return 0;
- }
-
- /* valid range? */
- if (size >= THREAD_MIN_STACKSIZE && size < THREAD_MAX_STACKSIZE) {
- _pythread_stacksize = size;
- return 0;
- }
-
- return -1;
-}
-
-#define THREAD_SET_STACKSIZE(x) _pythread_os2_set_stacksize(x)
diff --git a/contrib/tools/python/src/Python/thread_pth.h b/contrib/tools/python/src/Python/thread_pth.h
deleted file mode 100644
index 82a00e72ba..0000000000
--- a/contrib/tools/python/src/Python/thread_pth.h
+++ /dev/null
@@ -1,178 +0,0 @@
-
-/* 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;
-}
-
-void PyThread_exit_thread(void)
-{
- dprintf(("PyThread_exit_thread called\n"));
- if (!initialized) {
- exit(0);
- }
-}
-
-/*
- * 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");
-}
diff --git a/contrib/tools/python/src/Python/thread_sgi.h b/contrib/tools/python/src/Python/thread_sgi.h
deleted file mode 100644
index 771ab2cc60..0000000000
--- a/contrib/tools/python/src/Python/thread_sgi.h
+++ /dev/null
@@ -1,259 +0,0 @@
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/prctl.h>
-#include <ulocks.h>
-#include <errno.h>
-
-#define HDR_SIZE 2680 /* sizeof(ushdr_t) */
-#define MAXPROC 100 /* max # of threads that can be started */
-
-static usptr_t *shared_arena;
-static ulock_t count_lock; /* protection for some variables */
-static ulock_t wait_lock; /* lock used to wait for other threads */
-static int waiting_for_threads; /* protected by count_lock */
-static int nthreads; /* protected by count_lock */
-static int exit_status;
-static int exiting; /* we're already exiting (for maybe_exit) */
-static pid_t my_pid; /* PID of main thread */
-static struct pidlist {
- pid_t parent;
- pid_t child;
-} pidlist[MAXPROC]; /* PIDs of other threads; protected by count_lock */
-static int maxpidindex; /* # of PIDs in pidlist */
-/*
- * Initialization.
- */
-static void PyThread__init_thread(void)
-{
-#ifdef USE_DL
- long addr, size;
-#endif /* USE_DL */
-
-
-#ifdef USE_DL
- if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0)
- perror("usconfig - CONF_INITSIZE (check)");
- if (usconfig(CONF_INITSIZE, size) < 0)
- perror("usconfig - CONF_INITSIZE (reset)");
- addr = (long) dl_getrange(size + HDR_SIZE);
- dprintf(("trying to use addr %p-%p for shared arena\n", addr, addr+size));
- errno = 0;
- if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && errno != 0)
- perror("usconfig - CONF_ATTACHADDR (set)");
-#endif /* USE_DL */
- if (usconfig(CONF_INITUSERS, 16) < 0)
- perror("usconfig - CONF_INITUSERS");
- my_pid = getpid(); /* so that we know which is the main thread */
- if (usconfig(CONF_ARENATYPE, US_SHAREDONLY) < 0)
- perror("usconfig - CONF_ARENATYPE");
- usconfig(CONF_LOCKTYPE, US_DEBUG); /* XXX */
-#ifdef Py_DEBUG
- if (thread_debug & 4)
- usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);
- else if (thread_debug & 2)
- usconfig(CONF_LOCKTYPE, US_DEBUG);
-#endif /* Py_DEBUG */
- if ((shared_arena = usinit(tmpnam(0))) == 0)
- perror("usinit");
-#ifdef USE_DL
- if (usconfig(CONF_ATTACHADDR, addr) < 0) /* reset address */
- perror("usconfig - CONF_ATTACHADDR (reset)");
-#endif /* USE_DL */
- if ((count_lock = usnewlock(shared_arena)) == NULL)
- perror("usnewlock (count_lock)");
- (void) usinitlock(count_lock);
- if ((wait_lock = usnewlock(shared_arena)) == NULL)
- perror("usnewlock (wait_lock)");
- dprintf(("arena start: %p, arena size: %ld\n", shared_arena, (long) usconfig(CONF_GETSIZE, shared_arena)));
-}
-
-/*
- * Thread support.
- */
-
-static void clean_threads(void)
-{
- int i, j;
- pid_t mypid, pid;
-
- /* clean up any exited threads */
- mypid = getpid();
- i = 0;
- while (i < maxpidindex) {
- if (pidlist[i].parent == mypid && (pid = pidlist[i].child) > 0) {
- pid = waitpid(pid, 0, WNOHANG);
- if (pid > 0) {
- /* a thread has exited */
- pidlist[i] = pidlist[--maxpidindex];
- /* remove references to children of dead proc */
- for (j = 0; j < maxpidindex; j++)
- if (pidlist[j].parent == pid)
- pidlist[j].child = -1;
- continue; /* don't increment i */
- }
- }
- i++;
- }
- /* clean up the list */
- i = 0;
- while (i < maxpidindex) {
- if (pidlist[i].child == -1) {
- pidlist[i] = pidlist[--maxpidindex];
- continue; /* don't increment i */
- }
- i++;
- }
-}
-
-long PyThread_start_new_thread(void (*func)(void *), void *arg)
-{
-#ifdef USE_DL
- long addr, size;
- static int local_initialized = 0;
-#endif /* USE_DL */
- int success = 0; /* init not needed when SOLARIS_THREADS and */
- /* C_THREADS implemented properly */
-
- dprintf(("PyThread_start_new_thread called\n"));
- if (!initialized)
- PyThread_init_thread();
- switch (ussetlock(count_lock)) {
- case 0: return 0;
- case -1: perror("ussetlock (count_lock)");
- }
- if (maxpidindex >= MAXPROC)
- success = -1;
- else {
-#ifdef USE_DL
- if (!local_initialized) {
- if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0)
- perror("usconfig - CONF_INITSIZE (check)");
- if (usconfig(CONF_INITSIZE, size) < 0)
- perror("usconfig - CONF_INITSIZE (reset)");
- addr = (long) dl_getrange(size + HDR_SIZE);
- dprintf(("trying to use addr %p-%p for sproc\n",
- addr, addr+size));
- errno = 0;
- if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 &&
- errno != 0)
- perror("usconfig - CONF_ATTACHADDR (set)");
- }
-#endif /* USE_DL */
- clean_threads();
- if ((success = sproc(func, PR_SALL, arg)) < 0)
- perror("sproc");
-#ifdef USE_DL
- if (!local_initialized) {
- if (usconfig(CONF_ATTACHADDR, addr) < 0)
- /* reset address */
- perror("usconfig - CONF_ATTACHADDR (reset)");
- local_initialized = 1;
- }
-#endif /* USE_DL */
- if (success >= 0) {
- nthreads++;
- pidlist[maxpidindex].parent = getpid();
- pidlist[maxpidindex++].child = success;
- dprintf(("pidlist[%d] = %d\n",
- maxpidindex-1, success));
- }
- }
- if (usunsetlock(count_lock) < 0)
- perror("usunsetlock (count_lock)");
- return success;
-}
-
-long PyThread_get_thread_ident(void)
-{
- return getpid();
-}
-
-void PyThread_exit_thread(void)
-{
- dprintf(("PyThread_exit_thread called\n"));
- if (!initialized)
- exit(0);
- if (ussetlock(count_lock) < 0)
- perror("ussetlock (count_lock)");
- nthreads--;
- if (getpid() == my_pid) {
- /* main thread; wait for other threads to exit */
- exiting = 1;
- waiting_for_threads = 1;
- if (ussetlock(wait_lock) < 0)
- perror("ussetlock (wait_lock)");
- for (;;) {
- if (nthreads < 0) {
- dprintf(("really exit (%d)\n", exit_status));
- exit(exit_status);
- }
- if (usunsetlock(count_lock) < 0)
- perror("usunsetlock (count_lock)");
- dprintf(("waiting for other threads (%d)\n", nthreads));
- if (ussetlock(wait_lock) < 0)
- perror("ussetlock (wait_lock)");
- if (ussetlock(count_lock) < 0)
- perror("ussetlock (count_lock)");
- }
- }
- /* not the main thread */
- if (waiting_for_threads) {
- dprintf(("main thread is waiting\n"));
- if (usunsetlock(wait_lock) < 0)
- perror("usunsetlock (wait_lock)");
- }
- if (usunsetlock(count_lock) < 0)
- perror("usunsetlock (count_lock)");
- _exit(0);
-}
-
-/*
- * Lock support.
- */
-PyThread_type_lock PyThread_allocate_lock(void)
-{
- ulock_t lock;
-
- dprintf(("PyThread_allocate_lock called\n"));
- if (!initialized)
- PyThread_init_thread();
-
- if ((lock = usnewlock(shared_arena)) == NULL)
- perror("usnewlock");
- (void) usinitlock(lock);
- dprintf(("PyThread_allocate_lock() -> %p\n", lock));
- return (PyThread_type_lock) lock;
-}
-
-void PyThread_free_lock(PyThread_type_lock lock)
-{
- dprintf(("PyThread_free_lock(%p) called\n", lock));
- usfreelock((ulock_t) lock, shared_arena);
-}
-
-int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
-{
- int success;
-
- dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
- errno = 0; /* clear it just in case */
- if (waitflag)
- success = ussetlock((ulock_t) lock);
- else
- success = uscsetlock((ulock_t) lock, 1); /* Try it once */
- if (success < 0)
- perror(waitflag ? "ussetlock" : "uscsetlock");
- dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
- return success;
-}
-
-void PyThread_release_lock(PyThread_type_lock lock)
-{
- dprintf(("PyThread_release_lock(%p) called\n", lock));
- if (usunsetlock((ulock_t) lock) < 0)
- perror("usunsetlock");
-}