fix actors not running correctly
This commit is contained in:
@@ -499,9 +499,8 @@ void set_actor_state(cell_rt *actor)
|
||||
SDL_UnlockSpinlock(&queue_lock);
|
||||
SDL_SignalSemaphore(ready_sem);
|
||||
}
|
||||
} else if (!arrlen(actor->letters) && !hmlen(actor->timers)) {
|
||||
} else if (!arrlen(actor->letters) && !hmlen(actor->timers))
|
||||
actor->ar = SDL_AddTimerNS(actor->ar_secs*1e9, actor_remove_cb, actor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -768,7 +767,9 @@ static int actor_runner(void *data)
|
||||
SDL_AddAtomicInt(&runners_count, 1);
|
||||
|
||||
while (!SDL_GetAtomicInt(&shutting_down)) {
|
||||
SDL_WaitSemaphore(ready_sem);
|
||||
SDL_LockSpinlock(&queue_lock);
|
||||
|
||||
cell_rt *actor = NULL;
|
||||
if (arrlen(ready_queue) > 0) {
|
||||
actor = ready_queue[0];
|
||||
@@ -778,9 +779,6 @@ static int actor_runner(void *data)
|
||||
|
||||
if (actor)
|
||||
actor_turn(actor);
|
||||
|
||||
SDL_WaitSemaphore(ready_sem);
|
||||
if (SDL_GetAtomicInt(&shutting_down)) break;
|
||||
}
|
||||
|
||||
SDL_AddAtomicInt(&runners_count, -1);
|
||||
@@ -817,17 +815,9 @@ static void add_runners(int n)
|
||||
|
||||
static void loop()
|
||||
{
|
||||
/* Initialize synchronization primitives */
|
||||
ready_sem = SDL_CreateSemaphore(0);
|
||||
main_sem = SDL_CreateSemaphore(0);
|
||||
actors_mutex = SDL_CreateMutex();
|
||||
SDL_SetAtomicInt(&shutting_down, 0);
|
||||
SDL_SetAtomicInt(&runners_count, 0);
|
||||
|
||||
add_runners(SDL_GetNumLogicalCPUCores());
|
||||
|
||||
int msgs = 0;
|
||||
while (!SDL_GetAtomicInt(&shutting_down)) {
|
||||
SDL_WaitSemaphore(main_sem);
|
||||
SDL_WaitSemaphore(main_sem);
|
||||
SDL_LockSpinlock(&main_queue_lock);
|
||||
cell_rt *actor = NULL;
|
||||
if (arrlen(main_queue) > 0) {
|
||||
@@ -835,13 +825,9 @@ static void loop()
|
||||
arrdel(main_queue, 0);
|
||||
}
|
||||
SDL_UnlockSpinlock(&main_queue_lock);
|
||||
|
||||
if (actor) {
|
||||
printf("running %s\n", actor->id);
|
||||
printf("message is %d\n", actor->letters[0].type);
|
||||
actor_turn(actor);
|
||||
continue;
|
||||
}
|
||||
msgs++;
|
||||
actor_turn(actor);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -937,6 +923,17 @@ int main(int argc, char **argv)
|
||||
wota_write_array(&startwota, actor_argc - 1);
|
||||
for (int i = 1; i < actor_argc; i++)
|
||||
wota_write_text(&startwota, actor_argv[i]);
|
||||
|
||||
|
||||
/* Initialize synchronization primitives */
|
||||
ready_sem = SDL_CreateSemaphore(0);
|
||||
main_sem = SDL_CreateSemaphore(0);
|
||||
actors_mutex = SDL_CreateMutex();
|
||||
SDL_SetAtomicInt(&shutting_down, 0);
|
||||
SDL_SetAtomicInt(&runners_count, 0);
|
||||
|
||||
add_runners(SDL_GetNumLogicalCPUCores());
|
||||
|
||||
root_cell = create_actor(startwota.data);
|
||||
|
||||
/* Set up signal and exit handlers */
|
||||
|
||||
Reference in New Issue
Block a user