@@ -30,6 +30,11 @@ typedef struct AtomicWaitNode {
3030 korp_cond wait_cond ;
3131} AtomicWaitNode ;
3232
33+ typedef struct AtomicWaitAddressArgs {
34+ uint32 len ;
35+ void * * addr ;
36+ } AtomicWaitAddressArgs ;
37+
3338/* Atomic wait map */
3439static HashMap * wait_map ;
3540
@@ -87,6 +92,53 @@ search_module(WASMModuleCommon *module)
8792 return NULL ;
8893}
8994
95+ static void
96+ create_list_of_waiter_addresses (void * key , void * value , void * user_data )
97+ {
98+ AtomicWaitAddressArgs * data = (AtomicWaitAddressArgs * )user_data ;
99+ if (data -> len > 0 ) {
100+ if (!(data -> addr = wasm_runtime_realloc (data -> addr ,
101+ data -> len * sizeof (uint32 )))) {
102+ LOG_ERROR ("failed to realloc atomic wait address list during "
103+ "wait_map traversal" );
104+ return ;
105+ }
106+ }
107+ else {
108+ if (!(data -> addr = wasm_runtime_malloc (sizeof (data -> len ) + 1 ))) {
109+ LOG_ERROR ("failed to malloc atomic wait address list during "
110+ "wait_map traversal" );
111+ return ;
112+ }
113+ }
114+ data -> len ++ ;
115+ data -> addr [data -> len - 1 ] = key ;
116+ }
117+
118+ void
119+ notify_stale_threads_on_exception (WASMModuleInstanceCommon * module_inst )
120+ {
121+ AtomicWaitAddressArgs * args = NULL ;
122+ if (!(args = wasm_runtime_malloc (sizeof (AtomicWaitAddressArgs )))) {
123+ LOG_ERROR ("failed to create atomic wait address args node" );
124+ return ;
125+ }
126+
127+ memset (args , 0 , sizeof (* args ));
128+ os_mutex_lock (& shared_memory_list_lock );
129+ // create list of addresses
130+ bh_hash_map_traverse (wait_map , create_list_of_waiter_addresses , args );
131+ os_mutex_unlock (& shared_memory_list_lock );
132+
133+ // notify
134+ for (uint32 i = 0 ; i < args -> len ; i ++ ) {
135+ wasm_runtime_atomic_notify (module_inst , args -> addr [i ], UINT32_MAX );
136+ }
137+
138+ // free memory allocated to args data
139+ wasm_runtime_free (args );
140+ }
141+
90142WASMSharedMemNode *
91143wasm_module_get_shared_memory (WASMModuleCommon * module )
92144{
0 commit comments