Commits

Amaury Forgeot d'Arc  committed 5e1a89e

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

  • Participants
  • Parent commits 73b8484
  • Branches remove-PYPY_NOT_MAIN_FILE

Comments (0)

Files changed (11)

File pypy/translator/c/genc.py

         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',

File pypy/translator/c/src/g_prerequisite.h

 #  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>
 
 

File pypy/translator/c/src/obmalloc.c

 #ifdef WITH_PYMALLOC
 
 #include <string.h>
+#include <assert.h>
 
 /* An object allocator for Python.
 

File pypy/translator/c/src/stack.h

 /* 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;

File pypy/translator/c/src/thread.h

-
-/* #ifdef logic from CPython */
-
 #ifndef __PYPY_THREAD_H
 #define __PYPY_THREAD_H
 #include <assert.h>
 
 #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);

File pypy/translator/c/src/thread_nt.c

 }
 
 /************************************************************/
-
-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                                                 */
 /************************************************************/
 

File pypy/translator/c/src/thread_nt.h

 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)

File pypy/translator/c/src/thread_pthread.c

 /************************************************************/
 
 
-/* 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                                                 */
 /************************************************************/

File pypy/translator/c/src/thread_pthread.h

 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)

File pypy/translator/c/src/threadlocal.c

+#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

File pypy/translator/c/src/threadlocal.h

+/* 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
+