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
acfd7b8d
Commit
acfd7b8d
authored
Mar 16, 2010
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
runtime: lock finalizer table accesses
R=r CC=golang-dev
https://golang.org/cl/462043
parent
ee9bc00d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
4 deletions
+18
-4
mfinal.c
src/pkg/runtime/mfinal.c
+18
-4
No files found.
src/pkg/runtime/mfinal.c
View file @
acfd7b8d
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
#include "runtime.h"
#include "runtime.h"
#include "malloc.h"
#include "malloc.h"
Lock
finlock
;
// Finalizer hash table. Direct hash, linear scan, at most 3/4 full.
// Finalizer hash table. Direct hash, linear scan, at most 3/4 full.
// Table size is power of 3 so that hash can be key % max.
// Table size is power of 3 so that hash can be key % max.
// Key[i] == (void*)-1 denotes free but formerly occupied entry
// Key[i] == (void*)-1 denotes free but formerly occupied entry
...
@@ -97,18 +99,24 @@ addfinalizer(void *p, void (*f)(void*), int32 nret)
...
@@ -97,18 +99,24 @@ addfinalizer(void *p, void (*f)(void*), int32 nret)
uint32
*
ref
;
uint32
*
ref
;
byte
*
base
;
byte
*
base
;
if
(
!
mlookup
(
p
,
&
base
,
nil
,
nil
,
&
ref
)
||
p
!=
base
)
lock
(
&
finlock
);
if
(
!
mlookup
(
p
,
&
base
,
nil
,
nil
,
&
ref
)
||
p
!=
base
)
{
unlock
(
&
finlock
);
throw
(
"addfinalizer on invalid pointer"
);
throw
(
"addfinalizer on invalid pointer"
);
}
if
(
f
==
nil
)
{
if
(
f
==
nil
)
{
if
(
*
ref
&
RefHasFinalizer
)
{
if
(
*
ref
&
RefHasFinalizer
)
{
getfinalizer
(
p
,
1
,
nil
);
lookfintab
(
&
fintab
,
p
,
1
,
nil
);
*
ref
&=
~
RefHasFinalizer
;
*
ref
&=
~
RefHasFinalizer
;
}
}
unlock
(
&
finlock
);
return
;
return
;
}
}
if
(
*
ref
&
RefHasFinalizer
)
if
(
*
ref
&
RefHasFinalizer
)
{
unlock
(
&
finlock
);
throw
(
"double finalizer"
);
throw
(
"double finalizer"
);
}
*
ref
|=
RefHasFinalizer
;
*
ref
|=
RefHasFinalizer
;
if
(
fintab
.
nkey
>=
fintab
.
max
/
2
+
fintab
.
max
/
4
)
{
if
(
fintab
.
nkey
>=
fintab
.
max
/
2
+
fintab
.
max
/
4
)
{
...
@@ -141,6 +149,7 @@ addfinalizer(void *p, void (*f)(void*), int32 nret)
...
@@ -141,6 +149,7 @@ addfinalizer(void *p, void (*f)(void*), int32 nret)
}
}
addfintab
(
&
fintab
,
p
,
f
,
nret
);
addfintab
(
&
fintab
,
p
,
f
,
nret
);
unlock
(
&
finlock
);
}
}
// get finalizer; if del, delete finalizer.
// get finalizer; if del, delete finalizer.
...
@@ -148,5 +157,10 @@ addfinalizer(void *p, void (*f)(void*), int32 nret)
...
@@ -148,5 +157,10 @@ addfinalizer(void *p, void (*f)(void*), int32 nret)
void
*
void
*
getfinalizer
(
void
*
p
,
bool
del
,
int32
*
nret
)
getfinalizer
(
void
*
p
,
bool
del
,
int32
*
nret
)
{
{
return
lookfintab
(
&
fintab
,
p
,
del
,
nret
);
void
*
f
;
lock
(
&
finlock
);
f
=
lookfintab
(
&
fintab
,
p
,
del
,
nret
);
unlock
(
&
finlock
);
return
f
;
}
}
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