Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
a621a7ef
Commit
a621a7ef
authored
Aug 13, 2010
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete pkg/once
R=rsc CC=golang-dev
https://golang.org/cl/1995041
parent
7886318c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
0 additions
and
102 deletions
+0
-102
src/pkg/Makefile
src/pkg/Makefile
+0
-1
src/pkg/once/Makefile
src/pkg/once/Makefile
+0
-11
src/pkg/once/once.go
src/pkg/once/once.go
+0
-59
src/pkg/once/once_test.go
src/pkg/once/once_test.go
+0
-30
test/garbage/parser.go
test/garbage/parser.go
+0
-1
No files found.
src/pkg/Makefile
View file @
a621a7ef
...
...
@@ -100,7 +100,6 @@ DIRS=\
net/textproto
\
netchan
\
nntp
\
once
\
os
\
os/signal
\
patch
\
...
...
src/pkg/once/Makefile
deleted
100644 → 0
View file @
7886318c
# Copyright 2009 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
../../Make.$(GOARCH)
TARG
=
once
GOFILES
=
\
once.go
\
include
../../Make.pkg
src/pkg/once/once.go
deleted
100644 → 0
View file @
7886318c
// Copyright 2009 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.
// This package provides a single function, Do, to run a function
// exactly once, usually used as part of initialization.
package
once
import
"sync"
type
job
struct
{
done
bool
sync
.
Mutex
// should probably be sync.Notification or some such
}
var
jobs
=
make
(
map
[
func
()]
*
job
)
var
joblock
sync
.
Mutex
// Do is the the only exported piece of the package.
// For one-time initialization that is not done during init,
// wrap the initialization in a niladic function f() and call
// Do(f)
// If multiple processes call Do(f) simultaneously
// with the same f argument, only one will call f, and the
// others will block until f finishes running.
//
// Since a func() expression typically evaluates to a differerent
// function value each time it is evaluated, it is incorrect to
// pass such values to Do. For example,
// func f(x int) {
// Do(func() { fmt.Println(x) })
// }
// behaves the same as
// func f(x int) {
// fmt.Println(x)
// }
// because the func() expression in the first creates a new
// func each time f runs, and each of those funcs is run once.
func
Do
(
f
func
())
{
joblock
.
Lock
()
j
:=
jobs
[
f
]
if
j
==
nil
{
// run it
j
=
new
(
job
)
j
.
Lock
()
jobs
[
f
]
=
j
joblock
.
Unlock
()
f
()
j
.
done
=
true
j
.
Unlock
()
}
else
{
// wait for it
joblock
.
Unlock
()
if
j
.
done
!=
true
{
j
.
Lock
()
j
.
Unlock
()
}
}
}
src/pkg/once/once_test.go
deleted
100644 → 0
View file @
7886318c
// Copyright 2009 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.
package
once_test
import
(
"once"
"testing"
)
var
ncall
int
func
call
()
{
ncall
++
}
func
TestDo
(
t
*
testing
.
T
)
{
ncall
=
0
once
.
Do
(
call
)
if
ncall
!=
1
{
t
.
Fatalf
(
"once.Do(call) didn't call(): ncall=%d"
,
ncall
)
}
once
.
Do
(
call
)
if
ncall
!=
1
{
t
.
Fatalf
(
"second once.Do(call) did call(): ncall=%d"
,
ncall
)
}
once
.
Do
(
call
)
if
ncall
!=
1
{
t
.
Fatalf
(
"third once.Do(call) did call(): ncall=%d"
,
ncall
)
}
}
test/garbage/parser.go
View file @
a621a7ef
...
...
@@ -185,7 +185,6 @@ var packages = []string{
"mime"
,
"net"
,
"nntp"
,
"once"
,
"os"
,
"os/signal"
,
"patch"
,
...
...
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