[pypy-commit] pypy portable-threadlocal: More fixes. Now basically works on the framework GC too.

arigo noreply at buildbot.pypy.org
Sat Nov 22 18:51:02 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: portable-threadlocal
Changeset: r74634:e628e1043040
Date: 2014-11-22 18:50 +0100
http://bitbucket.org/pypy/pypy/changeset/e628e1043040/

Log:	More fixes. Now basically works on the framework GC too.

diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py
--- a/rpython/rlib/rthread.py
+++ b/rpython/rlib/rthread.py
@@ -276,12 +276,12 @@
 
         def getraw():
             _threadlocalref_seeme(self)
-            addr = llop.threadlocalref_addr(llmemory.Address)
+            addr = llop.threadlocalref_addr(rffi.CCHARP)
             return llop.raw_load(FIELDTYPE, addr, offset)
 
         def setraw(value):
             _threadlocalref_seeme(self)
-            addr = llop.threadlocalref_addr(llmemory.Address)
+            addr = llop.threadlocalref_addr(rffi.CCHARP)
             llop.raw_store(lltype.Void, addr, offset, value)
 
         self.getraw = getraw
diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py
--- a/rpython/rtyper/llinterp.py
+++ b/rpython/rtyper/llinterp.py
@@ -919,20 +919,14 @@
     def op_stack_current(self):
         return 0
 
-    def op_threadlocalref_set(self, key, value):
+    def op_threadlocalref_addr(self, key, value):
+        raise NotImplementedError("threadlocalref_addr")  # XXX implement me?
         try:
             d = self.llinterpreter.tlrefsdict
         except AttributeError:
             d = self.llinterpreter.tlrefsdict = {}
         d[key._obj] = value
 
-    def op_threadlocalref_get(self, key):
-        d = self.llinterpreter.tlrefsdict
-        return d[key._obj]
-
-    def op_threadlocalref_getaddr(self, key):
-        raise NotImplementedError("threadlocalref_getaddr")
-
     # __________________________________________________________
     # operations on addresses
 
diff --git a/rpython/translator/c/src/thread_nt.c b/rpython/translator/c/src/thread_nt.c
--- a/rpython/translator/c/src/thread_nt.c
+++ b/rpython/translator/c/src/thread_nt.c
@@ -26,15 +26,6 @@
 
 static long _pypythread_stacksize = 0;
 
-/*
- * Return the thread Id instead of an handle. The Id is said to uniquely
-   identify the thread in the system
- */
-long RPyThreadGetIdent()
-{
-  return GetCurrentThreadId();
-}
-
 static void
 bootstrap(void *call)
 {
@@ -42,7 +33,7 @@
 	/* copy callobj since other thread might free it before we're done */
 	void (*func)(void) = obj->func;
 
-	obj->id = RPyThreadGetIdent();
+	obj->id = GetCurrentThreadId();
 	ReleaseSemaphore(obj->done, 1, NULL);
 	func();
 }
diff --git a/rpython/translator/c/src/thread_nt.h b/rpython/translator/c/src/thread_nt.h
--- a/rpython/translator/c/src/thread_nt.h
+++ b/rpython/translator/c/src/thread_nt.h
@@ -13,8 +13,6 @@
 
 /* prototypes */
 RPY_EXTERN
-long RPyThreadGetIdent(void);
-RPY_EXTERN
 long RPyThreadStart(void (*func)(void));
 RPY_EXTERN
 int RPyThreadLockInit(struct RPyOpaque_ThreadLock *lock);
diff --git a/rpython/translator/c/src/thread_pthread.c b/rpython/translator/c/src/thread_pthread.c
--- a/rpython/translator/c/src/thread_pthread.c
+++ b/rpython/translator/c/src/thread_pthread.c
@@ -56,30 +56,6 @@
 # endif
 #endif
 
