diff --git a/amiga/fs_backing_store.c b/amiga/fs_backing_store.c deleted file mode 100644 index 9e7672eb1..000000000 --- a/amiga/fs_backing_store.c +++ /dev/null @@ -1,393 +0,0 @@ -/* - * Copyright 2014 Chris Young - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include "content/fs_backing_store.c" - -#ifdef AMIGA_NS_ASYNC -struct ami_bsm_store { - nsurl *url; - enum backing_store_flags flags; - uint8_t *data; - size_t datalen; -}; - -struct ami_bsm_fetch { - nsurl *url; - enum backing_store_flags bsflags; - uint8_t **data_out; - size_t *datalen_out; -}; - -struct ami_bsm_invalidate { - nsurl *url; -}; - -struct ami_bsm_release { - nsurl *url; - enum backing_store_flags bsflags; -}; - -struct ami_backing_store { - struct MsgPort *msgport; - struct llcache_store_parameters *parameters; -}; - -struct ami_backing_store_msg { - struct Message msg; - int type; - nserror error; - void *data; -}; - -enum { - AMI_BSM_STARTUP = 0, - AMI_BSM_STORE, - AMI_BSM_FETCH, - AMI_BSM_INVALIDATE, - AMI_BSM_RELEASE, - AMI_BSM_FINALISE -}; - -struct MsgPort *cachemsgport = NULL; - -static int32 ami_backing_store_process(STRPTR args, int32 length, APTR execbase) -{ - struct Process *proc = (struct Process *)FindTask(NULL); - struct ami_backing_store *abs = proc->pr_Task.tc_UserData; - struct MsgPort *nsmsgport = abs->msgport; - struct MsgPort *backingstoremsgport = AllocSysObjectTags(ASOT_PORT, TAG_END); - bool running = true; - - nserror error = filesystem_llcache_table->initialise(abs->parameters); - - /* Send a startup message to the message port we were given when we were created. - * This tells NetSurf where to send disk cache messages to, as well as informing - * that we are running. - */ - - struct ami_backing_store_msg *absmsg = AllocSysObjectTags(ASOT_MESSAGE, - ASOMSG_Size, sizeof(struct ami_backing_store_msg), - ASOMSG_ReplyPort, backingstoremsgport, - TAG_END); - - absmsg->type = AMI_BSM_STARTUP; - absmsg->error = error; - - PutMsg(nsmsgport, (struct Message *)absmsg); - - /* Main loop for this process */ - - while(running) { - WaitPort(backingstoremsgport); - - while((absmsg = (struct ami_backing_store_msg *)GetMsg(backingstoremsgport))) { - if(absmsg->msg.mn_Node.ln_Type == NT_REPLYMSG) { - /* if it's a reply, free stuff */ - FreeSysObject(ASOT_MESSAGE, absmsg); - } else { - if(running) { - switch(absmsg->type) { - case AMI_BSM_STORE: - { - struct ami_bsm_store *absm = absmsg->data; - absmsg->error = filesystem_llcache_table->store(absm->url, absm->flags, absm->data, absm->datalen); - FreeVec(absm); - FreeSysObject(ASOT_MESSAGE, absmsg); /* don't reply, just free */ - } - break; - - case AMI_BSM_FETCH: - { - struct ami_bsm_fetch *absm = absmsg->data; - absmsg->error = filesystem_llcache_table->fetch(absm->url, absm->bsflags, absm->data_out, absm->datalen_out); - ReplyMsg((struct Message *)absmsg); /* need to reply to this one */ - } - break; - - case AMI_BSM_INVALIDATE: - { - struct ami_bsm_invalidate *absm = absmsg->data; - absmsg->error = filesystem_llcache_table->invalidate(absm->url); - FreeVec(absm); - FreeSysObject(ASOT_MESSAGE, absmsg); /* don't reply, just free */ - } - break; - - case AMI_BSM_RELEASE: - { - struct ami_bsm_release *absm = absmsg->data; - absmsg->error = filesystem_llcache_table->release(absm->url, absm->bsflags); - FreeVec(absm); - FreeSysObject(ASOT_MESSAGE, absmsg); /* don't reply, just free */ - } - break; - - case AMI_BSM_FINALISE: - running = false; - absmsg->error = filesystem_llcache_table->finalise(); - ReplyMsg((struct Message *)absmsg); /* need to reply to this one */ - break; - - default: - // unknown message - FreeSysObject(ASOT_MESSAGE, absmsg); /* don't reply, just free */ - break; - } - } - } - } - } - - FreeSysObject(ASOT_PORT, backingstoremsgport); - - return RETURN_OK; -} - -static nserror ami_backing_store_send_reply(int type, void *data, struct MsgPort *msgport) -{ - if(cachemsgport == NULL) return NSERROR_INIT_FAILED; - - struct ami_backing_store_msg *absmsg = AllocSysObjectTags(ASOT_MESSAGE, - ASOMSG_Size, sizeof(struct ami_backing_store_msg), - ASOMSG_ReplyPort, msgport, - TAG_END); - - absmsg->type = type; - absmsg->data = data; - - PutMsg(cachemsgport, (struct Message *)absmsg); - - return NSERROR_OK; -} - -static nserror ami_backing_store_send(int type, void *data) -{ - return ami_backing_store_send_reply(type, data, NULL); -} - -/** - * Place an object in the backing store. - * - * @param url The url is used as the unique primary key for the data. - * @param flags The flags to control how the object is stored. - * @param data The objects source data. - * @param datalen The length of the \a data. - * @return NSERROR_OK on success or error code on faliure. - */ -static nserror -ami_backing_store_store(nsurl *url, - enum backing_store_flags flags, - uint8_t *data, - const size_t datalen) -{ - struct ami_bsm_store *absm = - AllocVecTagList(sizeof(struct ami_bsm_store), NULL); - - if(absm == NULL) return NSERROR_NOMEM; - - absm->url = url; - absm->flags = flags; - absm->data = data; - absm->datalen = datalen; - - return ami_backing_store_send(AMI_BSM_STORE, absm); -} - -/** - * Retrive an object from the backing store. - * - * @param[in] url The url is used as the unique primary key for the data. - * @param[in] bsflags The flags to control how the object is retrieved. - * @param[out] data_out The objects data. - * @param[out] datalen_out The length of the \a data retrieved. - * @return NSERROR_OK on success or error code on faliure. - */ -static nserror ami_backing_store_fetch(nsurl *url, - enum backing_store_flags bsflags, - uint8_t **data_out, - size_t *datalen_out) -{ - struct MsgPort *tempmsgport = AllocSysObjectTags(ASOT_PORT, TAG_END); - if(tempmsgport == NULL) return NSERROR_NOMEM; - - struct ami_bsm_fetch *absm = - AllocVecTagList(sizeof(struct ami_bsm_fetch), NULL); - if(absm == NULL) return NSERROR_NOMEM; - - absm->url = url; - absm->bsflags = bsflags; - absm->data_out = data_out; - absm->datalen_out = datalen_out; - - nserror error = ami_backing_store_send_reply(AMI_BSM_FETCH, absm, tempmsgport); - if(error != NSERROR_OK) return error; - - WaitPort(tempmsgport); - - struct ami_backing_store_msg *absmsg = (struct ami_backing_store_msg *)GetMsg(tempmsgport); - error = absmsg->error; - - FreeVec(absm); - FreeSysObject(ASOT_MESSAGE, absmsg); - FreeSysObject(ASOT_PORT, tempmsgport); - - return error; -} - - -/** - * release a previously fetched or stored memory object. - * - * @param[in] url The url is used as the unique primary key to invalidate. - * @param[in] bsflags The flags to control how the object data is released. - * @return NSERROR_OK on success or error code on faliure. - */ -static nserror ami_backing_store_release(nsurl *url, enum backing_store_flags bsflags) -{ - struct ami_bsm_release *absm = - AllocVecTagList(sizeof(struct ami_bsm_release), NULL); - - if(absm == NULL) return NSERROR_NOMEM; - - absm->url = url; - absm->bsflags = bsflags; - - return ami_backing_store_send(AMI_BSM_RELEASE, absm); -} - -/** - * Invalidate a source object from the backing store. - * - * The entry (if present in the backing store) must no longer - * be returned as a result to the fetch or meta operations. - * - * @param url The url is used as the unique primary key to invalidate. - * @return NSERROR_OK on success or error code on faliure. - */ -static nserror ami_backing_store_invalidate(nsurl *url) -{ - struct ami_bsm_store *absm = - AllocVecTagList(sizeof(struct ami_bsm_invalidate), NULL); - - if(absm == NULL) return NSERROR_NOMEM; - - absm->url = url; - - return ami_backing_store_send(AMI_BSM_INVALIDATE, absm); -} - -/** - * Finalise the backing store. - * - * \todo This will cause the backing store to leak any outstanding memory - * allocations. This will probably best be done by a global use count. - * - * @return NSERROR_OK on success. - */ -static nserror ami_backing_store_finalise(void) -{ - struct MsgPort *tempmsgport = AllocSysObjectTags(ASOT_PORT, TAG_END); - if(tempmsgport == NULL) return NSERROR_NOMEM; - - nserror error = ami_backing_store_send_reply(AMI_BSM_FINALISE, NULL, tempmsgport); - if(error != NSERROR_OK) return error; - - LOG("Waiting for backing store process to exit..."); - - WaitPort(tempmsgport); - - struct ami_backing_store_msg *absmsg = (struct ami_backing_store_msg *)GetMsg(tempmsgport); - error = absmsg->error; - - FreeSysObject(ASOT_MESSAGE, absmsg); - FreeSysObject(ASOT_PORT, tempmsgport); - cachemsgport = NULL; - - return error; -} - - -/** - * Initialise the backing store. - * - * @param parameters to configure backing store. - * @return NSERROR_OK on success or error code on faliure. - */ -static nserror -ami_backing_store_initialise(const struct llcache_store_parameters *parameters) -{ - struct MsgPort *tempmsgport = AllocSysObjectTags(ASOT_PORT, TAG_END); - struct ami_backing_store *abs = - AllocVecTagList(sizeof(struct ami_backing_store), NULL); - if(abs == NULL) return NSERROR_NOMEM; - - abs->msgport = tempmsgport; - abs->parameters = (struct llcache_store_parameters *)parameters; - - struct Process *proc = CreateNewProcTags( - NP_Name, "NetSurf backing store", - NP_Entry, ami_backing_store_process, - NP_Child, TRUE, - NP_StackSize, 16384, - NP_Priority, -1, - NP_UserData, abs, - TAG_DONE); - - if(proc == NULL) { - return NSERROR_NOMEM; - } - - LOG("Waiting for backing store process to start up..."); - - WaitPort(tempmsgport); - - struct ami_backing_store_msg *msg = (struct ami_backing_store_msg *)GetMsg(tempmsgport); - cachemsgport = msg->msg.mn_ReplyPort; - nserror error = msg->error; - ReplyMsg((struct Message *)msg); - FreeSysObject(ASOT_PORT, tempmsgport); - - LOG("Backing store process started. Error code: %d", error); - - return error; -} -#endif - -static struct gui_llcache_table amiga_llcache_table = { -#ifndef AMIGA_NS_ASYNC - .initialise = initialise, - .finalise = finalise, - .store = store, - .fetch = fetch, - .invalidate = invalidate, - .release = release, -#else - .initialise = ami_backing_store_initialise, - .finalise = ami_backing_store_finalise, - .store = ami_backing_store_store, - .fetch = ami_backing_store_fetch, - .invalidate = ami_backing_store_invalidate, - .release = ami_backing_store_release, -#endif -}; - -struct gui_llcache_table *amiga_filesystem_llcache_table = &amiga_llcache_table; - diff --git a/amiga/fs_backing_store.h b/amiga/fs_backing_store.h deleted file mode 100644 index 45aa39578..000000000 --- a/amiga/fs_backing_store.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2014 Chris Young - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef AMIGA_FS_BACKING_STORE_H -#define AMIGA_FS_BACKING_STORE_H -extern struct gui_llcache_table *amiga_filesystem_llcache_table; -extern struct gui_llcache_table *filesystem_llcache_table; -#endif - diff --git a/amiga/gui.c b/amiga/gui.c index 09fc36b6a..58e7938fd 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -95,6 +95,7 @@ #include "utils/utils.h" #include "utils/nsurl.h" #include "utils/file.h" +#include "content/backing_store.h" #include "content/fetchers.h" #include "content/fetchers/resource.h" #include "content/urldb.h" @@ -127,7 +128,6 @@ #include "amiga/file.h" #include "amiga/filetype.h" #include "amiga/font.h" -#include "amiga/fs_backing_store.h" #include "amiga/gui_options.h" #include "amiga/help.h" #include "amiga/history.h" @@ -3031,8 +3031,8 @@ static void gui_quit(void) ami_mouse_pointers_free(); LOG("Freeing clipboard"); ami_clipboard_free(); - LOG("Removing scheduler process"); - ami_scheduler_process_delete(); + LOG("Freeing scheduler resources"); + ami_schedule_free(); FreeSysObject(ASOT_PORT, appport); FreeSysObject(ASOT_PORT, sport); @@ -5504,7 +5504,7 @@ int main(int argc, char** argv) return RETURN_FAIL; } - if(ami_scheduler_process_create(schedulermsgport) != NSERROR_OK) { + if(ami_schedule_create(schedulermsgport) != NSERROR_OK) { ami_misc_fatal_error("Failed to initialise scheduler"); ami_gui_splash_close(splash_window); ami_libs_close(); @@ -5524,7 +5524,7 @@ int main(int argc, char** argv) users_dir = ASPrintf("%s", USERS_DIR); if(users_dir == NULL) { ami_misc_fatal_error("Failed to allocate memory"); - ami_scheduler_process_delete(); + ami_schedule_free(); ami_gui_splash_close(splash_window); ami_libs_close(); return RETURN_FAIL; @@ -5536,7 +5536,7 @@ int main(int argc, char** argv) struct InfoData *infodata = AllocDosObject(DOS_INFODATA, 0); if(infodata == NULL) { ami_misc_fatal_error("Failed to allocate memory"); - ami_scheduler_process_delete(); + ami_schedule_free(); ami_gui_splash_close(splash_window); ami_libs_close(); return RETURN_FAIL; @@ -5547,7 +5547,7 @@ int main(int argc, char** argv) if(infodata->id_DiskState == ID_DISKSTATE_WRITE_PROTECTED) { FreeDosObject(DOS_INFODATA, infodata); ami_misc_fatal_error("User directory MUST be on a writeable volume"); - ami_scheduler_process_delete(); + ami_schedule_free(); ami_gui_splash_close(splash_window); ami_libs_close(); return RETURN_FAIL; @@ -5567,7 +5567,7 @@ int main(int argc, char** argv) current_user_dir = AllocVecTagList(len, NULL); if(current_user_dir == NULL) { ami_misc_fatal_error("Failed to allocate memory"); - ami_scheduler_process_delete(); + ami_schedule_free(); ami_gui_splash_close(splash_window); ami_libs_close(); return RETURN_FAIL; @@ -5605,7 +5605,7 @@ int main(int argc, char** argv) ret = nsoption_init(ami_set_options, &nsoptions, &nsoptions_default); if (ret != NSERROR_OK) { ami_misc_fatal_error("Options failed to initialise"); - ami_scheduler_process_delete(); + ami_schedule_free(); ami_gui_splash_close(splash_window); ami_libs_close(); return RETURN_FAIL; @@ -5618,7 +5618,7 @@ int main(int argc, char** argv) if (ami_locate_resource(messages, "Messages") == false) { ami_misc_fatal_error("Cannot open Messages file"); - ami_scheduler_process_delete(); + ami_schedule_free(); ami_gui_splash_close(splash_window); ami_libs_close(); return RETURN_FAIL; @@ -5629,7 +5629,7 @@ int main(int argc, char** argv) ret = netsurf_init(current_user_cache); if (ret != NSERROR_OK) { ami_misc_fatal_error("NetSurf failed to initialise"); - ami_scheduler_process_delete(); + ami_schedule_free(); ami_gui_splash_close(splash_window); ami_libs_close(); return RETURN_FAIL; 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(); -static nserror ami_scheduler_schedule(struct ami_schedule_message *asmsg) -{ - struct nscallback *nscb; - - if(schedule_list == NULL) return NSERROR_INIT_FAILED; - if (asmsg->t < 0) return schedule_remove(asmsg->callback, asmsg->p); - - if ((nscb = ami_schedule_locate(asmsg->callback, asmsg->p, false))) { - return ami_schedule_reschedule(nscb, asmsg->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) - return NSERROR_NOMEM; - - nscb->callback = asmsg->callback; - nscb->p = asmsg->p; - - pblHeapInsert(schedule_list, nscb); - - return NSERROR_OK; + ami_misc_itempool_delete(pool_timereq); + ami_misc_itempool_delete(pool_nscb); } /* exported function documented in amiga/schedule.h */ nserror ami_schedule(int t, void (*callback)(void *p), void *p) { - struct ami_schedule_message *asmsg; + struct nscallback *nscb; -#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 + if(schedule_list == NULL) return NSERROR_INIT_FAILED; + if(t < 0) return schedule_remove(callback, p); - asmsg->type = AMI_S_SCHEDULE; - asmsg->t = t; - asmsg->callback = callback; - asmsg->p = p; + 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, t) != NSERROR_OK) + return NSERROR_NOMEM; + + nscb->callback = callback; + nscb->p = p; + + pblHeapInsert(schedule_list, nscb); -#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); + ami_scheduler_run(); } -#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; - } - - 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); } diff --git a/amiga/schedule.h b/amiga/schedule.h index cfea4d917..fb648eaa4 100755 --- a/amiga/schedule.h +++ b/amiga/schedule.h @@ -41,16 +41,17 @@ nserror ami_schedule(int t, void (*callback)(void *p), void *p); void ami_schedule_handle(struct MsgPort *nsmsgport); /** - * Create a new process for the scheduler. + * Initialise amiga scheduler * - * \param nsmsgport Message port for the scheduler to send events to. - * \return NSERROR_OK on success or error code on failure. + * \param msgport opened message port + * + * \return error. */ -nserror ami_scheduler_process_create(struct MsgPort *nsmsgport); +nserror ami_schedule_create(struct MsgPort *msgport); /** - * Signal the scheduler process to exit. + * Finalise amiga scheduler */ -void ami_scheduler_process_delete(void); +void ami_schedule_free(void); #endif