summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/embedded/thread.c
blob: 49b764b6d9d3822530ad95aee07084eee03a78cb (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// 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"

int8 *goos = "embedded";

void
minit(void)
{
}

void
osinit(void)
{
}

void
initsig(void)
{
}

void
exit(int32)
{
	for(;;);
}

// single processor, no interrupts,
// so no need for real concurrency or atomicity

void
newosproc(M *m, G *g, void *stk, void (*fn)(void))
{
	USED(m, g, stk, fn);
	throw("newosproc");
}

void
lock(Lock *l)
{
	if(m->locks < 0)
		throw("lock count");
	m->locks++;
	if(l->key != 0)
		throw("deadlock");
	l->key = 1;
}

void
unlock(Lock *l)
{
	m->locks--;
	if(m->locks < 0)
		throw("lock count");
	if(l->key != 1)
		throw("unlock of unlocked lock");
	l->key = 0;
}

void
noteclear(Note *n)
{
	n->lock.key = 0;
}

void
notewakeup(Note *n)
{
	n->lock.key = 1;
}

void
notesleep(Note *n)
{
	if(n->lock.key != 1)
		throw("notesleep");
}