summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2009-07-24 14:26:20 +0000
committerSimon Marlow <marlowsd@gmail.com>2009-07-24 14:26:20 +0000
commit2da67673279cf015ccc84270f6fd7935f64261a6 (patch)
treede71a6db993ba5c4e53fcc6cc29864bb9fa911dd /rts
parentb62f4e789fa4aea34ce6e857d512905054023417 (diff)
downloadhaskell-2da67673279cf015ccc84270f6fd7935f64261a6.tar.gz
Add atomic_inc()/atomic_dec(), and use them to replace gc_running_mutex
This also fixes a memory leak on Windows with -threaded, because we were calling initMutex(&gc_running_mutex) for each GC, which allocates memory.
Diffstat (limited to 'rts')
-rw-r--r--rts/sm/GC.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/rts/sm/GC.c b/rts/sm/GC.c
index cfe4c6bdb5..74880064e4 100644
--- a/rts/sm/GC.c
+++ b/rts/sm/GC.c
@@ -147,8 +147,8 @@ static void resize_generations (void);
static void resize_nursery (void);
static void start_gc_threads (void);
static void scavenge_until_all_done (void);
-static nat inc_running (void);
-static nat dec_running (void);
+static StgWord inc_running (void);
+static StgWord dec_running (void);
static void wakeup_gc_threads (nat n_threads, nat me);
static void shutdown_gc_threads (nat n_threads, nat me);
@@ -941,32 +941,22 @@ initGcThreads (void)
Start GC threads
------------------------------------------------------------------------- */
-static nat gc_running_threads;
+static volatile StgWord gc_running_threads;
-#if defined(THREADED_RTS)
-static Mutex gc_running_mutex;
-#endif
-
-static nat
+static StgWord
inc_running (void)
{
- nat n_running;
- ACQUIRE_LOCK(&gc_running_mutex);
- n_running = ++gc_running_threads;
- RELEASE_LOCK(&gc_running_mutex);
- ASSERT(n_running <= n_gc_threads);
- return n_running;
+ StgWord new;
+ new = atomic_inc(&gc_running_threads);
+ ASSERT(new <= n_gc_threads);
+ return new;
}
-static nat
+static StgWord
dec_running (void)
{
- nat n_running;
- ACQUIRE_LOCK(&gc_running_mutex);
- ASSERT(n_gc_threads != 0);
- n_running = --gc_running_threads;
- RELEASE_LOCK(&gc_running_mutex);
- return n_running;
+ ASSERT(gc_running_threads != 0);
+ return atomic_dec(&gc_running_threads);
}
static rtsBool
@@ -1142,7 +1132,6 @@ start_gc_threads (void)
{
#if defined(THREADED_RTS)
gc_running_threads = 0;
- initMutex(&gc_running_mutex);
#endif
}