diff options
Diffstat (limited to 'libgo/runtime/go-caller.c')
-rw-r--r-- | libgo/runtime/go-caller.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libgo/runtime/go-caller.c b/libgo/runtime/go-caller.c index a35d8d73f44..360bae69594 100644 --- a/libgo/runtime/go-caller.c +++ b/libgo/runtime/go-caller.c @@ -74,7 +74,7 @@ static void *back_state; /* A lock to control creating back_state. */ -static Lock back_state_lock; +static uint32 back_state_lock; /* The program arguments. */ @@ -85,7 +85,15 @@ extern Slice runtime_get_args(void); struct backtrace_state * __go_get_backtrace_state () { - runtime_lock (&back_state_lock); + uint32 set; + + /* We may not have a g here, so we can't use runtime_lock. */ + set = 0; + while (!__atomic_compare_exchange_n (&back_state_lock, &set, 1, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) + { + runtime_osyield (); + set = 0; + } if (back_state == NULL) { Slice args; @@ -113,7 +121,7 @@ __go_get_backtrace_state () back_state = backtrace_create_state (filename, 1, error_callback, NULL); } - runtime_unlock (&back_state_lock); + __atomic_store_n (&back_state_lock, 0, __ATOMIC_RELEASE); return back_state; } |