1. Pypy
  2. Untitled project
  3. stmgc

Commits

Remi Meier  committed 8207763

move the global lock to an extra file "stmsync"

  • Participants
  • Parent commits 4fb6332
  • Branches c7

Comments (0)

Files changed (6)

File c7/core.c

View file
 #include "reader_writer_lock.h"
 #include "nursery.h"
 #include "pages.h"
+#include "stmsync.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_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 *)
     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);
 
 
 
-
-
-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 */
 
 
 
-
-
-
-
 void _stm_write_slowpath(object_t *obj)
 {
     uintptr_t pagenum = ((uintptr_t)obj) / 4096;
 
 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));
 
 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;

File c7/core.h

View file
 #include <stddef.h>
 #include <stdint.h>
 #include <stdbool.h>
-
+#include <assert.h>
 
 #define NB_PAGES            (256*256)    // 256MB
 #define NB_THREADS          2
     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);
 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();

File c7/nursery.c

View file
 #include "list.h"
 #include "nursery.h"
 #include "pages.h"
-
+#include "stmsync.h"
 
 void stm_major_collection(void)
 {

File c7/stmsync.c

View file
+#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();
+}

File c7/stmsync.h

View file
+
+
+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();
+
+

File c7/test/support.py

View file
 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_):
 #include "core.h"
 #include "pages.h"
 #include "nursery.h"
+#include "stmsync.h"
 
 struct myobj_s {
     struct object_s hdr;