Call open/close timer from schedule init/free functions

This commit is contained in:
Chris Young 2014-11-10 23:50:28 +00:00
parent 4ca37c35cf
commit fb0af6f269
3 changed files with 32 additions and 33 deletions

View File

@ -2949,7 +2949,6 @@ static void gui_quit(void)
LOG(("Freeing scheduler"));
ami_schedule_free();
ami_schedule_close_timer();
FreeObjList(window_list);
@ -5265,8 +5264,10 @@ int main(int argc, char** argv)
ami_mime_init("PROGDIR:Resources/mimetypes");
sprintf(temp, "%s/mimetypes.user", current_user_dir);
ami_mime_init(temp);
ami_schedule_open_timer();
ami_schedule_create();
if(ami_schedule_create() == false) {
ami_misc_fatal_error("Failed to initialise scheduler");
return RETURN_FAIL;
}
amiga_plugin_hack_init();
ret = amiga_datatypes_init();

View File

@ -81,7 +81,7 @@ static nserror ami_schedule_add_timer_event(struct nscallback *nscb, int t)
GetSysTime(&tv);
AddTime(&nscb->tv,&tv); // now contains time when event occurs
if(nscb->treq = AllocVecTagList(sizeof(struct TimeRequest), NULL)) {
if((nscb->treq = AllocVecTagList(sizeof(struct TimeRequest), NULL))) {
*nscb->treq = *tioreq;
nscb->treq->Request.io_Command=TR_ADDREQUEST;
nscb->treq->Time.Seconds=nscb->tv.Seconds; // secs
@ -160,7 +160,6 @@ static nserror ami_schedule_reschedule(struct nscallback *nscb, int t)
static nserror schedule_remove(void (*callback)(void *p), void *p)
{
PblIterator *iterator;
struct nscallback *nscb;
nscb = ami_schedule_locate(callback, p, true);
@ -214,8 +213,7 @@ void schedule_run(BOOL poll)
if(nscb == -1) return;
if(poll)
{
if(poll) {
/* Ensure the scheduled event time has passed (CmpTime<=0)
* For timer signalled events this must *always* be true,
* so we save some time by only checking if we're polling.
@ -233,25 +231,7 @@ void schedule_run(BOOL poll)
callback(p);
}
/* exported function documented in amiga/schedule.h */
BOOL ami_schedule_create(void)
{
schedule_list = pblHeapNew();
if(schedule_list == PBL_ERROR_OUT_OF_MEMORY) return false;
pblHeapSetCompareFunction(schedule_list, ami_schedule_compare);
}
/* exported function documented in amiga/schedule.h */
void ami_schedule_free(void)
{
schedule_remove_all();
pblHeapFree(schedule_list); // this should be empty at this point
schedule_list = NULL;
}
/* exported function documented in amiga/schedule.h */
void ami_schedule_open_timer(void)
static void ami_schedule_open_timer(void)
{
msgport = AllocSysObjectTags(ASOT_PORT,
ASO_NoTrack,FALSE,
@ -269,8 +249,7 @@ void ami_schedule_open_timer(void)
ITimer = (struct TimerIFace *)GetInterface((struct Library *)TimerBase,"main",1,NULL);
}
/* exported function documented in amiga/schedule.h */
void ami_schedule_close_timer(void)
static void ami_schedule_close_timer(void)
{
if(ITimer) DropInterface((struct Interface *)ITimer);
CloseDevice((struct IORequest *) tioreq);
@ -278,6 +257,28 @@ void ami_schedule_close_timer(void)
FreeSysObject(ASOT_PORT,msgport);
}
/* exported function documented in amiga/schedule.h */
bool ami_schedule_create(void)
{
ami_schedule_open_timer();
schedule_list = pblHeapNew();
if(schedule_list == PBL_ERROR_OUT_OF_MEMORY) return false;
pblHeapSetCompareFunction(schedule_list, ami_schedule_compare);
return true;
}
/* exported function documented in amiga/schedule.h */
void ami_schedule_free(void)
{
schedule_remove_all();
pblHeapFree(schedule_list); // this should be empty at this point
schedule_list = NULL;
ami_schedule_close_timer();
}
/* exported function documented in amiga/schedule.h */
nserror ami_schedule(int t, void (*callback)(void *p), void *p)
{
@ -286,7 +287,7 @@ nserror ami_schedule(int t, void (*callback)(void *p), void *p)
if(schedule_list == NULL) return NSERROR_INIT_FAILED;
if (t < 0) return schedule_remove(callback, p);
if (nscb = ami_schedule_locate(callback, p, false)) {
if ((nscb = ami_schedule_locate(callback, p, false))) {
return ami_schedule_reschedule(nscb, t);
}

View File

@ -45,7 +45,7 @@ nserror ami_schedule(int t, void (*callback)(void *p), void *p);
*
* /return true if initialised ok or false on error.
*/
BOOL ami_schedule_create(void);
bool ami_schedule_create(void);
/**
* Finalise amiga scheduler
@ -62,7 +62,4 @@ void ami_schedule_free(void);
*/
void schedule_run(BOOL poll);
void ami_schedule_open_timer(void);
void ami_schedule_close_timer(void);
#endif