aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/runtime/thread.c')
-rw-r--r--libgo/runtime/thread.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/libgo/runtime/thread.c b/libgo/runtime/thread.c
new file mode 100644
index 0000000..5651217
--- /dev/null
+++ b/libgo/runtime/thread.c
@@ -0,0 +1,38 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "runtime.h"
+
+void
+runtime_initlock(Lock *l)
+{
+ if(pthread_mutex_init(&l->mutex, NULL) != 0)
+ runtime_throw("pthread_mutex_init failed");
+}
+
+void
+runtime_lock(Lock *l)
+{
+ if(pthread_mutex_lock(&l->mutex) != 0)
+ runtime_throw("lock failed");
+}
+
+void
+runtime_unlock(Lock *l)
+{
+ if(pthread_mutex_unlock(&l->mutex) != 0)
+ runtime_throw("unlock failed");
+}
+
+void
+runtime_destroylock(Lock *l)
+{
+ pthread_mutex_destroy(&l->mutex);
+}
+
+bool
+runtime_trylock(Lock *l)
+{
+ return pthread_mutex_trylock(&l->mutex) == 0;
+}