]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.2/Python/thread_atheos.h
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Python / thread_atheos.h
diff --git a/AppPkg/Applications/Python/Python-2.7.2/Python/thread_atheos.h b/AppPkg/Applications/Python/Python-2.7.2/Python/thread_atheos.h
deleted file mode 100644 (file)
index 0506186..0000000
+++ /dev/null
@@ -1,259 +0,0 @@
-/* Threading for AtheOS.\r
-   Based on thread_beos.h. */\r
-\r
-#include <atheos/threads.h>\r
-#include <atheos/semaphore.h>\r
-#include <atheos/atomic.h>\r
-#include <errno.h>\r
-#include <string.h>\r
-\r
-/* Missing decl from threads.h */\r
-extern int exit_thread(int);\r
-\r
-\r
-/* Undefine FASTLOCK to play with simple semaphores. */\r
-#define FASTLOCK\r
-\r
-\r
-#ifdef FASTLOCK\r
-\r
-/* Use an atomic counter and a semaphore for maximum speed. */\r
-typedef struct fastmutex {\r
-    sem_id sem;\r
-    atomic_t count;\r
-} fastmutex_t;\r
-\r
-\r
-static int fastmutex_create(const char *name, fastmutex_t * mutex);\r
-static int fastmutex_destroy(fastmutex_t * mutex);\r
-static int fastmutex_lock(fastmutex_t * mutex);\r
-static int fastmutex_timedlock(fastmutex_t * mutex, bigtime_t timeout);\r
-static int fastmutex_unlock(fastmutex_t * mutex);\r
-\r
-\r
-static int fastmutex_create(const char *name, fastmutex_t * mutex)\r
-{\r
-    mutex->count = 0;\r
-    mutex->sem = create_semaphore(name, 0, 0);\r
-    return (mutex->sem < 0) ? -1 : 0;\r
-}\r
-\r
-\r
-static int fastmutex_destroy(fastmutex_t * mutex)\r
-{\r
-    if (fastmutex_timedlock(mutex, 0) == 0 || errno == EWOULDBLOCK) {\r
-        return delete_semaphore(mutex->sem);\r
-    }\r
-    return 0;\r
-}\r
-\r
-\r
-static int fastmutex_lock(fastmutex_t * mutex)\r
-{\r
-    atomic_t prev = atomic_add(&mutex->count, 1);\r
-    if (prev > 0)\r
-        return lock_semaphore(mutex->sem);\r
-    return 0;\r
-}\r
-\r
-\r
-static int fastmutex_timedlock(fastmutex_t * mutex, bigtime_t timeout)\r
-{\r
-    atomic_t prev = atomic_add(&mutex->count, 1);\r
-    if (prev > 0)\r
-        return lock_semaphore_x(mutex->sem, 1, 0, timeout);\r
-    return 0;\r
-}\r
-\r
-\r
-static int fastmutex_unlock(fastmutex_t * mutex)\r
-{\r
-    atomic_t prev = atomic_add(&mutex->count, -1);\r
-    if (prev > 1)\r
-        return unlock_semaphore(mutex->sem);\r
-    return 0;\r
-}\r
-\r
-\r
-#endif                          /* FASTLOCK */\r
-\r
-\r
-/*\r
- * Initialization.\r
- *\r
- */\r
-static void PyThread__init_thread(void)\r
-{\r
-    /* Do nothing. */\r
-    return;\r
-}\r
-\r
-\r
-/*\r
- * Thread support.\r
- *\r
- */\r
-\r
-static atomic_t thread_count = 0;\r
-\r
-long PyThread_start_new_thread(void (*func) (void *), void *arg)\r
-{\r
-    status_t success = -1;\r
-    thread_id tid;\r
-    char name[OS_NAME_LENGTH];\r
-    atomic_t this_thread;\r
-\r
-    dprintf(("PyThread_start_new_thread called\n"));\r
-\r
-    this_thread = atomic_add(&thread_count, 1);\r
-    PyOS_snprintf(name, sizeof(name), "python thread (%d)", this_thread);\r
-\r
-    tid = spawn_thread(name, func, NORMAL_PRIORITY, 0, arg);\r
-    if (tid < 0) {\r
-        dprintf(("PyThread_start_new_thread spawn_thread failed: %s\n", strerror(errno)));\r
-    } else {\r
-        success = resume_thread(tid);\r
-        if (success < 0) {\r
-            dprintf(("PyThread_start_new_thread resume_thread failed: %s\n", strerror(errno)));\r
-        }\r
-    }\r
-\r
-    return (success < 0 ? -1 : tid);\r
-}\r
-\r
-\r
-long PyThread_get_thread_ident(void)\r
-{\r
-    return get_thread_id(NULL);\r
-}\r
-\r
-\r
-void PyThread_exit_thread(void)\r
-{\r
-    dprintf(("PyThread_exit_thread called\n"));\r
-\r
-    /* Thread-safe way to read a variable without a mutex: */\r
-    if (atomic_add(&thread_count, 0) == 0) {\r
-        /* No threads around, so exit main(). */\r
-        exit(0);\r
-    } else {\r
-        /* We're a thread */\r
-        exit_thread(0);\r
-    }\r
-}\r
-\r
-\r
-/*\r
- * Lock support.\r
- *\r
- */\r
-\r
-static atomic_t lock_count = 0;\r
-\r
-PyThread_type_lock PyThread_allocate_lock(void)\r
-{\r
-#ifdef FASTLOCK\r
-    fastmutex_t *lock;\r
-#else\r
-    sem_id sema;\r
-#endif\r
-    char name[OS_NAME_LENGTH];\r
-    atomic_t this_lock;\r
-\r
-    dprintf(("PyThread_allocate_lock called\n"));\r
-\r
-#ifdef FASTLOCK\r
-    lock = (fastmutex_t *) malloc(sizeof(fastmutex_t));\r
-    if (lock == NULL) {\r
-        dprintf(("PyThread_allocate_lock failed: out of memory\n"));\r
-        return (PyThread_type_lock) NULL;\r
-    }\r
-#endif\r
-    this_lock = atomic_add(&lock_count, 1);\r
-    PyOS_snprintf(name, sizeof(name), "python lock (%d)", this_lock);\r
-\r
-#ifdef FASTLOCK\r
-    if (fastmutex_create(name, lock) < 0) {\r
-        dprintf(("PyThread_allocate_lock failed: %s\n",\r
-                 strerror(errno)));\r
-        free(lock);\r
-        lock = NULL;\r
-    }\r
-    dprintf(("PyThread_allocate_lock()-> %p\n", lock));\r
-    return (PyThread_type_lock) lock;\r
-#else\r
-    sema = create_semaphore(name, 1, 0);\r
-    if (sema < 0) {\r
-        dprintf(("PyThread_allocate_lock failed: %s\n",\r
-                 strerror(errno)));\r
-        sema = 0;\r
-    }\r
-    dprintf(("PyThread_allocate_lock()-> %p\n", sema));\r
-    return (PyThread_type_lock) sema;\r
-#endif\r
-}\r
-\r
-\r
-void PyThread_free_lock(PyThread_type_lock lock)\r
-{\r
-    dprintf(("PyThread_free_lock(%p) called\n", lock));\r
-\r
-#ifdef FASTLOCK\r
-    if (fastmutex_destroy((fastmutex_t *) lock) < 0) {\r
-        dprintf(("PyThread_free_lock(%p) failed: %s\n", lock,\r
-                 strerror(errno)));\r
-    }\r
-    free(lock);\r
-#else\r
-    if (delete_semaphore((sem_id) lock) < 0) {\r
-        dprintf(("PyThread_free_lock(%p) failed: %s\n", lock,\r
-                 strerror(errno)));\r
-    }\r
-#endif\r
-}\r
-\r
-\r
-int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)\r
-{\r
-    int retval;\r
-\r
-    dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock,\r
-             waitflag));\r
-\r
-#ifdef FASTLOCK\r
-    if (waitflag)\r
-        retval = fastmutex_lock((fastmutex_t *) lock);\r
-    else\r
-        retval = fastmutex_timedlock((fastmutex_t *) lock, 0);\r
-#else\r
-    if (waitflag)\r
-        retval = lock_semaphore((sem_id) lock);\r
-    else\r
-        retval = lock_semaphore_x((sem_id) lock, 1, 0, 0);\r
-#endif\r
-    if (retval < 0) {\r
-        dprintf(("PyThread_acquire_lock(%p, %d) failed: %s\n",\r
-                 lock, waitflag, strerror(errno)));\r
-    }\r
-    dprintf(("PyThread_acquire_lock(%p, %d)-> %d\n", lock, waitflag,\r
-             retval));\r
-    return retval < 0 ? 0 : 1;\r
-}\r
-\r
-\r
-void PyThread_release_lock(PyThread_type_lock lock)\r
-{\r
-    dprintf(("PyThread_release_lock(%p) called\n", lock));\r
-\r
-#ifdef FASTLOCK\r
-    if (fastmutex_unlock((fastmutex_t *) lock) < 0) {\r
-        dprintf(("PyThread_release_lock(%p) failed: %s\n", lock,\r
-                 strerror(errno)));\r
-    }\r
-#else\r
-    if (unlock_semaphore((sem_id) lock) < 0) {\r
-        dprintf(("PyThread_release_lock(%p) failed: %s\n", lock,\r
-                 strerror(errno)));\r
-    }\r
-#endif\r
-}\r