File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -1099,6 +1099,12 @@ LLVM_C_ABI LLVMOrcThreadSafeContextRef LLVMOrcCreateNewThreadSafeContext(void);
10991099LLVM_C_ABI LLVMOrcThreadSafeContextRef
11001100LLVMOrcCreateNewThreadSafeContextFromLLVMContext (LLVMContextRef Ctx);
11011101
1102+ /* *
1103+ * Get a reference to the wrapped LLVMContext.
1104+ */
1105+ LLVMContextRef
1106+ LLVMOrcThreadSafeContextGetContext (LLVMOrcThreadSafeContextRef TSCtx);
1107+
11021108/* *
11031109 * Dispose of a ThreadSafeContext.
11041110 */
Original file line number Diff line number Diff line change @@ -36,6 +36,16 @@ class ThreadSafeContext {
3636 };
3737
3838public:
39+ // RAII based lock for ThreadSafeContext.
40+ class [[nodiscard]] Lock {
41+ public:
42+ Lock (std::shared_ptr<State> S) : S (std::move (S)), L (this ->S ->Mutex ) {}
43+
44+ private:
45+ std::shared_ptr<State> S;
46+ std::unique_lock<std::recursive_mutex> L;
47+ };
48+
3949 // / Construct a null context.
4050 ThreadSafeContext () = default ;
4151
@@ -62,6 +72,19 @@ class ThreadSafeContext {
6272 return F ((const LLVMContext *)nullptr );
6373 }
6474
75+ // / Returns a pointer to the LLVMContext that was used to construct this
76+ // / instance, or null if the instance was default constructed.
77+ LLVMContext *getContext () { return S ? S->Ctx .get () : nullptr ; }
78+
79+ // / Returns a pointer to the LLVMContext that was used to construct this
80+ // / instance, or null if the instance was default constructed.
81+ const LLVMContext *getContext () const { return S ? S->Ctx .get () : nullptr ; }
82+
83+ Lock getLock () const {
84+ assert (S && " Can not lock an empty ThreadSafeContext" );
85+ return Lock (S);
86+ }
87+
6588private:
6689 std::shared_ptr<State> S;
6790};
Original file line number Diff line number Diff line change @@ -734,6 +734,11 @@ LLVMOrcCreateNewThreadSafeContextFromLLVMContext(LLVMContextRef Ctx) {
734734 return wrap (new ThreadSafeContext (std::unique_ptr<LLVMContext>(unwrap (Ctx))));
735735}
736736
737+ LLVMContextRef
738+ LLVMOrcThreadSafeContextGetContext (LLVMOrcThreadSafeContextRef TSCtx) {
739+ return wrap (unwrap (TSCtx)->getContext ());
740+ }
741+
737742void LLVMOrcDisposeThreadSafeContext (LLVMOrcThreadSafeContextRef TSCtx) {
738743 delete unwrap (TSCtx);
739744}
You can’t perform that action at this time.
0 commit comments