[pypy-commit] stmgc default: Uniformize the lock management
arigo
noreply at buildbot.pypy.org
Sun Apr 13 18:25:12 CEST 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r1152:3bfb23623e74
Date: 2014-04-12 12:38 +0200
http://bitbucket.org/pypy/stmgc/changeset/3bfb23623e74/
Log: Uniformize the lock management
diff --git a/c7/stm/atomic.h b/c7/stm/atomic.h
--- a/c7/stm/atomic.h
+++ b/c7/stm/atomic.h
@@ -36,4 +36,12 @@
#endif
+#define spinlock_acquire(lock) \
+ do { if (LIKELY(__sync_lock_test_and_set(&(lock), 1) == 0)) break; \
+ spin_loop(); } while (1)
+#define spinlock_release(lock) \
+ do { assert((lock) == 1); \
+ __sync_lock_release(&(lock)); } while (0)
+
+
#endif /* _STM_ATOMIC_H */
diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -14,12 +14,13 @@
#define EVENTUALLY(condition) \
{ \
if (!(condition)) { \
- while (!__sync_bool_compare_and_swap( \
- &pages_privatizing.by_segment, 0, -1)) \
- spin_loop(); \
+ int _i; \
+ for (_i = 1; _i <= NB_SEGMENTS; _i++) \
+ spinlock_acquire(lock_pages_privatizing[_i]); \
if (!(condition)) \
stm_fatalerror("fails: " #condition); \
- __sync_lock_release(&pages_privatizing.by_segment); \
+ for (_i = 1; _i <= NB_SEGMENTS; _i++) \
+ spinlock_release(lock_pages_privatizing[_i]); \
} \
}
#endif
diff --git a/c7/stm/gcpage.c b/c7/stm/gcpage.c
--- a/c7/stm/gcpage.c
+++ b/c7/stm/gcpage.c
@@ -90,8 +90,7 @@
}
/* uncommon case: need to initialize some more pages */
- while (__sync_lock_test_and_set(&lock_growth_large, 1) != 0)
- spin_loop();
+ spinlock_acquire(lock_growth_large);
if (addr + size > uninitialized_page_start) {
uintptr_t npages;
@@ -105,7 +104,7 @@
__sync_synchronize();
uninitialized_page_start += npages * 4096UL;
}
- __sync_lock_release(&lock_growth_large);
+ spinlock_release(lock_growth_large);
return addr;
}
diff --git a/c7/stm/largemalloc.c b/c7/stm/largemalloc.c
--- a/c7/stm/largemalloc.c
+++ b/c7/stm/largemalloc.c
@@ -116,14 +116,12 @@
static void lm_lock(void)
{
- while (UNLIKELY(__sync_lock_test_and_set(&lm.lock, 1) != 0))
- spin_loop();
+ spinlock_acquire(lm.lock);
}
static void lm_unlock(void)
{
- assert(lm.lock == 1);
- __sync_lock_release(&lm.lock);
+ spinlock_release(lm.lock);
}
diff --git a/c7/stm/pages.c b/c7/stm/pages.c
--- a/c7/stm/pages.c
+++ b/c7/stm/pages.c
@@ -115,10 +115,7 @@
}
#ifndef NDEBUG
- while (__sync_fetch_and_or(&pages_privatizing.by_segment, bitmask)
- & bitmask) {
- spin_loop();
- }
+ spinlock_acquire(lock_pages_privatizing[STM_SEGMENT->segment_num]);
#endif
/* add this thread's 'pages_privatized' bit */
@@ -137,7 +134,7 @@
pagecopy(new_page, stm_object_pages + pagenum * 4096UL);
#ifndef NDEBUG
- __sync_fetch_and_sub(&pages_privatizing.by_segment, bitmask);
+ spinlock_release(lock_pages_privatizing[STM_SEGMENT->segment_num]);
#endif
}
diff --git a/c7/stm/pages.h b/c7/stm/pages.h
--- a/c7/stm/pages.h
+++ b/c7/stm/pages.h
@@ -74,5 +74,5 @@
}
#ifndef NDEBUG
-static struct page_shared_s pages_privatizing = { 0 };
+static char lock_pages_privatizing[NB_SEGMENTS + 1] = { 0 };
#endif
More information about the pypy-commit
mailing list