Author: Armin Rigo <ar...@tunes.org> Branch: portable-threadlocal Changeset: r74649:9c067d3de94c Date: 2014-11-23 11:59 +0100 http://bitbucket.org/pypy/pypy/changeset/9c067d3de94c/
Log: Test and fix diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py --- a/rpython/translator/c/genc.py +++ b/rpython/translator/c/genc.py @@ -749,6 +749,11 @@ # generate the start-up code and put it into a function print >> f, 'char *RPython_StartupCode(void) {' print >> f, '\tchar *error = NULL;' + + bk = database.translator.annotator.bookkeeper + if bk.thread_local_fields: + print >> f, '\tRPython_ThreadLocals_ProgramInit();' + for line in database.gcpolicy.gc_startup_code(): print >> f,"\t" + line @@ -768,10 +773,6 @@ for line in lines: print >> f, '\t'+line - bk = database.translator.annotator.bookkeeper - if bk.thread_local_fields: - print >> f, '\tRPython_ThreadLocals_ProgramInit();' - print >> f, '\treturn error;' print >> f, '}' diff --git a/rpython/translator/c/src/support.h b/rpython/translator/c/src/support.h --- a/rpython/translator/c/src/support.h +++ b/rpython/translator/c/src/support.h @@ -2,6 +2,9 @@ /************************************************************/ /*** C header subsection: support functions ***/ +#ifndef _SRC_SUPPORT_H +#define _SRC_SUPPORT_H + #define RUNNING_ON_LLINTERP 0 #define OP_JIT_RECORD_KNOWN_CLASS(i, c, r) /* nothing */ @@ -65,3 +68,5 @@ # define RPyNLenItem(array, index) ((array)->items[index]) # define RPyBareItem(array, index) ((array)[index]) #endif + +#endif /* _SRC_SUPPORT_H */ 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 @@ -27,7 +27,7 @@ where it is not the case are rather old nowadays. */ # endif #endif - ((struct pypy_threadlocal_s *)p)->ready = 1; + ((struct pypy_threadlocal_s *)p)->ready = 42; } @@ -47,6 +47,7 @@ char *_RPython_ThreadLocals_Build(void) { + RPyAssert(pypy_threadlocal.ready == 0, "corrupted thread-local"); _RPy_ThreadLocals_Init(&pypy_threadlocal); return (char *)&pypy_threadlocal; } 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 @@ -2,7 +2,8 @@ #ifndef _SRC_THREADLOCAL_H #define _SRC_THREADLOCAL_H -#include <src/precommondefs.h> +#include "src/precommondefs.h" +#include "src/support.h" /* RPython_ThreadLocals_ProgramInit() is called once at program start-up. */ @@ -29,10 +30,20 @@ /* Use the '__thread' specifier, so far only on Linux */ RPY_EXTERN __thread struct pypy_threadlocal_s pypy_threadlocal; -#define OP_THREADLOCALREF_ADDR(r) r = (char *)&pypy_threadlocal -#define OP_THREADLOCALREF_MAKE(r) \ - (OP_THREADLOCALREF_ADDR(r), \ - (pypy_threadlocal.ready || (r = _RPython_ThreadLocals_Build()))) + +#define OP_THREADLOCALREF_ADDR(r) \ + do { \ + RPyAssert(pypy_threadlocal.ready == 42, \ + "uninitialized thread-local!"); \ + r = (char *)&pypy_threadlocal; \ + } while (0) + +#define OP_THREADLOCALREF_MAKE(r) \ + do { \ + r = (char *)&pypy_threadlocal; \ + if (pypy_threadlocal.ready != 42) \ + r = _RPython_ThreadLocals_Build(); \ + } while (0) /* ------------------------------------------------------------ */ _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit