[Python-checkins] r84914 - in python/branches/py3k/Python: pystate.c thread_nt.h thread_pthread.h
kristjan.jonsson
python-checkins at python.org
Mon Sep 20 04:11:49 CEST 2010
Author: kristjan.jonsson
Date: Mon Sep 20 04:11:49 2010
New Revision: 84914
Log:
issue 9786 Native TLS support for pthreads
PyThread_create_key now has a failure mode that the applicatino can detect.
Modified:
python/branches/py3k/Python/pystate.c
python/branches/py3k/Python/thread_nt.h
python/branches/py3k/Python/thread_pthread.h
Modified: python/branches/py3k/Python/pystate.c
==============================================================================
--- python/branches/py3k/Python/pystate.c (original)
+++ python/branches/py3k/Python/pystate.c Mon Sep 20 04:11:49 2010
@@ -569,6 +569,8 @@
{
assert(i && t); /* must init with valid states */
autoTLSkey = PyThread_create_key();
+ if (autoTLSkey == -1)
+ Py_FatalError("Could not allocate TLS entry");
autoInterpreterState = i;
assert(PyThread_get_key_value(autoTLSkey) == NULL);
assert(t->gilstate_counter == 0);
Modified: python/branches/py3k/Python/thread_nt.h
==============================================================================
--- python/branches/py3k/Python/thread_nt.h (original)
+++ python/branches/py3k/Python/thread_nt.h Mon Sep 20 04:11:49 2010
@@ -315,7 +315,10 @@
int
PyThread_create_key(void)
{
- return (int) TlsAlloc();
+ DWORD result= TlsAlloc();
+ if (result == TLS_OUT_OF_INDEXES)
+ return -1;
+ return (int)result;
}
void
Modified: python/branches/py3k/Python/thread_pthread.h
==============================================================================
--- python/branches/py3k/Python/thread_pthread.h (original)
+++ python/branches/py3k/Python/thread_pthread.h Mon Sep 20 04:11:49 2010
@@ -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)
+{}
More information about the Python-checkins
mailing list