-/* XXX This implementation is considered (to quote Tim Peters) "inherently
-   hosed" because:
-     - It does not guarantee the promise that a non-zero integer is returned.
-     - The cast to long is inherently unsafe.
-     - It is not clear that the 'volatile' (for AIX?) and ugly casting in the
-       latter return statement (for Alpha OSF/1) are any longer necessary.
-*/
-long RPyThreadGetIdent(void)
-{
-	volatile pthread_t threadid;
-	/* Jump through some hoops for Alpha OSF/1 */
-	threadid = pthread_self();
-
-#ifdef __CYGWIN__
-	/* typedef __uint32_t pthread_t; */
-	return (long) threadid;
-#else
-	if (sizeof(pthread_t) <= sizeof(long))
-		return (long) threadid;
-	else
-		return (long) *(long *) &threadid;
-#endif
-}
-
 static long _pypythread_stacksize = 0;
 
 static void *bootstrap_pthread(void *func)
diff --git a/rpython/translator/c/src/thread_pthread.h b/rpython/translator/c/src/thread_pthread.h
--- a/rpython/translator/c/src/thread_pthread.h
+++ b/rpython/translator/c/src/thread_pthread.h
@@ -60,8 +60,6 @@
 /* prototypes */
 
 RPY_EXTERN
-long RPyThreadGetIdent(void);
-RPY_EXTERN
 long RPyThreadStart(void (*func)(void));
 RPY_EXTERN
 int RPyThreadLockInit(struct RPyOpaque_ThreadLock *lock);
diff --git a/rpython/translator/c/src/threadlocal.c b/rpython/translator/c/src/threadlocal.c
--- a/rpython/translator/c/src/threadlocal.c
+++ b/rpython/translator/c/src/threadlocal.c
@@ -11,6 +11,16 @@
 #include "src/thread.h"
 
 
+#ifdef _WIN32
+#  define RPyThreadGetIdent() GetCurrentThreadId()
+#else
+#  define RPyThreadGetIdent() ((long)pthread_self())
+/* xxx This abuses pthread_self() by assuming it just returns a long.
+   According to comments in CPython's source code, the platforms where
+   it is wrong are rather old nowadays. */
+#endif
+
+
 static void _RPython_ThreadLocals_Init(void *p)
 {
     memset(p, 0, sizeof(struct pypy_threadlocal_s));
diff --git a/rpython/translator/c/src/threadlocal.h b/rpython/translator/c/src/threadlocal.h
--- a/rpython/translator/c/src/threadlocal.h
+++ b/rpython/translator/c/src/threadlocal.h
@@ -18,7 +18,7 @@
 /* Use the '__thread' specifier, so far only on Linux */
 
 RPY_EXTERN __thread struct pypy_threadlocal_s pypy_threadlocal;
-#define OP_THREADLOCALREF_ADDR(r)    r = &pypy_threadlocal
+#define OP_THREADLOCALREF_ADDR(r)    r = (char *)&pypy_threadlocal
 
 
 /* ------------------------------------------------------------ */
@@ -30,7 +30,8 @@
 #include <windows.h>
 
 RPY_EXTERN DWORD pypy_threadlocal_key;
-#define OP_THREADLOCALREF_ADDR(r)    r = TlsGetValue(pypy_threadlocal_key)
+#define OP_THREADLOCALREF_ADDR(r)    r = (char *)TlsGetValue(  \
+                                           pypy_threadlocal_key)
 
 
 /* ------------------------------------------------------------ */
@@ -43,7 +44,8 @@
 #include <pthread.h>
 
 RPY_EXTERN pthread_key_t pypy_threadlocal_key;
-#define OP_THREADLOCALREF_ADDR(r)  r = pthread_getspecific(pypy_threadlocal_key)
+#define OP_THREADLOCALREF_ADDR(r)    r = (char *)pthread_getspecific(  \
+                                           pypy_threadlocal_key)
 
 
 /* ------------------------------------------------------------ */


More information about the pypy-commit mailing list