[pypy-commit] stmgc c7: move the global lock to an extra file "stmsync"

Remi Meier noreply at buildbot.pypy.org
Wed Jan 22 14:41:34 CET 2014


Author: Remi Meier
Branch: c7
Changeset: r667:82077634d84a
Date: 2014-01-22 14:37 +0100
http://bitbucket.org/pypy/stmgc/changeset/82077634d84a/

Log:	move the global lock to an extra file "stmsync"

diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -15,6 +15,7 @@
 #include "reader_writer_lock.h"
 #include "nursery.h"
 #include "pages.h"
+#include "stmsync.h"
 
 
 
@@ -24,46 +25,6 @@
 
 
 
-
-/* a multi-reader, single-writer lock: transactions normally take a reader
-   lock, so don't conflict with each other; when we need to do a global GC,
-   we take a writer lock to "stop the world". */
-
-rwticket rw_shared_lock;        /* the "GIL" */
-
-void stm_start_shared_lock(void)
-{
-    rwticket_rdlock(&rw_shared_lock);
-}
-
-void stm_stop_shared_lock(void)
-{
-    rwticket_rdunlock(&rw_shared_lock);
-}
-
-void stm_stop_exclusive_lock(void)
-{
-    rwticket_wrunlock(&rw_shared_lock);
-}
-
-void stm_start_exclusive_lock(void)
-{
-    rwticket_wrlock(&rw_shared_lock);
-}
-
-void _stm_start_safe_point(void)
-{
-    assert(!_STM_TL->need_abort);
-    stm_stop_shared_lock();
-}
-
-void _stm_stop_safe_point(void)
-{
-    stm_start_shared_lock();
-    if (_STM_TL->need_abort)
-        stm_abort_transaction();
-}
-
 bool _stm_was_read_remote(char *base, object_t *obj)
 {
     struct read_marker_s *marker = (struct read_marker_s *)
@@ -73,7 +34,6 @@
     return (marker->rm == other_TL1->transaction_read_version);
 }
 
