Move some things around and add another indicator to prevent double frees

This commit is contained in:
Paul Dino Jones 2024-08-31 16:02:34 -04:00
parent d1f252d4e0
commit 572a21b3d6
2 changed files with 39 additions and 27 deletions

View File

@ -188,7 +188,6 @@ int showstats(SimData* simdata)
void shmdatamapcallback(uv_timer_t* handle) void shmdatamapcallback(uv_timer_t* handle)
{ {
void* b = uv_handle_get_data((uv_handle_t*) handle); void* b = uv_handle_get_data((uv_handle_t*) handle);
loop_data* f = (loop_data*) b; loop_data* f = (loop_data*) b;
SimData* simdata = f->simdata; SimData* simdata = f->simdata;
@ -238,6 +237,11 @@ void shmdatamapcallback(uv_timer_t* handle)
if (f->simstate == false || simdata->simstatus <= 1 || appstate <= 1) if (f->simstate == false || simdata->simstatus <= 1 || appstate <= 1)
{ {
if(f->releasing == false)
{
f->releasing = true;
uv_timer_stop(handle);
slogi("releasing devices, please wait");
f->uion = false; f->uion = false;
SimDevice* devices = f->simdevices; SimDevice* devices = f->simdevices;
int numdevices = f->numdevices; int numdevices = f->numdevices;
@ -263,14 +267,15 @@ void shmdatamapcallback(uv_timer_t* handle)
slogi("stopped mapping data, press q again to quit"); slogi("stopped mapping data, press q again to quit");
//stopui(ms->ui_type, f); //stopui(ms->ui_type, f);
// free loop data // free loop data
uv_timer_stop(handle);
uv_timer_start(&datachecktimer, datacheckcallback, 3000, 1000); uv_timer_start(&datachecktimer, datacheckcallback, 1000, 1000);
f->releasing = false;
}
} }
} }
void datacheckcallback(uv_timer_t* handle) void datacheckcallback(uv_timer_t* handle)
{ {
void* b = uv_handle_get_data((uv_handle_t*) handle); void* b = uv_handle_get_data((uv_handle_t*) handle);
loop_data* f = (loop_data*) b; loop_data* f = (loop_data*) b;
SimData* simdata = f->simdata; SimData* simdata = f->simdata;
@ -300,15 +305,20 @@ void datacheckcallback(uv_timer_t* handle)
void cb(uv_poll_t* handle, int status, int events) void cb(uv_poll_t* handle, int status, int events)
{ {
void* b = uv_handle_get_data((uv_handle_t*) handle);
loop_data* f = (loop_data*) b;
char ch; char ch;
scanf("%c", &ch); scanf("%c", &ch);
if (ch == 'q') if (ch == 'q')
{
if(f->releasing == false)
{ {
appstate--; appstate--;
slogi("User requested stop appstate is now %i", appstate); slogi("User requested stop appstate is now %i", appstate);
fprintf(stdout, "User requested stop appstate is now %i\n", appstate); fprintf(stdout, "User requested stop appstate is now %i\n", appstate);
fflush(stdout); fflush(stdout);
} }
}
if (appstate == 0) if (appstate == 0)
{ {
@ -344,6 +354,7 @@ int monocoque_mainloop(MonocoqueSettings* ms)
baton->ms = ms; baton->ms = ms;
baton->simstate = false; baton->simstate = false;
baton->uion = false; baton->uion = false;
baton->releasing = false;
baton->sim = 0; baton->sim = 0;
baton->req.data = (void*) baton; baton->req.data = (void*) baton;
uv_handle_set_data((uv_handle_t*) &datachecktimer, (void*) baton); uv_handle_set_data((uv_handle_t*) &datachecktimer, (void*) baton);

View File

@ -15,6 +15,7 @@ typedef struct loop_data
Simulator sim; Simulator sim;
bool simstate; bool simstate;
bool uion; bool uion;
bool releasing;
int numdevices; int numdevices;
MonocoqueSettings* ms; MonocoqueSettings* ms;
SimData* simdata; SimData* simdata;