Skip to content

Commit 409864f

Browse files
committed
[llvm-c] APIs for acquiring and releasing ThreadSafeContext locks
1 parent dd02fb3 commit 409864f

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

llvm/docs/ReleaseNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ Changes to the C API
256256
* Added ``LLVMGetICmpSameSign`` and ``LLVMSetICmpSameSign`` for the `samesign`
257257
flag on `icmp` instructions.
258258

259+
* Added `LLVMOrcThreadSafeContextGetLock` and `LLVMOrcThreadSafeContextReleaseLock`
260+
for acquiring and releasing locks associated with `ThreadSafeContext` instances.
261+
259262
Changes to the CodeGen infrastructure
260263
-------------------------------------
261264

llvm/include/llvm-c/Orc.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ typedef int (*LLVMOrcSymbolPredicate)(void *Ctx,
385385
*/
386386
typedef struct LLVMOrcOpaqueThreadSafeContext *LLVMOrcThreadSafeContextRef;
387387

388+
/**
389+
* A reference to an orc::ThreadSafeContext::Lock instance.
390+
*/
391+
typedef struct LLVMOrcOpaqueThreadSafeContextLock
392+
*LLVMOrcThreadSafeContextLockRef;
393+
388394
/**
389395
* A reference to an orc::ThreadSafeModule instance.
390396
*/
@@ -1082,6 +1088,18 @@ LLVMOrcThreadSafeContextGetContext(LLVMOrcThreadSafeContextRef TSCtx);
10821088
*/
10831089
void LLVMOrcDisposeThreadSafeContext(LLVMOrcThreadSafeContextRef TSCtx);
10841090

1091+
/**
1092+
* Acquire the lock associated with a ThreadSafeContext.
1093+
*/
1094+
LLVMOrcThreadSafeContextLockRef
1095+
LLVMOrcThreadSafeContextGetLock(LLVMOrcThreadSafeContextRef TSCtx);
1096+
1097+
/**
1098+
* Release the lock associated with a ThreadSafeContext.
1099+
*/
1100+
void LLVMOrcThreadSafeContextReleaseLock(
1101+
LLVMOrcThreadSafeContextLockRef TSCtxLock);
1102+
10851103
/**
10861104
* Create a ThreadSafeModule wrapper around the given LLVM module. This takes
10871105
* ownership of the M argument which should not be disposed of or referenced

llvm/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DefinitionGenerator,
6161
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(InProgressLookupState, LLVMOrcLookupStateRef)
6262
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeContext,
6363
LLVMOrcThreadSafeContextRef)
64+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeContext::Lock,
65+
LLVMOrcThreadSafeContextLockRef)
6466
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeModule, LLVMOrcThreadSafeModuleRef)
6567
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITTargetMachineBuilder,
6668
LLVMOrcJITTargetMachineBuilderRef)
@@ -738,6 +740,16 @@ void LLVMOrcDisposeThreadSafeContext(LLVMOrcThreadSafeContextRef TSCtx) {
738740
delete unwrap(TSCtx);
739741
}
740742

743+
LLVMOrcThreadSafeContextLockRef
744+
LLVMOrcThreadSafeContextGetLock(LLVMOrcThreadSafeContextRef TSCtx) {
745+
return wrap(new ThreadSafeContext::Lock(std::move(unwrap(TSCtx)->getLock())));
746+
}
747+
748+
void LLVMOrcThreadSafeContextReleaseLock(
749+
LLVMOrcThreadSafeContextLockRef TSCtxLock) {
750+
delete unwrap(TSCtxLock);
751+
}
752+
741753
LLVMErrorRef
742754
LLVMOrcThreadSafeModuleWithModuleDo(LLVMOrcThreadSafeModuleRef TSM,
743755
LLVMOrcGenericIRModuleOperationFunction F,

0 commit comments

Comments
 (0)