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