Skip to content

Commit 5f093a2

Browse files
committed
---
yaml --- r: 147807 b: refs/heads/try2 c: c22fed9 h: refs/heads/master i: 147805: be424ce 147803: fc21c0e 147799: d0004b8 147791: aa286c2 147775: a5a6c9b v: v3
1 parent fda6e7e commit 5f093a2

File tree

8 files changed

+42
-66
lines changed

8 files changed

+42
-66
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: f3370295b738c8b4c80fa8fc8449c0c3545b1b35
8+
refs/heads/try2: c22fed9424a907beab53f6c6cd54afeff039f1b3
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libnative/io/net.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,14 @@ pub fn init() {
164164
}
165165

166166
unsafe {
167-
use std::unstable::mutex::{Mutex, MUTEX_INIT};
168-
static mut LOCK: Mutex = MUTEX_INIT;
169-
static mut INITIALIZED: bool = false;
170-
if INITIALIZED { return }
171-
LOCK.lock();
172-
if !INITIALIZED {
167+
use std::unstable::mutex::{Once, ONCE_INIT};
168+
static mut INIT: Once = ONCE_INIT;
169+
INIT.doit(|| {
173170
let mut data: WSADATA = intrinsics::init();
174171
let ret = WSAStartup(0x202, // version 2.2
175172
&mut data);
176173
assert_eq!(ret, 0);
177-
INITIALIZED = true;
178-
}
179-
LOCK.unlock();
174+
});
180175
}
181176
}
182177

branches/try2/src/librustc/back/link.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,8 @@ pub mod write {
310310
}
311311

312312
unsafe fn configure_llvm(sess: Session) {
313-
use std::unstable::mutex::{MUTEX_INIT, Mutex};
314-
static mut LOCK: Mutex = MUTEX_INIT;
315-
static mut CONFIGURED: bool = false;
313+
use std::unstable::mutex::{Once, ONCE_INIT};
314+
static mut INIT: Once = ONCE_INIT;
316315

317316
// Copy what clan does by turning on loop vectorization at O2 and
318317
// slp vectorization at O3
@@ -341,8 +340,7 @@ pub mod write {
341340
add(*arg);
342341
}
343342

344-
LOCK.lock();
345-
if !CONFIGURED {
343+
INIT.doit(|| {
346344
llvm::LLVMInitializePasses();
347345

348346
// Only initialize the platforms supported by Rust here, because
@@ -369,9 +367,7 @@ pub mod write {
369367

370368
llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int,
371369
llvm_args.as_ptr());
372-
CONFIGURED = true;
373-
}
374-
LOCK.unlock();
370+
});
375371
}
376372

