Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
53e69e1d
Commit
53e69e1d
authored
Jan 27, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
various race conditions.
R=r DELTA=43 (29 added, 5 deleted, 9 changed) OCL=23608 CL=23611
parent
47ab1c1e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
14 deletions
+38
-14
proc.c
src/runtime/proc.c
+5
-1
rt1_amd64_darwin.c
src/runtime/rt1_amd64_darwin.c
+7
-1
rt1_amd64_linux.c
src/runtime/rt1_amd64_linux.c
+26
-12
No files found.
src/runtime/proc.c
View file @
53e69e1d
...
...
@@ -397,7 +397,7 @@ nextgandunlock(void)
throw
(
"all goroutines are asleep - deadlock!"
);
m
->
nextg
=
nil
;
noteclear
(
&
m
->
havenextg
);
if
(
sched
.
waitstop
)
{
if
(
sched
.
waitstop
&&
sched
.
mcpu
<=
sched
.
mcpumax
)
{
sched
.
waitstop
=
0
;
notewakeup
(
&
sched
.
stopped
);
}
...
...
@@ -590,6 +590,10 @@ sys·entersyscall(uint64 callerpc, int64 trap)
sched
.
msyscall
++
;
if
(
sched
.
gwait
!=
0
)
matchmg
();
if
(
sched
.
waitstop
&&
sched
.
mcpu
<=
sched
.
mcpumax
)
{
sched
.
waitstop
=
0
;
notewakeup
(
&
sched
.
stopped
);
}
unlock
(
&
sched
);
// leave SP around for gc; poison PC to make sure it's not used
g
->
sched
.
SP
=
(
byte
*
)
&
callerpc
;
...
...
src/runtime/rt1_amd64_darwin.c
View file @
53e69e1d
...
...
@@ -277,19 +277,25 @@ xadd(uint32 volatile *val, int32 delta)
void
lock
(
Lock
*
l
)
{
if
(
m
->
locks
<
0
)
throw
(
"lock count"
);
m
->
locks
++
;
// Allocate semaphore if needed.
if
(
l
->
sema
==
0
)
initsema
(
&
l
->
sema
);
if
(
xadd
(
&
l
->
key
,
1
)
>
1
)
// someone else has it; wait
mach_semacquire
(
l
->
sema
);
m
->
locks
++
;
}
void
unlock
(
Lock
*
l
)
{
m
->
locks
--
;
if
(
m
->
locks
<
0
)
throw
(
"lock count"
);
if
(
xadd
(
&
l
->
key
,
-
1
)
>
0
)
// someone else is waiting
mach_semrelease
(
l
->
sema
);
}
...
...
src/runtime/rt1_amd64_linux.c
View file @
53e69e1d
...
...
@@ -301,13 +301,11 @@ futexwakeup(uint32 *addr)
// else return 0;
// but atomically.
void
lock
(
Lock
*
l
)
static
void
futex
lock
(
Lock
*
l
)
{
uint32
v
;
m
->
locks
++
;
again:
v
=
l
->
key
;
if
((
v
&
1
)
==
0
){
...
...
@@ -346,13 +344,11 @@ again:
goto
again
;
}
void
unlock
(
Lock
*
l
)
static
void
futex
unlock
(
Lock
*
l
)
{
uint32
v
;
m
->
locks
--
;
// Atomically get value and clear lock bit.
again:
v
=
l
->
key
;
...
...
@@ -366,6 +362,24 @@ again:
futexwakeup
(
&
l
->
key
);
}
void
lock
(
Lock
*
l
)
{
if
(
m
->
locks
<
0
)
throw
(
"lock count"
);
m
->
locks
++
;
futexlock
(
l
);
}
void
unlock
(
Lock
*
l
)
{
m
->
locks
--
;
if
(
m
->
locks
<
0
)
throw
(
"lock count"
);
futexunlock
(
l
);
}
// One-time notifications.
//
...
...
@@ -383,20 +397,20 @@ void
noteclear
(
Note
*
n
)
{
n
->
lock
.
key
=
0
;
// memset(n, 0, sizeof *n)
lock
(
&
n
->
lock
);
futex
lock
(
&
n
->
lock
);
}
void
notewakeup
(
Note
*
n
)
{
unlock
(
&
n
->
lock
);
futex
unlock
(
&
n
->
lock
);
}
void
notesleep
(
Note
*
n
)
{
lock
(
&
n
->
lock
);
unlock
(
&
n
->
lock
);
// Let other sleepers find out too.
futex
lock
(
&
n
->
lock
);
futex
unlock
(
&
n
->
lock
);
// Let other sleepers find out too.
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment