summaryrefslogtreecommitdiffstats
path: root/Python/thread_os2.h
diff options
context:
space:
mode:
authorAndrew MacIntyre <andymac@bullseye.apana.org.au>2002-02-26 11:41:34 (GMT)
committerAndrew MacIntyre <andymac@bullseye.apana.org.au>2002-02-26 11:41:34 (GMT)
commitd940054ad4bcd39e31f6e22d0fd6f674ec4a99b3 (patch)
tree4cb201880bdd113ccee29bc944b55cbbd1d45f10 /Python/thread_os2.h
parentc487439aa79acaf6c83a65985c110d5ca1ea71da (diff)
downloadcpython-d940054ad4bcd39e31f6e22d0fd6f674ec4a99b3.zip
cpython-d940054ad4bcd39e31f6e22d0fd6f674ec4a99b3.tar.gz
cpython-d940054ad4bcd39e31f6e22d0fd6f674ec4a99b3.tar.bz2
OS/2 EMX port changes (Python part of patch #450267):
Python/ dynload_shlib.c // EMX port emulates dlopen() etc. for DL extensions import.c // changes to support 8.3 DLL name limit (VACPP+EMX) // and case sensitive import semantics importdl.h thread_os2.h
Diffstat (limited to 'Python/thread_os2.h')
-rw-r--r--Python/thread_os2.h54
1 files changed, 52 insertions, 2 deletions
diff --git a/Python/thread_os2.h b/Python/thread_os2.h
index a35f3e9..69bcd2c 100644
--- a/Python/thread_os2.h
+++ b/Python/thread_os2.h
@@ -7,8 +7,12 @@
#include "process.h"
+#if defined(PYCC_GCC)
+#include <sys/builtin.h>
+#include <sys/fmutex.h>
+#else
long PyThread_get_thread_ident(void);
-
+#endif
/*
* Initialization of the C package, should not be needed.
@@ -41,14 +45,20 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
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
}
static void
@@ -103,7 +113,7 @@ PyThread__exit_prog(int status)
/*
* 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.
+ * counterparts.
*/
typedef struct os2_lock_t {
@@ -114,6 +124,19 @@ typedef struct os2_lock_t {
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));
@@ -130,16 +153,27 @@ PyThread_allocate_lock(void)
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
}
/*
@@ -150,15 +184,22 @@ PyThread_free_lock(PyThread_type_lock aLock)
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) {
@@ -182,15 +223,23 @@ PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag)
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()));
@@ -208,4 +257,5 @@ void PyThread_release_lock(PyThread_type_lock aLock)
DosPostEventSem(lock->changed);
DosExitCritSec();
+#endif
}