377373
unsafe fn populate_llvm_passes(fpm: lib::llvm::PassManagerRef,

branches/try2/src/librustc/lib/llvm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,15 +1455,16 @@ pub mod llvm {
14551455
BufferName: *c_char)
14561456
-> MemoryBufferRef;
14571457

1458+
pub fn LLVMIsMultithreaded() -> Bool;
1459+
pub fn LLVMStartMultithreaded() -> Bool;
1460+
14581461
/** Returns a string describing the last error caused by an LLVMRust*
14591462
call. */
14601463
pub fn LLVMRustGetLastError() -> *c_char;
14611464

14621465
/// Print the pass timings since static dtors aren't picking them up.
14631466
pub fn LLVMRustPrintPassTimings();
14641467

1465-
pub fn LLVMRustStartMultithreading() -> bool;
1466-
14671468
pub fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
14681469

14691470
pub fn LLVMStructSetBody(StructTy: TypeRef,

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,8 +3189,21 @@ pub fn trans_crate(sess: session::Session,
31893189
analysis: &CrateAnalysis,
31903190
output: &Path) -> CrateTranslation {
31913191
// Before we touch LLVM, make sure that multithreading is enabled.
3192-
if unsafe { !llvm::LLVMRustStartMultithreading() } {
3193-
sess.bug("couldn't enable multi-threaded LLVM");
3192+
unsafe {
3193+
use std::unstable::mutex::{Once, ONCE_INIT};
3194+
static mut INIT: Once = ONCE_INIT;
3195+
static mut POISONED: bool = false;
3196+
INIT.doit(|| {
3197+
if llvm::LLVMStartMultithreaded() != 1 {
3198+
// use an extra bool to make sure that all future usage of LLVM
3199+
// cannot proceed despite the Once not running more than once.
3200+
POISONED = true;
3201+
}
3202+
});
3203+
3204+
if POISONED {
3205+
sess.bug("couldn't enable multi-threaded LLVM");
3206+
}
31943207
}
31953208

31963209
let mut symbol_hasher = Sha256::new();

branches/try2/src/libstd/rt/local_ptr.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,30 +160,20 @@ pub mod native {
160160
use option::{Option, Some, None};
161161
use ptr;
162162
use tls = rt::thread_local_storage;
163-
use unstable::mutex::{Mutex, MUTEX_INIT};
164163

165-
static mut LOCK: Mutex = MUTEX_INIT;
166-
static mut INITIALIZED: bool = false;
167164
static mut RT_TLS_KEY: tls::Key = -1;
168165

169166
/// Initialize the TLS key. Other ops will fail if this isn't executed
170167
/// first.
171168
pub fn init() {
172169
unsafe {
173-
LOCK.lock();
174-
if !INITIALIZED {
175-
tls::create(&mut RT_TLS_KEY);
176-
INITIALIZED = true;
177-
}
178-
LOCK.unlock();
170+
tls::create(&mut RT_TLS_KEY);
179171
}
180172
}
181173

182174
pub unsafe fn cleanup() {
183-
rtassert!(INITIALIZED);
175+
rtassert!(RT_TLS_KEY != -1);
184176
tls::destroy(RT_TLS_KEY);
185-
LOCK.destroy();
186-
INITIALIZED = false;
187177
}
188178

189179
/// Give a pointer to thread-local storage.

branches/try2/src/libstd/unstable/mutex.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
4848
#[allow(non_camel_case_types)];
4949

50+
use int;
5051
use libc::c_void;
5152
use sync::atomics;
5253

@@ -339,15 +340,15 @@ mod imp {
339340
/// ```
340341
pub struct Once {
341342
priv mutex: Mutex,
342-
priv cnt: AtomicInt,
343-
priv lock_cnt: AtomicInt,
343+
priv cnt: atomics::AtomicInt,
344+
priv lock_cnt: atomics::AtomicInt,
344345
}
345346

346347
/// Initialization value for static `Once` values.
347348
pub static ONCE_INIT: Once = Once {
348349
mutex: MUTEX_INIT,
349-
cnt: INIT_ATOMIC_INT,
350-
lock_cnt: INIT_ATOMIC_INT,
350+
cnt: atomics::INIT_ATOMIC_INT,
351+
lock_cnt: atomics::INIT_ATOMIC_INT,
351352
};
352353

353354
impl Once {
@@ -388,34 +389,36 @@ impl Once {
388389
// calling `doit` will return immediately before the initialization has
389390
// completed.
390391

391-
let prev = self.cnt.fetch_add(1, SeqCst);
392+
let prev = self.cnt.fetch_add(1, atomics::SeqCst);
392393
if prev < 0 {
393394
// Make sure we never overflow, we'll never have int::min_value
394395
// simultaneous calls to `doit` to make this value go back to 0
395-
self.cnt.store(int::min_value, SeqCst);
396+
self.cnt.store(int::min_value, atomics::SeqCst);
396397
return
397398
}
398399

399400
// If the count is negative, then someone else finished the job,
400401
// otherwise we run the job and record how many people will try to grab
401402
// this lock
402403
unsafe { self.mutex.lock() }
403-
if self.cnt.load(SeqCst) > 0 {
404+
if self.cnt.load(atomics::SeqCst) > 0 {
404405
f();
405-
let prev = self.cnt.swap(int::min_value, SeqCst);
406-
self.lock_cnt.store(prev, SeqCst);
406+
let prev = self.cnt.swap(int::min_value, atomics::SeqCst);
407+
self.lock_cnt.store(prev, atomics::SeqCst);
407408
}
408409
unsafe { self.mutex.unlock() }
409410

410411
// Last one out cleans up after everyone else, no leaks!
411-
if self.lock_cnt.fetch_add(-1, SeqCst) == 1 {
412+
if self.lock_cnt.fetch_add(-1, atomics::SeqCst) == 1 {
412413
unsafe { self.mutex.destroy() }
413414
}
414415
}
415416
}
416417

417418
#[cfg(test)]
418419
mod test {
420+
use prelude::*;
421+
419422
use rt::thread::Thread;
420423
use super::{ONCE_INIT, Once, Mutex, MUTEX_INIT};
421424
use task;

branches/try2/src/rustllvm/RustWrapper.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,28 +149,6 @@ extern "C" LLVMValueRef LLVMInlineAsm(LLVMTypeRef Ty,
149149
IsAlignStack, (InlineAsm::AsmDialect) Dialect));
150150
}
151151

152-
/**
153-
* This function is intended to be a threadsafe interface into enabling a
154-
* multithreaded LLVM. This is invoked at the start of the translation phase of
155-
* compilation to ensure that LLVM is ready.
156-
*
157-
* All of trans properly isolates LLVM with the use of a different
158-
* LLVMContextRef per task, thus allowing parallel compilation of different
159-
* crates in the same process. At the time of this writing, the use case for
160-
* this is unit tests for rusti, but there are possible other applications.
161-
*/
162-
extern "C" bool LLVMRustStartMultithreading() {
163-
static Mutex lock;
164-
bool ret = true;
165-
assert(lock.acquire());
166-
if (!LLVMIsMultithreaded()) {
167-
ret = LLVMStartMultithreaded();
168-
}
169-
assert(lock.release());
170-
return ret;
171-
}
172-
173-
174152
typedef DIBuilder* DIBuilderRef;
175153

176154
template<typename DIT>

0 commit comments

Comments
 (0)