Skip to content

Commit 69ecf36

Browse files
committed
---
yaml --- r: 150238 b: refs/heads/try2 c: 53e451f h: refs/heads/master v: v3
1 parent 204aaf4 commit 69ecf36

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 3572a30e7a4fec7f0bb0957fc72588757111f14e
8+
refs/heads/try2: 53e451f4106c0eb6614b4c534744e81c6100cbbd
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libsync/sync/one.rs renamed to branches/try2/src/libsync/one.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
1616
use std::int;
1717
use std::sync::atomics;
18-
use sync::mutex::{StaticMutex, MUTEX_INIT};
18+
19+
use mutex::{StaticMutex, MUTEX_INIT};
1920

2021
/// A type which can be used to run a one-time global initialization. This type
2122
/// is *unsafe* to use because it is built on top of the `Mutex` in this module.
@@ -62,7 +63,7 @@ impl Once {
6263
///
6364
/// When this function returns, it is guaranteed that some initialization
6465
/// has run and completed (it may not be the closure specified).
65-
pub fn doit(&mut self, f: ||) {
66+
pub fn doit(&self, f: ||) {
6667
// Implementation-wise, this would seem like a fairly trivial primitive.
6768
// The stickler part is where our mutexes currently require an
6869
// allocation, and usage of a `Once` should't leak this allocation.
@@ -101,14 +102,13 @@ impl Once {
101102
// If the count is negative, then someone else finished the job,
102103
// otherwise we run the job and record how many people will try to grab
103104
// this lock
104-
{
105-
let _guard = self.mutex.lock();
106-
if self.cnt.load(atomics::SeqCst) > 0 {
107-
f();
108-
let prev = self.cnt.swap(int::MIN, atomics::SeqCst);
109-
self.lock_cnt.store(prev, atomics::SeqCst);
110-
}
105+
let guard = self.mutex.lock();
106+
if self.cnt.load(atomics::SeqCst) > 0 {
107+
f();
108+
let prev = self.cnt.swap(int::MIN, atomics::SeqCst);
109+
self.lock_cnt.store(prev, atomics::SeqCst);
111110
}
111+
drop(guard);
112112

113113
// Last one out cleans up after everyone else, no leaks!
114114
if self.lock_cnt.fetch_add(-1, atomics::SeqCst) == 1 {

0 commit comments

Comments
 (0)