[pypy-commit] pypy portable-threadlocal: Clean up rstack.{py, c, h} by removing an obscure conditional include
arigo
noreply at buildbot.pypy.org
Sat Nov 22 19:12:46 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: portable-threadlocal
Changeset: r74635:d8c6c988cd8c
Date: 2014-11-22 19:10 +0100
http://bitbucket.org/pypy/pypy/changeset/d8c6c988cd8c/
Log: Clean up rstack.{py,c,h} by removing an obscure conditional include
diff --git a/rpython/rlib/rstack.py b/rpython/rlib/rstack.py
--- a/rpython/rlib/rstack.py
+++ b/rpython/rlib/rstack.py
@@ -1,6 +1,6 @@
"""
This file defines utilities for manipulating the stack in an
-RPython-compliant way, intended mostly for use by the Stackless PyPy.
+RPython-compliant way. It is mainly about the stack_check() function.
"""
import py
@@ -10,18 +10,11 @@
from rpython.rlib import rgc
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rtyper.lltypesystem.lloperation import llop
-from rpython.translator import cdir
-from rpython.translator.tool.cbuild import ExternalCompilationInfo
# ____________________________________________________________
-srcdir = py.path.local(cdir) / 'src'
-compilation_info = ExternalCompilationInfo(
- includes=['src/stack.h'],
- separate_module_files=[srcdir / 'stack.c', srcdir / 'threadlocal.c'])
-
def llexternal(name, args, res, _callable=None):
- return rffi.llexternal(name, args, res, compilation_info=compilation_info,
+ return rffi.llexternal(name, args, res,
sandboxsafe=True, _nowrapper=True,
_callable=_callable)
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
@@ -707,22 +707,21 @@
print >> f, "#endif"
def gen_threadlocal_structdef(f, database):
+ from rpython.translator.c.support import cdecl
+ print >> f
bk = database.translator.annotator.bookkeeper
- if bk.thread_local_fields:
- from rpython.translator.c.support import cdecl
- print >> f
- fields = list(bk.thread_local_fields)
- fields.sort(key=lambda field: field.fieldname)
- print >> f, '#define RPY_HAS_THREADLOCAL_S'
- for field in fields:
- print >> f, ('#define RPY_TLOFS_%s offsetof(' % field.fieldname +
- 'struct pypy_threadlocal_s, %s)' % field.fieldname)
- print >> f, 'struct pypy_threadlocal_s {'
- for field in fields:
- typename = database.gettype(field.FIELDTYPE)
- print >> f, '\t%s;' % cdecl(typename, field.fieldname)
- print >> f, '};'
- print >> f
+ fields = list(bk.thread_local_fields)
+ fields.sort(key=lambda field: field.fieldname)
+ for field in fields:
+ print >> f, ('#define RPY_TLOFS_%s offsetof(' % field.fieldname +
+ 'struct pypy_threadlocal_s, %s)' % field.fieldname)
+ print >> f, 'struct pypy_threadlocal_s {'
+ print >> f, '\tchar *stack_end;'
+ for field in fields:
+ typename = database.gettype(field.FIELDTYPE)
+ print >> f, '\t%s;' % cdecl(typename, field.fieldname)
+ print >> f, '};'
+ print >> f
def gen_forwarddecl(f, database):
print >> f, '/***********************************************************/'
@@ -794,6 +793,7 @@
srcdir / 'asm.c',
srcdir / 'instrument.c',
srcdir / 'int.c',
+ srcdir / 'stack.c',
srcdir / 'threadlocal.c',
]
if _CYGWIN:
diff --git a/rpython/translator/c/src/g_include.h b/rpython/translator/c/src/g_include.h
--- a/rpython/translator/c/src/g_include.h
+++ b/rpython/translator/c/src/g_include.h
@@ -19,6 +19,8 @@
#include "src/address.h"
#include "src/unichar.h"
#include "src/llgroup.h"
+#include "src/stack.h"
+#include "src/threadlocal.h"
#include "src/instrument.h"
#include "src/asm.h"
@@ -48,7 +50,3 @@
#ifdef __CYGWIN__
#include "src/cygwin_wait.h"
#endif
-
-#ifdef RPY_HAS_THREADLOCAL_S
-#include "src/threadlocal.h"
-#endif
diff --git a/rpython/translator/c/src/stack.c b/rpython/translator/c/src/stack.c
--- a/rpython/translator/c/src/stack.c
+++ b/rpython/translator/c/src/stack.c
@@ -1,6 +1,8 @@
/* Stack operation */
+#include "common_header.h"
+#include "structdef.h" /* for struct pypy_threadlocal_s */
#include <src/stack.h>
-#include <src/thread.h>
+#include <src/threadlocal.h>
#include <stdio.h>
@@ -9,7 +11,6 @@
char *_LLstacktoobig_stack_end = NULL;
long _LLstacktoobig_stack_length = MAX_STACK_SIZE;
char _LLstacktoobig_report_error = 1;
-static RPyThreadStaticTLS end_tls_key;
void LL_stack_set_length_fraction(double fraction)
{
@@ -20,6 +21,8 @@
{
long diff, max_stack_size;
char *baseptr, *curptr = (char*)current;
+ char *tl;
+ struct pypy_threadlocal_s *tl1;
/* The stack_end variable is updated to match the current value
if it is still 0 or if we later find a 'curptr' position
@@ -27,15 +30,9 @@
thread-local storage, but we try to minimize its overhead by
keeping a local copy in _LLstacktoobig_stack_end. */
- if (_LLstacktoobig_stack_end == NULL) {
- /* not initialized */
- /* XXX We assume that initialization is performed early,
- when there is still only one thread running. This
- allows us to ignore race conditions here */
- RPyThreadStaticTLS_Create(&end_tls_key);
- }
-
- baseptr = (char *) RPyThreadStaticTLS_Get(end_tls_key);
+ OP_THREADLOCALREF_ADDR(tl);
+ tl1 = (struct pypy_threadlocal_s *)tl;
+ baseptr = tl1->stack_end;
max_stack_size = _LLstacktoobig_stack_length;
if (baseptr == NULL) {
/* first time we see this thread */
@@ -58,7 +55,7 @@
/* update the stack base pointer to the current value */
baseptr = curptr;
- RPyThreadStaticTLS_Set(end_tls_key, baseptr);
+ tl1->stack_end = baseptr;
_LLstacktoobig_stack_end = baseptr;
return 0;
}
diff --git a/rpython/translator/c/src/stack.h b/rpython/translator/c/src/stack.h
--- a/rpython/translator/c/src/stack.h
+++ b/rpython/translator/c/src/stack.h
@@ -2,14 +2,13 @@
/************************************************************/
/*** C header subsection: stack operations ***/
+#include <src/precommondefs.h>
+
+
#ifndef MAX_STACK_SIZE
# define MAX_STACK_SIZE (3 << 18) /* 768 kb */
#endif
-/* 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 "threadlocal.h"
RPY_EXTERN char *_LLstacktoobig_stack_end;
RPY_EXTERN long _LLstacktoobig_stack_length;
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
@@ -1,14 +1,10 @@
#include "common_header.h"
-#include "structdef.h"
-
-#ifdef RPY_HAS_THREADLOCAL_S /* otherwise, this file is not needed */
-
+#include "structdef.h" /* for struct pypy_threadlocal_s */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "src/threadlocal.h"
-#include "src/thread.h"
#ifdef _WIN32
@@ -103,6 +99,3 @@
/* ------------------------------------------------------------ */
#endif
/* ------------------------------------------------------------ */
-
-
-#endif /* RPY_HAS_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
@@ -5,11 +5,6 @@
#include <src/precommondefs.h>
-#ifndef RPY_HAS_THREADLOCAL_S
-# error "src/threadlocal.h should only be included if RPY_HAS_THREADLOCAL_S"
-#endif
-
-
/* ------------------------------------------------------------ */
#ifdef USE___THREAD
/* ------------------------------------------------------------ */
More information about the pypy-commit
mailing list