summaryrefslogtreecommitdiff
path: root/libgo/runtime/thread.c
blob: 565121768b6df97a78833189fff86a537b438ea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}