Commit 91831575 authored by simonmar's avatar simonmar
Browse files

[project @ 2005-04-12 09:17:47 by simonmar]

The in_haskell sanity check should be per-Capability rather than global.

I just ran a Haskell program in 8 pthreads simultaneously :-)
parent 693550d9
...@@ -92,6 +92,9 @@ typedef struct StgRegTable_ { ...@@ -92,6 +92,9 @@ typedef struct StgRegTable_ {
#if defined(SMP) || defined(PAR) #if defined(SMP) || defined(PAR)
StgSparkPool rSparks; /* per-task spark pool */ StgSparkPool rSparks; /* per-task spark pool */
#endif #endif
StgWord rInHaskell; /* non-zero if we're in Haskell code */
// If this flag is set, we are running Haskell code. Used to detect
// uses of 'foreign import unsafe' that should be 'safe'.
} StgRegTable; } StgRegTable;
......
...@@ -177,11 +177,6 @@ int context_switch = 0; ...@@ -177,11 +177,6 @@ int context_switch = 0;
/* if this flag is set as well, give up execution */ /* if this flag is set as well, give up execution */
rtsBool interrupted = rtsFalse; rtsBool interrupted = rtsFalse;
/* If this flag is set, we are running Haskell code. Used to detect
* uses of 'foreign import unsafe' that should be 'safe'.
*/
static rtsBool in_haskell = rtsFalse;
/* Next thread ID to allocate. /* Next thread ID to allocate.
* Locks required: thread_id_mutex * Locks required: thread_id_mutex
*/ */
...@@ -482,7 +477,7 @@ schedule( StgMainThread *mainThread USED_WHEN_RTS_SUPPORTS_THREADS, ...@@ -482,7 +477,7 @@ schedule( StgMainThread *mainThread USED_WHEN_RTS_SUPPORTS_THREADS,
// Check whether we have re-entered the RTS from Haskell without // Check whether we have re-entered the RTS from Haskell without
// going via suspendThread()/resumeThread (i.e. a 'safe' foreign // going via suspendThread()/resumeThread (i.e. a 'safe' foreign
// call). // call).
if (in_haskell) { if (cap->r.rInHaskell) {
errorBelch("schedule: re-entered unsafely.\n" errorBelch("schedule: re-entered unsafely.\n"
" Perhaps a 'foreign import unsafe' should be 'safe'?"); " Perhaps a 'foreign import unsafe' should be 'safe'?");
stg_exit(1); stg_exit(1);
...@@ -671,7 +666,7 @@ run_thread: ...@@ -671,7 +666,7 @@ run_thread:
prev_what_next = t->what_next; prev_what_next = t->what_next;
errno = t->saved_errno; errno = t->saved_errno;
in_haskell = rtsTrue; cap->r.rInHaskell = rtsTrue;
switch (prev_what_next) { switch (prev_what_next) {
...@@ -699,7 +694,7 @@ run_thread: ...@@ -699,7 +694,7 @@ run_thread:
blackholes_need_checking = rtsTrue; blackholes_need_checking = rtsTrue;
} }
in_haskell = rtsFalse; cap->r.rInHaskell = rtsFalse;
// The TSO might have moved, eg. if it re-entered the RTS and a GC // The TSO might have moved, eg. if it re-entered the RTS and a GC
// happened. So find the new location: // happened. So find the new location:
...@@ -2131,6 +2126,7 @@ suspendThread( StgRegTable *reg ) ...@@ -2131,6 +2126,7 @@ suspendThread( StgRegTable *reg )
tok = cap->r.rCurrentTSO->id; tok = cap->r.rCurrentTSO->id;
/* Hand back capability */ /* Hand back capability */
cap->r.rInHaskell = rtsFalse;
releaseCapability(cap); releaseCapability(cap);
#if defined(RTS_SUPPORTS_THREADS) #if defined(RTS_SUPPORTS_THREADS)
...@@ -2140,7 +2136,6 @@ suspendThread( StgRegTable *reg ) ...@@ -2140,7 +2136,6 @@ suspendThread( StgRegTable *reg )
IF_DEBUG(scheduler, sched_belch("worker (token %d): leaving RTS", tok)); IF_DEBUG(scheduler, sched_belch("worker (token %d): leaving RTS", tok));
#endif #endif
in_haskell = rtsFalse;
RELEASE_LOCK(&sched_mutex); RELEASE_LOCK(&sched_mutex);
errno = saved_errno; errno = saved_errno;
...@@ -2188,7 +2183,7 @@ resumeThread( StgInt tok ) ...@@ -2188,7 +2183,7 @@ resumeThread( StgInt tok )
tso->why_blocked = NotBlocked; tso->why_blocked = NotBlocked;
cap->r.rCurrentTSO = tso; cap->r.rCurrentTSO = tso;
in_haskell = rtsTrue; cap->r.rInHaskell = rtsTrue;
RELEASE_LOCK(&sched_mutex); RELEASE_LOCK(&sched_mutex);
errno = saved_errno; errno = saved_errno;
return &cap->r; return &cap->r;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment