Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion core/iwasm/common/wasm_shared_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef struct AtomicWaitInfo {
korp_mutex wait_list_lock;
bh_list wait_list_head;
bh_list *wait_list;
int count_acquisition;
} AtomicWaitInfo;

typedef struct AtomicWaitNode {
Expand Down Expand Up @@ -307,6 +308,8 @@ acquire_wait_info(void *address, bool create)

if (address)
wait_info = (AtomicWaitInfo *)bh_hash_map_find(wait_map, address);
if (wait_info)
++wait_info->count_acquisition;
Comment thread
g0djan marked this conversation as resolved.
Outdated

if (!create) {
os_mutex_unlock(&wait_map_lock);
Expand Down Expand Up @@ -334,6 +337,7 @@ acquire_wait_info(void *address, bool create)
if (!bh_hash_map_insert(wait_map, address, (void *)wait_info)) {
goto fail3;
}
wait_info->count_acquisition = 1;
}

os_mutex_unlock(&wait_map_lock);
Expand Down Expand Up @@ -380,11 +384,23 @@ static bool
map_remove_wait_info(HashMap *wait_map_, AtomicWaitInfo *wait_info,
void *address)
{
os_mutex_lock(&wait_map_lock);
Comment thread
g0djan marked this conversation as resolved.
--wait_info->count_acquisition;
Comment thread
g0djan marked this conversation as resolved.
Outdated

os_mutex_lock(&wait_info->wait_list_lock);
if (wait_info->wait_list->len > 0) {
Comment thread
g0djan marked this conversation as resolved.
os_mutex_unlock(&wait_info->wait_list_lock);
os_mutex_unlock(&wait_map_lock);
return false;
}
os_mutex_unlock(&wait_info->wait_list_lock);
Comment thread
wenyongh marked this conversation as resolved.
if (wait_info->count_acquisition > 0) {
os_mutex_unlock(&wait_map_lock);
return false;
}

bh_hash_map_remove(wait_map_, address, NULL, NULL);
os_mutex_unlock(&wait_map_lock);
return true;
}

Expand Down Expand Up @@ -486,8 +502,8 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
wasm_runtime_free(wait_node);

/* Release wait info if no wait nodes attached */
removed_from_map = map_remove_wait_info(wait_map, wait_info, address);
os_mutex_unlock(&wait_info->wait_list_lock);
removed_from_map = map_remove_wait_info(wait_map, wait_info, address);
if (removed_from_map)
destroy_wait_info(wait_info);
Comment thread
wenyongh marked this conversation as resolved.
Outdated
os_mutex_unlock(&node->shared_mem_lock);
Expand Down