diff Python/thread_pthread.h @ 64844:8e428b8e7d81

issue 9786 Native TLS support for pthreads PyThread_create_key now has a failure mode that the applicatino can detect.
author Kristján Valur Jónsson <kristjan@ccpgames.com>
date Mon, 20 Sep 2010 02:11:49 +0000
parents cab14be0ada1
children ed5e598da150
line wrap: on
line diff
--- a/Python/thread_pthread.h	Mon Sep 20 01:33:21 2010 +0000
+++ b/Python/thread_pthread.h	Mon Sep 20 02:11:49 2010 +0000
@@ -558,3 +558,46 @@
 }
 
 #define THREAD_SET_STACKSIZE(x) _pythread_pthread_set_stacksize(x)
+
+#define Py_HAVE_NATIVE_TLS
+
+int
+PyThread_create_key(void)
+{
+    pthread_key_t key;
+    int fail = pthread_key_create(&key, NULL);
+    return fail ? -1 : key;
+}
+
+void
+PyThread_delete_key(int key)
+{
+    pthread_key_delete(key);
+}
+
+void
+PyThread_delete_key_value(int key)
+{
+    pthread_setspecific(key, NULL);
+}
+
+int
+PyThread_set_key_value(int key, void *value)
+{
+    int fail;
+    void *oldValue = pthread_getspecific(key);
+    if (oldValue != NULL)
+        return 0;
+    fail = pthread_setspecific(key, value);
+    return fail ? -1 : 0;
+}
+
+void *
+PyThread_get_key_value(int key)
+{
+    return pthread_getspecific(key);
+}
+
+void
+PyThread_ReInitTLS(void)
+{}