fix mutex race
Some checks failed
Build and Deploy / build-linux (push) Failing after 1m27s
Build and Deploy / build-macos (push) Failing after 8s
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled

This commit is contained in:
2025-05-28 18:50:39 -05:00
parent 09f48d08b9
commit 53b3f0af9c

View File

@@ -233,21 +233,26 @@ prosperon_rt *create_actor(int argc, char **argv, void (*hook)(JSContext*))
prosperon_rt *get_actor(char *id)
{
int idx = shgeti(actors, id);
if (idx == -1) return NULL;
prosperon_rt *actor;
SDL_LockMutex(actors_mutex);
actor = actors[idx].value;
int idx = shgeti(actors, id);
if (idx == -1) {
SDL_UnlockMutex(actors_mutex);
return NULL;
}
prosperon_rt *actor = actors[idx].value;
SDL_UnlockMutex(actors_mutex);
return actor;
}
const char *register_actor(const char *id, prosperon_rt *actor, int mainthread)
{
if (shgeti(actors, id) != -1) return "Actor with given ID already exists.";
SDL_LockMutex(actors_mutex);
if (shgeti(actors, id) != -1) {
SDL_UnlockMutex(actors_mutex);
return "Actor with given ID already exists.";
}
actor->main_thread_only = mainthread;
actor->id = strdup(id);
SDL_LockMutex(actors_mutex);
shput(actors, id, actor);
SDL_UnlockMutex(actors_mutex);
return NULL;
@@ -267,9 +272,10 @@ const char *send_message(const char *id, void *msg)
SDL_RemoveTimer(target->ar);
target->ar = 0;
}
set_actor_state(target);
SDL_UnlockMutex(target->msg_mutex);
set_actor_state(target);
return NULL;
}
@@ -1570,7 +1576,9 @@ int main(int argc, char **argv)
int actor_exists(const char *id)
{
SDL_LockMutex(actors_mutex);
int idx = shgeti(actors,id);
SDL_UnlockMutex(actors_mutex);
if (idx == -1)
return 0;
else