This repository was archived by the owner on Feb 5, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +16
-26
lines changed Expand file tree Collapse file tree 5 files changed +16
-26
lines changed Original file line number Diff line number Diff line change 15
15
#define LLVM_SUPPORT_MUTEX_H
16
16
17
17
#include " llvm/Support/Compiler.h"
18
- #include " llvm/Support/Threading.h"
19
18
#include < cassert>
20
19
21
20
namespace llvm
22
21
{
22
+ // Forward declare.
23
+ bool llvm_is_multithreaded ();
24
+
23
25
namespace sys
24
26
{
25
27
// / @brief Platform agnostic Mutex class.
Original file line number Diff line number Diff line change 14
14
#ifndef LLVM_SUPPORT_THREADING_H
15
15
#define LLVM_SUPPORT_THREADING_H
16
16
17
+ #include " llvm/Support/Mutex.h"
18
+
17
19
namespace llvm {
20
+ // / llvm_get_global_lock - returns the llvm global lock object.
21
+ sys::Mutex& llvm_get_global_lock ();
22
+
18
23
// / llvm_start_multithreaded - Allocate and initialize structures needed to
19
24
// / make LLVM safe for multithreading. The return value indicates whether
20
25
// / multithreaded initialization succeeded. LLVM will still be operational
@@ -33,14 +38,6 @@ namespace llvm {
33
38
// / mode or not.
34
39
bool llvm_is_multithreaded ();
35
40
36
- // / acquire_global_lock - Acquire the global lock. This is a no-op if called
37
- // / before llvm_start_multithreaded().
38
- void llvm_acquire_global_lock ();
39
-
40
- // / release_global_lock - Release the global lock. This is a no-op if called
41
- // / before llvm_start_multithreaded().
42
- void llvm_release_global_lock ();
43
-
44
41
// / llvm_execute_on_thread - Execute the given \p UserFn on a separate
45
42
// / thread, passing it the provided \p UserData.
46
43
// /
Original file line number Diff line number Diff line change 14
14
#include " llvm/Support/ManagedStatic.h"
15
15
#include " llvm/Config/config.h"
16
16
#include " llvm/Support/Atomic.h"
17
+ #include " llvm/Support/MutexGuard.h"
17
18
#include < cassert>
18
19
using namespace llvm ;
19
20
@@ -23,7 +24,7 @@ void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(),
23
24
void (*Deleter)(void *)) const {
24
25
assert (Creator);
25
26
if (llvm_is_multithreaded ()) {
26
- llvm_acquire_global_lock ( );
27
+ llvm::MutexGuard Lock ( llvm::llvm_get_global_lock () );
27
28
28
29
if (!Ptr) {
29
30
void * tmp = Creator ();
@@ -43,8 +44,6 @@ void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(),
43
44
Next = StaticList;
44
45
StaticList = this ;
45
46
}
46
-
47
- llvm_release_global_lock ();
48
47
} else {
49
48
assert (!Ptr && !DeleterFn && !Next &&
50
49
" Partially initialized ManagedStatic!?" );
Original file line number Diff line number Diff line change @@ -21,13 +21,15 @@ using namespace llvm;
21
21
22
22
static bool multithreaded_mode = false ;
23
23
24
- static sys::Mutex* global_lock = nullptr ;
24
+ sys::Mutex& llvm::llvm_get_global_lock () {
25
+ static sys::Mutex global_lock;
26
+ return global_lock;
27
+ }
25
28
26
29
bool llvm::llvm_start_multithreaded () {
27
30
#if LLVM_ENABLE_THREADS != 0
28
31
assert (!multithreaded_mode && " Already multithreaded!" );
29
32
multithreaded_mode = true ;
30
- global_lock = new sys::Mutex (true );
31
33
32
34
// We fence here to ensure that all initialization is complete BEFORE we
33
35
// return from llvm_start_multithreaded().
@@ -47,22 +49,13 @@ void llvm::llvm_stop_multithreaded() {
47
49
sys::MemoryFence ();
48
50
49
51
multithreaded_mode = false ;
50
- delete global_lock;
51
52
#endif
52
53
}
53
54
54
55
bool llvm::llvm_is_multithreaded () {
55
56
return multithreaded_mode;
56
57
}
57
58
58
- void llvm::llvm_acquire_global_lock () {
59
- if (multithreaded_mode) global_lock->acquire ();
60
- }
61
-
62
- void llvm::llvm_release_global_lock () {
63
- if (multithreaded_mode) global_lock->release ();
64
- }
65
-
66
59
#if LLVM_ENABLE_THREADS != 0 && defined(HAVE_PTHREAD_H)
67
60
#include < pthread.h>
68
61
Original file line number Diff line number Diff line change 18
18
#include " llvm/Support/FileSystem.h"
19
19
#include " llvm/Support/Format.h"
20
20
#include " llvm/Support/ManagedStatic.h"
21
- #include " llvm/Support/Mutex .h"
21
+ #include " llvm/support/MutexGuard .h"
22
22
#include " llvm/Support/Process.h"
23
23
#include " llvm/Support/raw_ostream.h"
24
24
using namespace llvm ;
@@ -84,14 +84,13 @@ static TimerGroup *getDefaultTimerGroup() {
84
84
sys::MemoryFence ();
85
85
if (tmp) return tmp;
86
86
87
- llvm_acquire_global_lock ( );
87
+ llvm::MutexGuard Lock ( llvm::llvm_get_global_lock () );
88
88
tmp = DefaultTimerGroup;
89
89
if (!tmp) {
90
90
tmp = new TimerGroup (" Miscellaneous Ungrouped Timers" );
91
91
sys::MemoryFence ();
92
92
DefaultTimerGroup = tmp;
93
93
}
94
- llvm_release_global_lock ();
95
94
96
95
return tmp;
97
96
}
You can’t perform that action at this time.
0 commit comments