Author: Armin Rigo <[email protected]>
Branch: portable-threadlocal
Changeset: r74736:31fa1fdc28a7
Date: 2014-11-26 15:44 +0100
http://bitbucket.org/pypy/pypy/changeset/31fa1fdc28a7/
Log: test and fix for the no-__thread case
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
@@ -69,6 +69,9 @@
explicitly, with malloc()/free(), and attached to (a single) thread-
local key using the API of Windows or pthread. */
+pthread_key_t pypy_threadlocal_key;
+
+
void RPython_ThreadLocals_ProgramInit(void)
{
#ifdef _WIN32
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
@@ -55,15 +55,16 @@
#ifdef _WIN32
# include <WinSock2.h>
# include <windows.h>
-# define _RPy_ThreadLocals_Get TlsGetValue
-# define _RPy_ThreadLocals_Set TlsSetValue
-RPY_EXTERN DWORD pypy_threadlocal_key;
+# define _RPy_ThreadLocals_Get() TlsGetValue(pypy_threadlocal_key)
+# define _RPy_ThreadLocals_Set(x) TlsSetValue(pypy_threadlocal_key, x)
+typedef DWORD pthread_key_t;
#else
# include <pthread.h>
-# define _RPy_ThreadLocals_Get pthread_getspecific
-# define _RPy_ThreadLocals_Set pthread_setspecific
+# define _RPy_ThreadLocals_Get() pthread_getspecific(pypy_threadlocal_key)
+# define _RPy_ThreadLocals_Set(x) pthread_setspecific(pypy_threadlocal_key,
x)
+#endif
+
RPY_EXTERN pthread_key_t pypy_threadlocal_key;
-#endif
#define OP_THREADLOCALREF_ADDR(r) \
diff --git a/rpython/translator/c/test/test_standalone.py
b/rpython/translator/c/test/test_standalone.py
--- a/rpython/translator/c/test/test_standalone.py
+++ b/rpython/translator/c/test/test_standalone.py
@@ -2,6 +2,7 @@
import sys, os, re
from rpython.config.translationoption import get_combined_translation_config
+from rpython.config.translationoption import SUPPORT__THREAD
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rlib.rarithmetic import r_longlong
from rpython.rlib.debug import ll_assert, have_debug_prints, debug_flush
@@ -1026,11 +1027,12 @@
gcrootfinder = 'shadowstack'
config = None
- def compile(self, entry_point):
+ def compile(self, entry_point, no__thread=True):
t = TranslationContext(self.config)
t.config.translation.gc = "semispace"
t.config.translation.gcrootfinder = self.gcrootfinder
t.config.translation.thread = True
+ t.config.translation.no__thread = no__thread
t.buildannotator().build_types(entry_point, [s_list_of_strings])
t.buildrtyper().specialize()
#
@@ -1142,7 +1144,7 @@
def test_thread_and_gc(self):
import time, gc
- from rpython.rlib import rthread
+ from rpython.rlib import rthread, rposix
from rpython.rtyper.lltypesystem import lltype
from rpython.rlib.objectmodel import invoke_around_extcall
@@ -1163,14 +1165,22 @@
self.head = head
self.tail = tail
+ def check_errno(value):
+ rposix.set_errno(value)
+ for i in range(10000000):
+ pass
+ assert rposix.get_errno() == value
+
def bootstrap():
rthread.gc_thread_start()
+ check_errno(42)
state.xlist.append(Cons(123, Cons(456, None)))
gc.collect()
rthread.gc_thread_die()
def new_thread():
ident = rthread.start_new_thread(bootstrap, ())
+ check_errno(41)
time.sleep(0.5) # enough time to start, hopefully
return ident
@@ -1209,14 +1219,19 @@
os.write(1, "%d ok\n" % (i+1))
return 0
- t, cbuilder = self.compile(entry_point)
- data = cbuilder.cmdexec('')
- assert data.splitlines() == ['hello world',
- '1 ok',
- '2 ok',
- '3 ok',
- '4 ok',
- '5 ok']
+ def runme(no__thread):
+ t, cbuilder = self.compile(entry_point, no__thread=no__thread)
+ data = cbuilder.cmdexec('')
+ assert data.splitlines() == ['hello world',
+ '1 ok',
+ '2 ok',
+ '3 ok',
+ '4 ok',
+ '5 ok']
+
+ if SUPPORT__THREAD:
+ runme(no__thread=False)
+ runme(no__thread=True)
def test_gc_with_fork_without_threads(self):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit