1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
8 runtime_initlock(Lock *l)
11 if(sem_init(&l->sem, 0, 0) != 0)
12 runtime_throw("sem_init failed");
16 runtime_xadd(uint32 volatile *val, int32 delta)
23 if(runtime_cas(val, oval, nval))
28 // noinline so that runtime_lock doesn't have to split the stack.
29 static void runtime_lock_full(Lock *l) __attribute__ ((noinline));
32 runtime_lock_full(Lock *l)
34 if(sem_wait(&l->sem) != 0)
35 runtime_throw("sem_wait failed");
42 runtime_throw("lock count");
45 if(runtime_xadd(&l->key, 1) > 1) // someone else has it; wait
49 static void runtime_unlock_full(Lock *l) __attribute__ ((noinline));
52 runtime_unlock_full(Lock *l)
54 if(sem_post(&l->sem) != 0)
55 runtime_throw("sem_post failed");
59 runtime_unlock(Lock *l)
63 runtime_throw("lock count");
65 if(runtime_xadd(&l->key, -1) > 0) // someone else is waiting
66 runtime_unlock_full(l);
70 runtime_destroylock(Lock *l)