OSDN Git Service

Add Go frontend, libgo library, and Go testsuite.
[pf3gnuchains/gcc-fork.git] / libgo / runtime / thread.c
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.
4
5 #include "runtime.h"
6
7 void
8 runtime_initlock(Lock *l)
9 {
10         if(pthread_mutex_init(&l->mutex, NULL) != 0)
11                 runtime_throw("pthread_mutex_init failed");
12 }
13
14 void
15 runtime_lock(Lock *l)
16 {
17         if(pthread_mutex_lock(&l->mutex) != 0)
18                 runtime_throw("lock failed");
19 }
20
21 void
22 runtime_unlock(Lock *l)
23 {
24         if(pthread_mutex_unlock(&l->mutex) != 0)
25                 runtime_throw("unlock failed");
26 }
27
28 void
29 runtime_destroylock(Lock *l)
30 {
31         pthread_mutex_destroy(&l->mutex);
32 }
33
34 bool
35 runtime_trylock(Lock *l)
36 {
37         return pthread_mutex_trylock(&l->mutex) == 0;
38 }