Use itempools for the scheduler

This commit is contained in:
Chris Young 2016-01-21 19:23:10 +00:00
parent d9e92d2032
commit 7da516067d

View File

@ -29,6 +29,7 @@
#include "utils/errors.h" #include "utils/errors.h"
#include "utils/log.h" #include "utils/log.h"
#include "amiga/misc.h"
#include "amiga/schedule.h" #include "amiga/schedule.h"
#ifdef AMIGA_NS_ASYNC #ifdef AMIGA_NS_ASYNC
@ -40,6 +41,9 @@ struct Device *TimerBase;
struct TimerIFace *ITimer; struct TimerIFace *ITimer;
#endif #endif
static APTR pool_nscb = NULL;
static APTR pool_timereq = NULL;
struct nscallback struct nscallback
{ {
struct TimeVal tv; struct TimeVal tv;
@ -83,7 +87,7 @@ static void ami_schedule_remove_timer_event(struct nscallback *nscb)
AbortIO((struct IORequest *)nscb->treq); AbortIO((struct IORequest *)nscb->treq);
WaitIO((struct IORequest *)nscb->treq); WaitIO((struct IORequest *)nscb->treq);
FreeVec(nscb->treq); ami_misc_itempool_free(pool_timereq, nscb->treq, sizeof(struct TimeRequest));
} }
} }
@ -107,7 +111,7 @@ static nserror ami_schedule_add_timer_event(struct nscallback *nscb, int t)
GetSysTime(&tv); GetSysTime(&tv);
AddTime(&nscb->tv,&tv); // now contains time when event occurs AddTime(&nscb->tv,&tv); // now contains time when event occurs
if((nscb->treq = AllocVecTagList(sizeof(struct TimeRequest), NULL))) { if((nscb->treq = ami_misc_itempool_alloc(pool_timereq, sizeof(struct TimeRequest)))) {
*nscb->treq = *tioreq; *nscb->treq = *tioreq;
nscb->treq->Request.io_Command=TR_ADDREQUEST; nscb->treq->Request.io_Command=TR_ADDREQUEST;
nscb->treq->Time.Seconds=nscb->tv.Seconds; // secs nscb->treq->Time.Seconds=nscb->tv.Seconds; // secs
@ -137,7 +141,7 @@ static struct nscallback *ami_schedule_locate(void (*callback)(void *p), void *p
bool found_cb = false; bool found_cb = false;
/* check there is something on the list */ /* check there is something on the list */
if (schedule_list == NULL) return NULL; if (schedule_list == NULL) return NULL;
if(pblHeapIsEmpty(schedule_list)) return NULL; if(pblHeapIsEmpty(schedule_list)) return NULL;
iterator = pblHeapIterator(schedule_list); iterator = pblHeapIterator(schedule_list);
@ -192,7 +196,7 @@ static nserror schedule_remove(void (*callback)(void *p), void *p)
if(nscb != NULL) { if(nscb != NULL) {
ami_schedule_remove_timer_event(nscb); ami_schedule_remove_timer_event(nscb);
FreeVec(nscb); ami_misc_itempool_free(pool_nscb, nscb, sizeof(struct nscallback));
pblHeapConstruct(schedule_list); pblHeapConstruct(schedule_list);
} }
@ -212,7 +216,7 @@ static void schedule_remove_all(void)
{ {
ami_schedule_remove_timer_event(nscb); ami_schedule_remove_timer_event(nscb);
pblIteratorRemove(iterator); pblIteratorRemove(iterator);
FreeVec(nscb); ami_misc_itempool_free(pool_nscb, nscb, sizeof(struct nscallback));
}; };
pblIteratorFree(iterator); pblIteratorFree(iterator);
@ -275,7 +279,7 @@ static void ami_scheduler_run(struct MsgPort *nsmsgport)
p = nscb->p; p = nscb->p;
ami_schedule_remove_timer_event(nscb); ami_schedule_remove_timer_event(nscb);
pblHeapRemoveFirst(schedule_list); pblHeapRemoveFirst(schedule_list);
FreeVec(nscb); ami_misc_itempool_free(pool_nscb, nscb, sizeof(struct nscallback));
asmsg->type = AMI_S_RUN; asmsg->type = AMI_S_RUN;
asmsg->callback = callback; asmsg->callback = callback;
@ -371,7 +375,7 @@ static nserror ami_scheduler_schedule(struct ami_schedule_message *asmsg)
return ami_schedule_reschedule(nscb, asmsg->t); return ami_schedule_reschedule(nscb, asmsg->t);
} }
nscb = AllocVecTagList(sizeof(struct nscallback), NULL); nscb = ami_misc_itempool_alloc(pool_nscb, sizeof(struct nscallback));
if(!nscb) return NSERROR_NOMEM; if(!nscb) return NSERROR_NOMEM;
if (ami_schedule_add_timer_event(nscb, asmsg->t) != NSERROR_OK) if (ami_schedule_add_timer_event(nscb, asmsg->t) != NSERROR_OK)
@ -536,6 +540,9 @@ static int32 ami_scheduler_process(STRPTR args, int32 length, APTR execbase)
*/ */
nserror ami_scheduler_process_create(struct MsgPort *nsmsgport) nserror ami_scheduler_process_create(struct MsgPort *nsmsgport)
{ {
pool_nscb = ami_misc_itempool_create(sizeof(struct nscallback));
pool_timereq = ami_misc_itempool_create(sizeof(struct TimeRequest));
#ifndef AMIGA_NS_ASYNC #ifndef AMIGA_NS_ASYNC
ami_schedule_create(nsmsgport); ami_schedule_create(nsmsgport);
#else #else
@ -585,5 +592,8 @@ void ami_scheduler_process_delete(void)
PutMsg(smsgport, (struct Message *)asmsg); PutMsg(smsgport, (struct Message *)asmsg);
smsgport = NULL; /* this is freed via another copy of this pointer */ smsgport = NULL; /* this is freed via another copy of this pointer */
#endif #endif
ami_misc_itempool_delete(pool_timereq);
ami_misc_itempool_delete(pool_nscb);
} }