Author: Amaury Forgeot d'Arc <[email protected]>
Branch: remove-PYPY_NOT_MAIN_FILE
Changeset: r58083:5e1a89eeafe4
Date: 2012-10-03 22:32 +0200
http://bitbucket.org/pypy/pypy/changeset/5e1a89eeafe4/

Log:    It's certainly a good idea to put thread functions apart, and only
        compile TLS storage with other genc sources.

diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -918,7 +918,7 @@
         srcdir / 'debug_print.c',
         srcdir / 'debug_traceback.c',  # ifdef HAVE_RTYPER
         srcdir / 'stack.c',
-        srcdir / 'thread.c',
+        srcdir / 'threadlocal.c',
         srcdir / 'asm.c',
         srcdir / 'instrument.c',
         srcdir / 'int.c',
diff --git a/pypy/translator/c/src/g_prerequisite.h 
b/pypy/translator/c/src/g_prerequisite.h
--- a/pypy/translator/c/src/g_prerequisite.h
+++ b/pypy/translator/c/src/g_prerequisite.h
@@ -11,9 +11,6 @@
 #  include <io.h>   /* needed, otherwise _lseeki64 truncates to 32-bits (??) */
 #endif
 
-#include "thread.h"   /* needs to be included early to define the
-                         struct RPyOpaque_ThreadLock */
-
 #include <stddef.h>
 
 
diff --git a/pypy/translator/c/src/obmalloc.c b/pypy/translator/c/src/obmalloc.c
--- a/pypy/translator/c/src/obmalloc.c
+++ b/pypy/translator/c/src/obmalloc.c
@@ -2,6 +2,7 @@
 #ifdef WITH_PYMALLOC
 
 #include <string.h>
+#include <assert.h>
 
 /* An object allocator for Python.
 
diff --git a/pypy/translator/c/src/stack.h b/pypy/translator/c/src/stack.h
--- a/pypy/translator/c/src/stack.h
+++ b/pypy/translator/c/src/stack.h
@@ -9,7 +9,7 @@
 /* This include must be done in any case to initialise
  * the header dependencies early (winsock2, before windows.h).
  * It is needed to have RPyThreadStaticTLS, too. */
-#include "thread.h"
+#include "threadlocal.h"
 
 extern char *_LLstacktoobig_stack_end;
 extern long _LLstacktoobig_stack_length;
diff --git a/pypy/translator/c/src/thread.h b/pypy/translator/c/src/thread.h
--- a/pypy/translator/c/src/thread.h
+++ b/pypy/translator/c/src/thread.h
@@ -1,6 +1,3 @@
-
-/* #ifdef logic from CPython */
-
 #ifndef __PYPY_THREAD_H
 #define __PYPY_THREAD_H
 #include <assert.h>
@@ -19,25 +16,6 @@
 
 #endif /* !_WIN32 */
 
-#ifdef USE___THREAD
-
-#define RPyThreadStaticTLS                  __thread void *
-#define RPyThreadStaticTLS_Create(tls)      NULL
-#define RPyThreadStaticTLS_Get(tls)         tls
-#define RPyThreadStaticTLS_Set(tls, value)  tls = value
-
-#endif
-
-#ifndef RPyThreadStaticTLS
-
-#define RPyThreadStaticTLS             RPyThreadTLS
-#define RPyThreadStaticTLS_Create(key) RPyThreadTLS_Create(key)
-#define RPyThreadStaticTLS_Get(key)    RPyThreadTLS_Get(key)
-#define RPyThreadStaticTLS_Set(key, value) RPyThreadTLS_Set(key, value)
-char *RPyThreadTLS_Create(RPyThreadTLS *result);
-
-#endif
-
 long RPyGilAllocate(void);
 long RPyGilYieldThread(void);
 void RPyGilRelease(void);
diff --git a/pypy/translator/c/src/thread_nt.c 
b/pypy/translator/c/src/thread_nt.c
--- a/pypy/translator/c/src/thread_nt.c
+++ b/pypy/translator/c/src/thread_nt.c
@@ -181,17 +181,6 @@
 }
 
 /************************************************************/
-
-char *RPyThreadTLS_Create(RPyThreadTLS *result)
-{
-       *result = TlsAlloc();
-       if (*result == TLS_OUT_OF_INDEXES)
-               return "out of thread-local storage indexes";
-       else
-               return NULL;
-}
-
-/************************************************************/
 /* GIL code                                                 */
 /************************************************************/
 
