@@ -16,7 +16,7 @@ pub struct ExecutionEngine {
16
16
impl ExecutionEngine {
17
17
/// Constructs a new `ExecutionEngine`.
18
18
///
19
- /// This method initializes a new LLVM context and module , configures the general target,
19
+ /// This method initializes a new LLVM ExecutionEngine , configures the general target,
20
20
/// and optionally sets up a logger for debugging information based on the `debug_info` parameter.
21
21
///
22
22
/// # Parameters
@@ -27,12 +27,13 @@ impl ExecutionEngine {
27
27
/// A new instance of `ExecutionEngine`.
28
28
pub fn new ( module : Arc < RwLock < SafeLLVMPointer > > , debug_info : bool ) -> Self {
29
29
GeneralTargetConfigurator . configure ( ) ;
30
-
30
+
31
31
let mut engine_ref: execution_engine:: LLVMExecutionEngineRef = std:: ptr:: null_mut ( ) ;
32
32
let mut out_error: * mut c_char = std:: ptr:: null_mut ( ) ;
33
33
let engine_ptr = & mut engine_ref;
34
34
35
- module. read ( ) . unwrap ( ) . read ( LLVMRefType :: Module , |module_ref| {
35
+ let module_rw_lock = module. try_read ( ) . expect ( "Failed to read module" ) ;
36
+ module_rw_lock. write ( LLVMRefType :: Module , |module_ref| {
36
37
if let LLVMRef :: Module ( module_ptr) = module_ref {
37
38
unsafe {
38
39
if execution_engine:: LLVMCreateExecutionEngineForModule ( engine_ptr, * module_ptr, & mut out_error) != 0 {
@@ -95,8 +96,8 @@ impl ExecutionEngine {
95
96
ReturnType : ' static ,
96
97
ArgType : Any + Send + Sync ,
97
98
{
98
- let engine_lock = self . engine . read ( ) . map_err ( |e| format ! ( "Failed to obtain read lock on engine: {}" , e) ) ?;
99
- let result = engine_lock. read ( LLVMRefType :: ExecutionEngine , |engine_ref| {
99
+ let engine_lock = self . engine . try_read ( ) . map_err ( |e| format ! ( "Failed to obtain read lock on engine: {}" , e) ) ?;
100
+ let result = engine_lock. write ( LLVMRefType :: ExecutionEngine , |engine_ref| {
100
101
if let LLVMRef :: ExecutionEngine ( engine_ptr) = engine_ref {
101
102
let function_name_c = CString :: new ( function_name) . map_err ( |_| "Failed to create CString for function name." ) ?;
102
103
let function_address = unsafe { execution_engine:: LLVMGetFunctionAddress ( * engine_ptr, function_name_c. as_ptr ( ) ) } ;
0 commit comments