Fix/Simplify the atomic.wait/nofity implementations (#2044)
Use the shared memory's shared_mem_lock to lock the whole atomic.wait and atomic.notify processes, and use it for os_cond_reltimedwait and os_cond_notify, so as to make the whole processes actual atomic operations: the original implementation accesses the wait address with shared_mem_lock and uses wait_node->wait_lock for os_cond_reltimedwait, which is not an atomic operation. And remove the unnecessary wait_map_lock and wait_lock, since the whole processes are already locked by shared_mem_lock.
This commit is contained in:
@ -3414,7 +3414,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
ret = wasm_runtime_atomic_notify(
|
||||
(WASMModuleInstanceCommon *)module, maddr,
|
||||
notify_count);
|
||||
bh_assert((int32)ret >= 0);
|
||||
if (ret == (uint32)-1)
|
||||
goto got_exception;
|
||||
|
||||
PUSH_I32(ret);
|
||||
break;
|
||||
@ -3471,7 +3472,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
{
|
||||
/* Skip the memory index */
|
||||
frame_ip++;
|
||||
os_atomic_thread_fence(os_memory_order_release);
|
||||
os_atomic_thread_fence(os_memory_order_seq_cst);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3578,7 +3579,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
|
||||
CHECK_ATOMIC_MEMORY_ACCESS();
|
||||
os_mutex_lock(&node->shared_mem_lock);
|
||||
STORE_U32(maddr, frame_sp[1]);
|
||||
STORE_U32(maddr, sval);
|
||||
os_mutex_unlock(&node->shared_mem_lock);
|
||||
}
|
||||
break;
|
||||
@ -3619,8 +3620,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr);
|
||||
CHECK_ATOMIC_MEMORY_ACCESS();
|
||||
os_mutex_lock(&node->shared_mem_lock);
|
||||
PUT_I64_TO_ADDR((uint32 *)maddr,
|
||||
GET_I64_FROM_ADDR(frame_sp + 1));
|
||||
PUT_I64_TO_ADDR((uint32 *)maddr, sval);
|
||||
os_mutex_unlock(&node->shared_mem_lock);
|
||||
}
|
||||
break;
|
||||
@ -3721,9 +3721,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
|
||||
os_mutex_lock(&node->shared_mem_lock);
|
||||
readv = (uint64)LOAD_I64(maddr);
|
||||
if (readv == expect) {
|
||||
if (readv == expect)
|
||||
STORE_I64(maddr, sval);
|
||||
}
|
||||
os_mutex_unlock(&node->shared_mem_lock);
|
||||
}
|
||||
PUSH_I64(readv);
|
||||
|
||||
@ -3252,7 +3252,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
ret = wasm_runtime_atomic_notify(
|
||||
(WASMModuleInstanceCommon *)module, maddr,
|
||||
notify_count);
|
||||
bh_assert((int32)ret >= 0);
|
||||
if (ret == (uint32)-1)
|
||||
goto got_exception;
|
||||
|
||||
PUSH_I32(ret);
|
||||
break;
|
||||
@ -3307,7 +3308,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
}
|
||||
case WASM_OP_ATOMIC_FENCE:
|
||||
{
|
||||
os_atomic_thread_fence(os_memory_order_release);
|
||||
os_atomic_thread_fence(os_memory_order_seq_cst);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3555,9 +3556,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
|
||||
os_mutex_lock(&node->shared_mem_lock);
|
||||
readv = (uint64)LOAD_I64(maddr);
|
||||
if (readv == expect) {
|
||||
if (readv == expect)
|
||||
STORE_I64(maddr, sval);
|
||||
}
|
||||
os_mutex_unlock(&node->shared_mem_lock);
|
||||
}
|
||||
PUSH_I64(readv);
|
||||
|
||||
Reference in New Issue
Block a user