diff --git a/pypy/translator/c/src/thread_nt.h 
b/pypy/translator/c/src/thread_nt.h
--- a/pypy/translator/c/src/thread_nt.h
+++ b/pypy/translator/c/src/thread_nt.h
@@ -21,8 +21,3 @@
 long RPyThreadGetStackSize(void);
 long RPyThreadSetStackSize(long);
 
-/* Thread-local storage */
-#define __thread __declspec(thread)
-typedef DWORD RPyThreadTLS;
-#define RPyThreadTLS_Get(key)          TlsGetValue(key)
-#define RPyThreadTLS_Set(key, value)   TlsSetValue(key, value)
diff --git a/pypy/translator/c/src/thread_pthread.c 
b/pypy/translator/c/src/thread_pthread.c
--- a/pypy/translator/c/src/thread_pthread.c
+++ b/pypy/translator/c/src/thread_pthread.c
@@ -377,17 +377,6 @@
 /************************************************************/
 
 
-/* Thread-local storage */
-
-char *RPyThreadTLS_Create(RPyThreadTLS *result)
-{
-       if (pthread_key_create(result, NULL) != 0)
-               return "out of thread-local storage keys";
-       else
-               return NULL;
-}
-
-
 /************************************************************/
 /* GIL code                                                 */
 /************************************************************/
diff --git a/pypy/translator/c/src/thread_pthread.h 
b/pypy/translator/c/src/thread_pthread.h
--- a/pypy/translator/c/src/thread_pthread.h
+++ b/pypy/translator/c/src/thread_pthread.h
@@ -75,11 +75,3 @@
 long RPyThreadGetStackSize(void);
 long RPyThreadSetStackSize(long);
 void RPyThreadAfterFork(void);
-
-
-/* implementations */
-
-/* Thread-local storage */
-typedef pthread_key_t RPyThreadTLS;
-#define RPyThreadTLS_Get(key)          pthread_getspecific(key)
-#define RPyThreadTLS_Set(key, value)   pthread_setspecific(key, value)
diff --git a/pypy/translator/c/src/threadlocal.c 
b/pypy/translator/c/src/threadlocal.c
new file mode 100644
--- /dev/null
+++ b/pypy/translator/c/src/threadlocal.c
@@ -0,0 +1,24 @@
+#include "src/threadlocal.h"
+
+#ifdef _WIN32
+
+char *RPyThreadTLS_Create(RPyThreadTLS *result)
+{
+    *result = TlsAlloc();
+    if (*result == TLS_OUT_OF_INDEXES)
+        return "out of thread-local storage indexes";
+    else
+        return NULL;
+}
+
+#else
+
+char *RPyThreadTLS_Create(RPyThreadTLS *result)
+{
+    if (pthread_key_create(result, NULL) != 0)
+        return "out of thread-local storage keys";
+    else
+        return NULL;
+}
+
+#endif
diff --git a/pypy/translator/c/src/threadlocal.h 
b/pypy/translator/c/src/threadlocal.h
new file mode 100644
--- /dev/null
+++ b/pypy/translator/c/src/threadlocal.h
@@ -0,0 +1,39 @@
+/* Thread-local storage */
+
+#ifdef _WIN32
+
+#include <windows.h>
+#define __thread __declspec(thread)
+typedef DWORD RPyThreadTLS;
+#define RPyThreadTLS_Get(key)          TlsGetValue(key)
+#define RPyThreadTLS_Set(key, value)   TlsSetValue(key, value)
+
+#else
+
+#include <pthread.h>
+typedef pthread_key_t RPyThreadTLS;
+#define RPyThreadTLS_Get(key)          pthread_getspecific(key)
+#define RPyThreadTLS_Set(key, value)   pthread_setspecific(key, value)
+
+#endif
+
+
+#ifdef USE___THREAD
+
+#define RPyThreadStaticTLS                  __thread void *
+#define RPyThreadStaticTLS_Create(tls)      NULL
+#define RPyThreadStaticTLS_Get(tls)         tls
+#define RPyThreadStaticTLS_Set(tls, value)  tls = value
+
+#endif
+
+#ifndef RPyThreadStaticTLS
+
+#define RPyThreadStaticTLS             RPyThreadTLS
+#define RPyThreadStaticTLS_Create(key) RPyThreadTLS_Create(key)
+#define RPyThreadStaticTLS_Get(key)    RPyThreadTLS_Get(key)
+#define RPyThreadStaticTLS_Set(key, value) RPyThreadTLS_Set(key, value)
+char *RPyThreadTLS_Create(RPyThreadTLS *result);
+
+#endif
+
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to