-
 bool _stm_was_read(object_t *obj)
 {
     read_marker_t *marker = (read_marker_t *)(((uintptr_t)obj) >> 4);
@@ -89,30 +49,6 @@
 
 
 
-
-
-char *_stm_real_address(object_t *o)
-{
-    if (o == NULL)
-        return NULL;
-    assert(FIRST_OBJECT_PAGE * 4096 <= (uintptr_t)o
-           && (uintptr_t)o < NB_PAGES * 4096);
-    return (char*)real_address(o);
-}
-
-object_t *_stm_tl_address(char *ptr)
-{
-    if (ptr == NULL)
-        return NULL;
-    
-    uintptr_t res = ptr - _STM_TL->thread_base;
-    assert(FIRST_OBJECT_PAGE * 4096 <= res
-           && res < NB_PAGES * 4096);
-    return (object_t*)res;
-}
-
-
-
 static void push_modified_to_other_threads()
 {
     /* WE HAVE THE EXCLUSIVE LOCK HERE */
@@ -148,10 +84,6 @@
 
 
 
-
-
-
-
 void _stm_write_slowpath(object_t *obj)
 {
     uintptr_t pagenum = ((uintptr_t)obj) / 4096;
@@ -200,7 +132,7 @@
 
 void stm_setup(void)
 {
-    memset(&rw_shared_lock, 0, sizeof(rwticket));
+    _stm_reset_shared_lock();
 
     /* Check that some values are acceptable */
     assert(4096 <= ((uintptr_t)_STM_TL));
@@ -300,8 +232,7 @@
 
 void _stm_teardown_thread(void)
 {
-    assert(!rwticket_wrtrylock(&rw_shared_lock));
-    assert(!rwticket_wrunlock(&rw_shared_lock));
+    _stm_reset_shared_lock();
     
     stm_list_free(_STM_TL->modified_objects);
     _STM_TL->modified_objects = NULL;
diff --git a/c7/core.h b/c7/core.h
--- a/c7/core.h
+++ b/c7/core.h
@@ -4,7 +4,7 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <stdbool.h>
-
+#include <assert.h>
 
 #define NB_PAGES            (256*256)    // 256MB
 #define NB_THREADS          2
@@ -133,6 +133,26 @@
     return (struct object_s*)REAL_ADDRESS(_STM_TL->thread_base, src);
 }
 
+static inline char *_stm_real_address(object_t *o)
+{
+    if (o == NULL)
+        return NULL;
+    assert(FIRST_OBJECT_PAGE * 4096 <= (uintptr_t)o
+           && (uintptr_t)o < NB_PAGES * 4096);
+    return (char*)real_address(o);
+}
+
+static inline object_t *_stm_tl_address(char *ptr)
+{
+    if (ptr == NULL)
+        return NULL;
+    
+    uintptr_t res = ptr - _STM_TL->thread_base;
+    assert(FIRST_OBJECT_PAGE * 4096 <= res
+           && res < NB_PAGES * 4096);
+    return (object_t*)res;
+}
+
 static inline char *get_thread_base(long thread_num)
 {
     return object_pages + thread_num * (NB_PAGES * 4096UL);
@@ -195,16 +215,12 @@
 void stm_setup_thread(void);
 void stm_start_transaction(jmpbufptr_t *jmpbufptr);
 void stm_stop_transaction(void);
-char *_stm_real_address(object_t *o);
-object_t *_stm_tl_address(char *ptr);
+
 
 object_t *_stm_allocate_old(size_t size);
 
 object_t *stm_allocate_prebuilt(size_t size);
 
-void _stm_start_safe_point(void);
-void _stm_stop_safe_point(void);
-
 void stm_abort_transaction(void);
 
 void _stm_minor_collect();
diff --git a/c7/nursery.c b/c7/nursery.c
--- a/c7/nursery.c
+++ b/c7/nursery.c
@@ -14,7 +14,7 @@
 #include "list.h"
 #include "nursery.h"
 #include "pages.h"
-
+#include "stmsync.h"
 
 void stm_major_collection(void)
 {
diff --git a/c7/stmsync.c b/c7/stmsync.c
new file mode 100644
--- /dev/null
+++ b/c7/stmsync.c
@@ -0,0 +1,53 @@
+#include "stmsync.h"
+#include "core.h"
+#include "reader_writer_lock.h"
+#include <assert.h>
+#include <string.h>
+
+
+/* a multi-reader, single-writer lock: transactions normally take a reader
+   lock, so don't conflict with each other; when we need to do a global GC,
+   we take a writer lock to "stop the world". */
+
+rwticket rw_shared_lock;        /* the "GIL" */
+
+void _stm_reset_shared_lock()
+{
+    assert(!rwticket_wrtrylock(&rw_shared_lock));
+    assert(!rwticket_wrunlock(&rw_shared_lock));
+
+    memset(&rw_shared_lock, 0, sizeof(rwticket));
+}
+
+void stm_start_shared_lock(void)
+{
+    rwticket_rdlock(&rw_shared_lock);
+}
+
+void stm_stop_shared_lock(void)
+{
+    rwticket_rdunlock(&rw_shared_lock);
+}
+
+void stm_stop_exclusive_lock(void)
+{
+    rwticket_wrunlock(&rw_shared_lock);
+}
+
+void stm_start_exclusive_lock(void)
+{
+    rwticket_wrlock(&rw_shared_lock);
+}
+
+void _stm_start_safe_point(void)
+{
+    assert(!_STM_TL->need_abort);
+    stm_stop_shared_lock();
+}
+
+void _stm_stop_safe_point(void)
+{
+    stm_start_shared_lock();
+    if (_STM_TL->need_abort)
+        stm_abort_transaction();
+}
diff --git a/c7/stmsync.h b/c7/stmsync.h
new file mode 100644
--- /dev/null
+++ b/c7/stmsync.h
@@ -0,0 +1,11 @@
+
+
+void stm_start_shared_lock(void);
+void stm_stop_shared_lock(void);
+void stm_stop_exclusive_lock(void);
+void stm_start_exclusive_lock(void);
+void _stm_start_safe_point(void);
+void _stm_stop_safe_point(void);
+void _stm_reset_shared_lock();
+
+
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -9,11 +9,13 @@
 header_files = [os.path.join(parent_dir, _n) for _n in
                 """core.h pagecopy.h list.h
                 reader_writer_lock.h
-                nursery.h pages.h""".split()]
+                nursery.h pages.h
+                stmsync.h""".split()]
 source_files = [os.path.join(parent_dir, _n) for _n in
                 """core.c pagecopy.c list.c
                 reader_writer_lock.c
-                nursery.c pages.c""".split()]
+                nursery.c pages.c
+                stmsync.c""".split()]
 
 _pycache_ = os.path.join(parent_dir, 'test', '__pycache__')
 if os.path.exists(_pycache_):
@@ -103,6 +105,7 @@
 #include "core.h"
 #include "pages.h"
 #include "nursery.h"
+#include "stmsync.h"
 
 struct myobj_s {
     struct object_s hdr;


More information about the pypy-commit mailing list