@@ -91,74 +91,13 @@ using namespace llvm;
91
91
using namespace std ;
92
92
93
93
#define LOCK (InterpInfo ) \
94
- LockRAII interop_lock = \
95
- LockRAII ((InterpInfo).InterpreterLock, (InterpInfo).ThreadIdLock, \
96
- (InterpInfo).CurrentThreadId)
97
-
98
- namespace {
99
- struct LockRAII {
100
- LockRAII (std::mutex& resource_lock, std::mutex& thread_id_lock,
101
- std::optional<std::thread::id>& current_thread_id)
102
- : ResourceLock(resource_lock), ThreadIdLock(thread_id_lock),
103
- CurrentThreadId (current_thread_id) {
104
- ThreadIdLock.lock ();
105
- if (!ResourceLock.try_lock ()) {
106
- if (CurrentThreadId) {
107
- if ((*CurrentThreadId) != std::this_thread::get_id ()) {
108
- ThreadIdLock.unlock ();
109
- ResourceLock.lock (); // blocking
110
- bool res = ThreadIdLock.try_lock (); // should be free
111
- assert (res && " Internal Error: Interpreter lock not held, but "
112
- " ThreadId lock held.\n Please report this as a bug.\n " );
113
- ThreadIdLock.unlock ();
114
- return ;
115
- }
116
- owned = false ;
117
- ThreadIdLock.unlock ();
118
- return ;
119
- }
120
- assert (false &&
121
- " Internal Error: A thread holds lock for the current "
122
- " interpreter, but no information available on which thread "
123
- " holds the lock.\n Please report this as a bug.\n " );
124
- }
125
- assert (!CurrentThreadId &&
126
- " Internal Error: Lock released but thread id not cleared.\n Please "
127
- " report this as a bug.\n " );
128
- CurrentThreadId = std::this_thread::get_id ();
129
- ThreadIdLock.unlock ();
130
- }
131
-
132
- ~LockRAII () {
133
- assert (!ResourceLock.try_lock () &&
134
- " Internal Error: Resource lock not held" );
135
- if (!owned)
136
- return ;
137
- ThreadIdLock.lock ();
138
- CurrentThreadId = std::nullopt;
139
- ThreadIdLock.unlock ();
140
- ResourceLock.unlock ();
141
- }
142
-
143
- LockRAII (LockRAII&&) = delete ;
144
- LockRAII (const LockRAII&) = delete ;
145
- LockRAII& operator =(const LockRAII&) = delete ;
146
- LockRAII& operator =(LockRAII&&) = delete ;
147
-
148
- private:
149
- bool owned = true ;
150
- std::mutex& ResourceLock;
151
- std::mutex& ThreadIdLock;
152
- std::optional<std::thread::id>& CurrentThreadId;
153
- };
154
- } // namespace
94
+ std::lock_guard<std::recursive_mutex> interop_lock ( \
95
+ (InterpInfo).InterpreterLock)
155
96
156
97
struct InterpreterInfo {
157
98
compat::Interpreter* Interpreter = nullptr ;
158
99
bool isOwned = true ;
159
- std::mutex InterpreterLock;
160
- std::mutex ThreadIdLock;
161
- std::optional<std::thread::id> CurrentThreadId = std::nullopt;
100
+ std::recursive_mutex InterpreterLock;
162
101
163
102
InterpreterInfo (compat::Interpreter* I, bool Owned)
164
103
: Interpreter (I), isOwned (Owned) {}
0 commit comments