runtime_MCache_ReleaseAll (mcache);
+ /* As soon as we release this look, a GC could run. Since this
+ thread is no longer on the list, the GC will not find our M
+ structure, so it could get freed at any time. That means that
+ any code from here to thread exit must not assume that the m is
+ valid. */
+ m = NULL;
+
i = pthread_mutex_unlock (&__go_thread_ids_lock);
__go_assert (i == 0);
void
runtime_lock(Lock *l)
{
- if(m->locks < 0)
- runtime_throw("lock count");
- m->locks++;
+ if(m != nil) {
+ if(m->locks < 0)
+ runtime_throw("lock count");
+ m->locks++;
+ }
if(runtime_xadd(&l->key, 1) > 1) // someone else has it; wait
runtime_lock_full(l);
void
runtime_unlock(Lock *l)
{
- m->locks--;
- if(m->locks < 0)
- runtime_throw("lock count");
+ if(m != nil) {
+ m->locks--;
+ if(m->locks < 0)
+ runtime_throw("lock count");
+ }
if(runtime_xadd(&l->key, -1) > 0) // someone else is waiting
runtime_unlock_full(l);