From 7efd9a2c676605aacdf58f7a8a531f0032502b51 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 21 Jan 2016 20:13:49 +0000 Subject: Remove unused Amiga async scheduler --- amiga/schedule.c | 306 ++++++------------------------------------------------- 1 file changed, 29 insertions(+), 277 deletions(-) (limited to 'amiga/schedule.c') diff --git a/amiga/schedule.c b/amiga/schedule.c index 39c3a3ba7..a8061a7b3 100755 --- a/amiga/schedule.c +++ b/amiga/schedule.c @@ -27,14 +27,10 @@ #include #include "utils/errors.h" -#include "utils/log.h" #include "amiga/misc.h" #include "amiga/schedule.h" -#ifdef AMIGA_NS_ASYNC -static struct MsgPort *smsgport = NULL; /* to send messages for the scheduler to */ -#endif static struct TimeRequest *tioreq; struct Device *TimerBase; #ifdef __amigaos4__ @@ -52,21 +48,6 @@ struct nscallback struct TimeRequest *treq; }; -struct ami_schedule_message { - struct Message msg; - int type; - int t; - void *callback; - void *p; -}; - -enum { - AMI_S_SCHEDULE = 0, - AMI_S_RUN, - AMI_S_STARTUP, - AMI_S_EXIT -}; - static PblHeap *schedule_list; /** @@ -231,18 +212,6 @@ static int ami_schedule_compare(const void *prev, const void *next) } -/** - * Process events up to current time. - * NetSurf entry point after being signalled by the scheduler process. - */ -static void schedule_run(struct ami_schedule_message *asmsg) -{ - void (*callback)(void *p) = asmsg->callback; - void *p = asmsg->p; - - callback(p); -} - /** * Process events up to current time. * @@ -250,21 +219,13 @@ static void schedule_run(struct ami_schedule_message *asmsg) * venture to later scheduled events until the next time it is called - * immediately afterwards, if we're in a timer signalled loop. */ -static void ami_scheduler_run(struct MsgPort *nsmsgport) +static void ami_scheduler_run(void) { struct nscallback *nscb; + struct TimeVal tv; void (*callback)(void *p); void *p; - struct TimeVal tv; - struct ami_schedule_message *asmsg; -#ifndef AMIGA_NS_ASYNC - asmsg = AllocVecTagList(sizeof(struct ami_schedule_message), NULL); -#else - asmsg = AllocSysObjectTags(ASOT_MESSAGE, - ASOMSG_Size, sizeof(struct ami_schedule_message), - TAG_END); -#endif nscb = pblHeapGetFirst(schedule_list); if(nscb == -1) return; @@ -277,30 +238,18 @@ static void ami_scheduler_run(struct MsgPort *nsmsgport) callback = nscb->callback; p = nscb->p; + ami_schedule_remove_timer_event(nscb); pblHeapRemoveFirst(schedule_list); ami_misc_itempool_free(pool_nscb, nscb, sizeof(struct nscallback)); - asmsg->type = AMI_S_RUN; - asmsg->callback = callback; - asmsg->p = p; + callback(p); -#ifndef AMIGA_NS_ASYNC - schedule_run(asmsg); - FreeVec(asmsg); -#else - PutMsg(nsmsgport, (struct Message *)asmsg); -#endif return; } -static struct MsgPort *ami_schedule_open_timer(struct MsgPort *msgport) +static void ami_schedule_open_timer(struct MsgPort *msgport) { - if(msgport == NULL) { - msgport = AllocSysObjectTags(ASOT_PORT, - ASO_NoTrack, FALSE, - TAG_DONE); - } #ifdef __amigaos4__ tioreq = (struct TimeRequest *)AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_Size,sizeof(struct TimeRequest), @@ -317,104 +266,70 @@ static struct MsgPort *ami_schedule_open_timer(struct MsgPort *msgport) #ifdef __amigaos4__ ITimer = (struct TimerIFace *)GetInterface((struct Library *)TimerBase, "main", 1, NULL); #endif - return msgport; } -static void ami_schedule_close_timer(struct MsgPort *msgport) +static void ami_schedule_close_timer(void) { #ifdef __amigaos4__ if(ITimer) DropInterface((struct Interface *)ITimer); #endif CloseDevice((struct IORequest *) tioreq); FreeSysObject(ASOT_IOREQUEST, tioreq); - - /* Will be NULL if the GUI code is allocating/deallocating (no async mode) */ - if(msgport != NULL) FreeSysObject(ASOT_PORT, msgport); } -/** - * Initialise amiga scheduler - * - * \param msgport optional already opened message port - * - * \return true if initialised ok or false on error. - */ -static struct MsgPort *ami_schedule_create(struct MsgPort *msgport) +/* exported interface documented in amiga/schedule.h */ +nserror ami_schedule_create(struct MsgPort *msgport) { - msgport = ami_schedule_open_timer(msgport); + pool_nscb = ami_misc_itempool_create(sizeof(struct nscallback)); + pool_timereq = ami_misc_itempool_create(sizeof(struct TimeRequest)); + + ami_schedule_open_timer(msgport); schedule_list = pblHeapNew(); - if(schedule_list == PBL_ERROR_OUT_OF_MEMORY) return NULL; + if(schedule_list == PBL_ERROR_OUT_OF_MEMORY) return NSERROR_NOMEM; pblHeapSetCompareFunction(schedule_list, ami_schedule_compare); - return msgport; + return NSERROR_OK; } -/** - * Finalise amiga scheduler - * - * \param msgport optional message port to free - */ -static void ami_schedule_free(struct MsgPort *msgport) +/* exported interface 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(msgport); + ami_schedule_close_timer(); + + ami_misc_itempool_delete(pool_timereq); + ami_misc_itempool_delete(pool_nscb); } -static nserror ami_scheduler_schedule(struct ami_schedule_message *asmsg) +/* exported function documented in amiga/schedule.h */ +nserror ami_schedule(int t, void (*callback)(void *p), void *p) { struct nscallback *nscb; if(schedule_list == NULL) return NSERROR_INIT_FAILED; - if (asmsg->t < 0) return schedule_remove(asmsg->callback, asmsg->p); + if(t < 0) return schedule_remove(callback, p); - if ((nscb = ami_schedule_locate(asmsg->callback, asmsg->p, false))) { - return ami_schedule_reschedule(nscb, asmsg->t); + if ((nscb = ami_schedule_locate(callback, p, false))) { + return ami_schedule_reschedule(nscb, t); } nscb = ami_misc_itempool_alloc(pool_nscb, sizeof(struct nscallback)); if(!nscb) return NSERROR_NOMEM; - if (ami_schedule_add_timer_event(nscb, asmsg->t) != NSERROR_OK) + if (ami_schedule_add_timer_event(nscb, t) != NSERROR_OK) return NSERROR_NOMEM; - nscb->callback = asmsg->callback; - nscb->p = asmsg->p; + nscb->callback = callback; + nscb->p = p; pblHeapInsert(schedule_list, nscb); return NSERROR_OK; -} - -/* exported function documented in amiga/schedule.h */ -nserror ami_schedule(int t, void (*callback)(void *p), void *p) -{ - struct ami_schedule_message *asmsg; -#ifndef AMIGA_NS_ASYNC - asmsg = AllocVecTagList(sizeof(struct ami_schedule_message), NULL); -#else - if(smsgport == NULL) return NSERROR_INIT_FAILED; - asmsg = AllocSysObjectTags(ASOT_MESSAGE, - ASOMSG_Size, sizeof(struct ami_schedule_message), - TAG_END); -#endif - - asmsg->type = AMI_S_SCHEDULE; - asmsg->t = t; - asmsg->callback = callback; - asmsg->p = p; - -#ifndef AMIGA_NS_ASYNC - ami_scheduler_schedule(asmsg); - FreeVec(asmsg); -#else - PutMsg(smsgport, (struct Message *)asmsg); -#endif - return NSERROR_OK; } /* exported interface documented in amiga/schedule.h */ @@ -423,7 +338,6 @@ void ami_schedule_handle(struct MsgPort *nsmsgport) /* nsmsgport is the NetSurf message port that the scheduler task * (or timer.device in no-async mode) is sending messages to. */ -#ifndef AMIGA_NS_ASYNC struct TimerRequest *timermsg; while((timermsg = (struct TimerRequest *)GetMsg(nsmsgport))) { @@ -431,169 +345,7 @@ void ami_schedule_handle(struct MsgPort *nsmsgport) * it crashes if we reply after schedule_run has executed. */ ReplyMsg((struct Message *)timermsg); - ami_scheduler_run(NULL); - } -#else - struct ami_schedule_message *asmsg; - - while((asmsg = (struct ami_schedule_message *)GetMsg(nsmsgport))) { - if(asmsg->msg.mn_Node.ln_Type == NT_REPLYMSG) { - /* if it's a reply, free stuff */ - FreeSysObject(ASOT_MESSAGE, asmsg); - } else { - switch(asmsg->type) { - case AMI_S_STARTUP: - smsgport = asmsg->msg.mn_ReplyPort; - break; - - case AMI_S_RUN: - schedule_run(asmsg); - break; - - default: - // unknown message - break; - } - FreeSysObject(ASOT_MESSAGE, asmsg); /* don't reply, just free */ - } - } -#endif -} - -#ifdef AMIGA_NS_ASYNC -static int32 ami_scheduler_process(STRPTR args, int32 length, APTR execbase) -{ - struct Process *proc = (struct Process *)FindTask(NULL); - struct MsgPort *nsmsgport = proc->pr_Task.tc_UserData; - struct MsgPort *schedulermsgport = AllocSysObjectTags(ASOT_PORT, TAG_END); - struct MsgPort *timermsgport = ami_schedule_create(); - bool running = true; - struct TimerRequest *timermsg = NULL; - ULONG schedulesig = 1L << schedulermsgport->mp_SigBit; - ULONG timersig = 1L << timermsgport->mp_SigBit; - uint32 signalmask = schedulesig | timersig; - uint32 signal = 0; - - /* Send a startup message to the message port we were given when we were created. - * This tells NetSurf where to send scheduler events to. */ - - struct ami_schedule_message *asmsg = AllocSysObjectTags(ASOT_MESSAGE, - ASOMSG_Size, sizeof(struct ami_schedule_message), - ASOMSG_ReplyPort, schedulermsgport, - TAG_END); - - asmsg->type = AMI_S_STARTUP; - PutMsg(nsmsgport, (struct Message *)asmsg); - - /* Main loop for this process */ - - while(running) { - signal = Wait(signalmask); - - if(signal & schedulesig) { - while((asmsg = (struct ami_schedule_message *)GetMsg(schedulermsgport))) { - if(asmsg->msg.mn_Node.ln_Type == NT_REPLYMSG) { - /* if it's a reply, free stuff */ - FreeSysObject(ASOT_MESSAGE, asmsg); - } else { - switch(asmsg->type) { - case AMI_S_SCHEDULE: - ami_scheduler_schedule(asmsg); - break; - - case AMI_S_EXIT: - running = false; - break; - - default: - // unknown message - break; - } - FreeSysObject(ASOT_MESSAGE, asmsg); /* don't reply, just free */ - } - } - } - - if(signal & timersig) { - while((timermsg = (struct TimerRequest *)GetMsg(timermsgport))) { - /* reply first, as we don't need the message contents and - * it crashes if we reply after schedule_run has executed. - */ - ReplyMsg((struct Message *)timermsg); - ami_scheduler_run(nsmsgport); - } - } - } - - ami_schedule_free(timermsgport); - FreeSysObject(ASOT_PORT, schedulermsgport); - - return RETURN_OK; -} -#endif - -/** - * Create a new process for the scheduler. - * - * \param nsmsgport Message port to send scheduler events to. - * \return NSERROR_OK on success or error code on faliure. - */ -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 - ami_schedule_create(nsmsgport); -#else - if(nsmsgport == NULL) return NSERROR_INIT_FAILED; - - struct Process *proc = CreateNewProcTags( - NP_Name, "NetSurf scheduler", - NP_Entry, ami_scheduler_process, - NP_Child, TRUE, - NP_StackSize, 2048, - NP_Priority, 1, - NP_UserData, nsmsgport, - TAG_DONE); - - if(proc == NULL) { - return NSERROR_NOMEM; + ami_scheduler_run(); } - - LOG("Waiting for scheduler process to start up..."); - - WaitPort(nsmsgport); - struct ami_schedule_message *asmsg = (struct ami_schedule_message *)GetMsg(nsmsgport); - - if(asmsg->type == AMI_S_STARTUP) { /* We shouldn't get any other messages at this stage */ - smsgport = asmsg->msg.mn_ReplyPort; - ReplyMsg((struct Message *)asmsg); - } -#endif - LOG("Scheduler started"); - - return NSERROR_OK; -} - -/* exported function documented in amiga/schedule.h */ -void ami_scheduler_process_delete(void) -{ -#ifndef AMIGA_NS_ASYNC - ami_schedule_free(NULL); -#else - if(smsgport == NULL) return; - - struct ami_schedule_message *asmsg = AllocSysObjectTags(ASOT_MESSAGE, - ASOMSG_Size, sizeof(struct ami_schedule_message), - TAG_END); - - asmsg->type = AMI_S_EXIT; - PutMsg(smsgport, (struct Message *)asmsg); - smsgport = NULL; /* this is freed via another copy of this pointer */ -#endif - - ami_misc_itempool_delete(pool_timereq); - ami_misc_itempool_delete(pool_nscb); } -- cgit v1.2.3