Side by Side Diff

Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Keyboard Shortcuts

File
u :up to issue
m :publish + mail comments
M :edit review message
j / k :jump to file after / before current file
J / K :jump to next file with a comment after / before current file
Side-by-side diff
i :toggle intra-line diffs
e :expand all comments
c :collapse all comments
s :toggle showing all comments
n / p :next / previous diff chunk or comment
N / P :next / previous comment
<Up> / <Down> :next / previous line
<Enter> :respond to / edit current comment
d :mark current comment as done
Issue
u :up to list of issues
m :publish + mail comments
j / k :jump to patch after / before current patch
o / <Enter> :open current patch in side-by-side view
i :open current patch in unified diff view
Issue List
j / k :jump to issue after / before current issue
o / <Enter> :open current issue
# : close issue
Comment/message editing
<Ctrl> + s or <Ctrl> + Enter :save comment
<Esc> :cancel edit
Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(321)
Issues Repositories Search
Open Issues | Closed Issues | All Issues | Sign in with your Google Account to create issues and add comments

Side by Side Diff: src/pkg/runtime/plan9/thread.c

Issue 2273041: code review 2273041: Initial Plan9 runtime support for 386. (Closed)
Patch Set: code review 2273041: Initial Plan9 runtime support for 386. Created 15 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/runtime/plan9/signals.h ('k') | src/pkg/runtime/runtime.h » ('j') | no next file with comments »
('i') | ('e') | ('c') | ('s')
OLDNEW
(Empty)
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 #include "os.h"
7
8 int8 *goos = "plan9";
9
10 void
11 minit(void)
12 {
13 }
14
15 void
16 osinit(void)
17 {
18 }
19
20 void
21 initsig(int32 queue)
22 {
23 }
24
25 void
26 exit(int32)
27 {
28 exits(nil);
29 }
30
31 void
32 newosproc(M *m, G *g, void *stk, void (*fn)(void))
33 {
34 USED(m, g, stk, fn);
35 ········
36 m->tls[0] = m->id; // so 386 asm can find it
37 if(0){
38 printf("newosproc stk=%p m=%p g=%p fn=%p rfork=%p id=%d/%d ostk= %p\n",
39 stk, m, g, fn, rfork, m->id, m->tls[0], &m);
40 }········
41 ········
42 if (rfork(RFPROC | RFMEM, stk, m, g, fn) < 0 )
43 throw("newosproc: rfork failed");
44 }
45
46 // Blocking locks.
47
48 // Implement Locks, using semaphores.
49 // l->key is the number of threads who want the lock.
50 // In a race, one thread increments l->key from 0 to 1
51 // and the others increment it from >0 to >1. The thread
52 // who does the 0->1 increment gets the lock, and the
53 // others wait on the semaphore. When the 0->1 thread
54 // releases the lock by decrementing l->key, l->key will
55 // be >0, so it will increment the semaphore to wake up
56 // one of the others. This is the same algorithm used
57 // in Plan 9's user-level locks.
58
59 void
60 lock(Lock *l)
61 {
62 if(m->locks < 0)
63 throw("lock count");
64 m->locks++;
65
66 if(xadd(&l->key, 1) == 1)
67 return; // changed from 0 -> 1; we hold lock
68 // otherwise wait in kernel
69 while(plan9_semacquire(&l->sema, 1) < 0) {
70 /* interrupted; try again */
71 }
72 }
73
74 void
75 unlock(Lock *l)
76 {
77 m->locks--;
78 if(m->locks < 0)
79 throw("lock count");
80
81 if(xadd(&l->key, -1) == 0)
82 return; // changed from 1 -> 0: no contention
83 ········
84 plan9_semrelease(&l->sema, 1);
85 }
86
87
88 void·
89 destroylock(Lock *l)
90 {
91 // nothing
92 }
93
94 // User-level semaphore implementation:
95 // try to do the operations in user space on u,
96 // but when it's time to block, fall back on the kernel semaphore k.
97 // This is the same algorithm used in Plan 9.
98 void
99 usemacquire(Usema *s)
100 {
101 if((int32)xadd(&s->u, -1) < 0)
102 while(plan9_semacquire(&s->k, 1) < 0) {
103 /* interrupted; try again */
104 }
105 }
106
107 void
108 usemrelease(Usema *s)
109 {
110 if((int32)xadd(&s->u, 1) <= 0)
111 plan9_semrelease(&s->k, 1);
112 }
113
114
115 // Event notifications.
116 void
117 noteclear(Note *n)
118 {
119 n->wakeup = 0;
120 }
121
122 void
123 notesleep(Note *n)
124 {
125 while(!n->wakeup)
126 usemacquire(&n->sema);
127 }
128
129 void
130 notewakeup(Note *n)
131 {
132 n->wakeup = 1;
133 usemrelease(&n->sema);
134 }
135
OLDNEW
« no previous file with comments | « src/pkg/runtime/plan9/signals.h ('k') | src/pkg/runtime/runtime.h » ('j') | no next file with comments »
Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b

AltStyle によって変換されたページ (->オリジナル) /