diff options
Diffstat (limited to 'amiga')
-rwxr-xr-x | amiga/font.c | 6 | ||||
-rw-r--r-- | amiga/gui.c | 11 | ||||
-rw-r--r-- | amiga/menu.c | 9 | ||||
-rwxr-xr-x | amiga/schedule.c | 160 | ||||
-rwxr-xr-x | amiga/schedule.h | 38 | ||||
-rw-r--r-- | amiga/tree.c | 6 |
6 files changed, 140 insertions, 90 deletions
diff --git a/amiga/font.c b/amiga/font.c index 3430a4ea3..df4a18862 100755 --- a/amiga/font.c +++ b/amiga/font.c @@ -23,12 +23,12 @@ #include "amiga/gui.h" #include "amiga/utf8.h" #include "amiga/object.h" +#include "amiga/schedule.h" #include "utils/nsoption.h" #include "css/css.h" #include "css/utils.h" #include "render/font.h" #include "utils/log.h" -#include "utils/schedule.h" #include "utils/utf8.h" #include "utils/utils.h" @@ -831,7 +831,7 @@ void ami_init_fonts(void) NewList(&ami_diskfontlib_list); /* run first cleanup in ten minutes */ - schedule(60000, (schedule_callback_fn)ami_font_cleanup, ami_font_list); + ami_schedule(600000, ami_font_cleanup, ami_font_list); } void ami_close_fonts(void) @@ -875,7 +875,7 @@ static void ami_font_cleanup(struct MinList *ami_font_list) }while(node=nnode); /* reschedule to run in five minutes */ - schedule(30000, (schedule_callback_fn)ami_font_cleanup, ami_font_list); + ami_schedule(300000, ami_font_cleanup, ami_font_list); } void ami_font_setdevicedpi(int id) diff --git a/amiga/gui.c b/amiga/gui.c index aedb26c56..84e9dc98c 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -2538,7 +2538,7 @@ static void ami_gui_fetch_callback(void *p) static void gui_poll(bool active) { - if(active) schedule(0, ami_gui_fetch_callback, NULL); + if(active) ami_schedule(0, ami_gui_fetch_callback, NULL); ami_get_msg(); } @@ -4050,19 +4050,19 @@ static void ami_redraw_callback(void *p) */ void ami_schedule_redraw(struct gui_window_2 *gwin, bool full_redraw) { - int cs = 0; + int ms = 0; if(full_redraw) gwin->redraw_required = true; if(gwin->redraw_scheduled == true) return; - if(gwin->bw->reformat_pending) cs = nsoption_int(reformat_delay); - schedule(cs, ami_redraw_callback, gwin); + if(gwin->bw->reformat_pending) ms = nsoption_int(reformat_delay) * 10; + ami_schedule(ms, ami_redraw_callback, gwin); gwin->redraw_scheduled = true; } static void ami_schedule_redraw_remove(struct gui_window_2 *gwin) { - schedule_remove(ami_redraw_callback, gwin); + ami_schedule(-1, ami_redraw_callback, gwin); } static void ami_do_redraw_tiled(struct gui_window_2 *gwin, bool busy, @@ -5133,6 +5133,7 @@ static struct gui_fetch_table amiga_fetch_table = { static struct gui_browser_table amiga_browser_table = { .poll = gui_poll, + .schedule = ami_schedule, .quit = gui_quit, .set_search_ico = gui_set_search_ico, diff --git a/amiga/menu.c b/amiga/menu.c index 2c019bd9e..9cb857e9d 100644 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -58,12 +58,13 @@ #include "amiga/theme.h" #include "amiga/tree.h" #include "amiga/utf8.h" +#include "amiga/schedule.h" #include "desktop/hotlist.h" #include "desktop/browser_private.h" #include "desktop/gui.h" #include "desktop/textinput.h" #include "utils/messages.h" -#include "utils/schedule.h" + enum { NSA_GLYPH_SUBMENU, @@ -481,7 +482,11 @@ struct NewMenu *ami_create_menu(struct gui_window_2 *gwin) /* Set up scheduler to refresh the hotlist menu */ if(nsoption_int(menu_refresh) > 0) - schedule(nsoption_int(menu_refresh), (void *)ami_menu_refresh, gwin); + { + ami_schedule(nsoption_int(menu_refresh) * 10, + ami_menu_refresh, + gwin); + } return(gwin->menu); } diff --git a/amiga/schedule.c b/amiga/schedule.c index d4b35a509..4ec9df7e9 100755 --- a/amiga/schedule.c +++ b/amiga/schedule.c @@ -16,7 +16,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "utils/schedule.h" #include "amiga/os3support.h" #include "amiga/schedule.h" @@ -37,51 +36,18 @@ struct nscallback PblHeap *schedule_list; -void ami_remove_timer_event(struct nscallback *nscb); - -/** - * Schedule a callback. - * - * \param t interval before the callback should be made / cs - * \param callback callback function - * \param p user parameter, passed to callback function - * - * The callback function will be called as soon as possible after t cs have - * passed. - */ - -void schedule(int t, void (*callback)(void *p), void *p) +static void ami_remove_timer_event(struct nscallback *nscb) { - struct nscallback *nscb; - struct TimeVal tv; - ULONG time_us = 0; - - if(schedule_list == NULL) return; - - nscb = AllocVecTagList(sizeof(struct nscallback), NULL); if(!nscb) return; - time_us = t*10000; /* t converted to µs */ - - nscb->tv.Seconds = time_us / 1000000; - nscb->tv.Microseconds = time_us % 1000000; - - GetSysTime(&tv); - AddTime(&nscb->tv,&tv); // now contains time when event occurs - - if(nscb->treq = AllocVecTagList(sizeof(struct TimeRequest), NULL)) + if(nscb->treq) { - *nscb->treq = *tioreq; - nscb->treq->Request.io_Command=TR_ADDREQUEST; - nscb->treq->Time.Seconds=nscb->tv.Seconds; // secs - nscb->treq->Time.Microseconds=nscb->tv.Microseconds; // micro - SendIO((struct IORequest *)nscb->treq); - } - - nscb->callback = callback; - nscb->p = p; + if(CheckIO((struct IORequest *)nscb->treq)==NULL) + AbortIO((struct IORequest *)nscb->treq); - pblHeapInsert(schedule_list, nscb); + WaitIO((struct IORequest *)nscb->treq); + FreeVec(nscb->treq); + } } /** @@ -93,14 +59,22 @@ void schedule(int t, void (*callback)(void *p), void *p) * All scheduled callbacks matching both callback and p are removed. */ -void schedule_remove(void (*callback)(void *p), void *p) +static nserror schedule_remove(void (*callback)(void *p), void *p) { PblIterator *iterator; struct nscallback *nscb; bool restoreheap = false; - if(schedule_list == NULL) return; - if(pblHeapIsEmpty(schedule_list)) return; + /* check there is something on the list to remove */ + if (schedule_list == NULL) + { + return NSERROR_OK; + } + + if(pblHeapIsEmpty(schedule_list)) + { + return NSERROR_OK; + } iterator = pblHeapIterator(schedule_list); @@ -117,10 +91,15 @@ void schedule_remove(void (*callback)(void *p), void *p) pblIteratorFree(iterator); - if(restoreheap) pblHeapConstruct(schedule_list); + if(restoreheap) + { + pblHeapConstruct(schedule_list); + } + + return NSERROR_OK; } -void schedule_remove_all(void) +static void schedule_remove_all(void) { PblIterator *iterator; struct nscallback *nscb; @@ -139,13 +118,16 @@ void schedule_remove_all(void) pblIteratorFree(iterator); } -/** - * Process events up to current time. - * This implementation only takes the top entry off the heap, it does not - * venture to later scheduled events until the next time it is called - - * immediately afterwards, if we're in a timer signalled loop. - */ +static int ami_schedule_compare(const void *prev, const void *next) +{ + struct nscallback *nscb1 = *(struct nscallback **)prev; + struct nscallback *nscb2 = *(struct nscallback **)next; + + return CmpTime(&nscb1->tv, &nscb2->tv); +} + +/* exported function documented in amiga/schedule.h */ void schedule_run(BOOL poll) { struct nscallback *nscb; @@ -176,28 +158,7 @@ void schedule_run(BOOL poll) callback(p); } -void ami_remove_timer_event(struct nscallback *nscb) -{ - if(!nscb) return; - - if(nscb->treq) - { - if(CheckIO((struct IORequest *)nscb->treq)==NULL) - AbortIO((struct IORequest *)nscb->treq); - - WaitIO((struct IORequest *)nscb->treq); - FreeVec(nscb->treq); - } -} - -int ami_schedule_compare(const void *prev, const void *next) -{ - struct nscallback *nscb1 = *(struct nscallback **)prev; - struct nscallback *nscb2 = *(struct nscallback **)next; - - return CmpTime(&nscb1->tv, &nscb2->tv); -} - +/* exported function documented in amiga/schedule.h */ BOOL ami_schedule_create(void) { schedule_list = pblHeapNew(); @@ -206,6 +167,7 @@ BOOL ami_schedule_create(void) pblHeapSetCompareFunction(schedule_list, ami_schedule_compare); } +/* exported function documented in amiga/schedule.h */ void ami_schedule_free(void) { schedule_remove_all(); @@ -213,6 +175,7 @@ void ami_schedule_free(void) schedule_list = NULL; } +/* exported function documented in amiga/schedule.h */ void ami_schedule_open_timer(void) { msgport = AllocSysObjectTags(ASOT_PORT, @@ -231,6 +194,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) { if(ITimer) @@ -242,3 +206,51 @@ void ami_schedule_close_timer(void) FreeSysObject(ASOT_IOREQUEST,tioreq); FreeSysObject(ASOT_PORT,msgport); } + +/* exported function documented in amiga/schedule.h */ +nserror ami_schedule(int t, void (*callback)(void *p), void *p) +{ + struct nscallback *nscb; + struct TimeVal tv; + ULONG time_us = 0; + + if(schedule_list == NULL) + { + return NSERROR_INIT_FAILED; + } + + if(t < 0) + { + return schedule_remove(callback, p); + } + + nscb = AllocVecTagList(sizeof(struct nscallback), NULL); + if(!nscb) + { + return NSERROR_NOMEM; + } + + time_us = t * 1000; /* t converted to µs */ + + nscb->tv.Seconds = time_us / 1000000; + nscb->tv.Microseconds = time_us % 1000000; + + GetSysTime(&tv); + AddTime(&nscb->tv,&tv); // now contains time when event occurs + + 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 + nscb->treq->Time.Microseconds=nscb->tv.Microseconds; // micro + SendIO((struct IORequest *)nscb->treq); + } + + nscb->callback = callback; + nscb->p = p; + + pblHeapInsert(schedule_list, nscb); + + return NSERROR_OK; +} diff --git a/amiga/schedule.h b/amiga/schedule.h index 3eddc8913..659230627 100755 --- a/amiga/schedule.h +++ b/amiga/schedule.h @@ -19,7 +19,6 @@ #ifndef AMIGA_SCHEDULE_H #define AMIGA_SCHEDULE_H #include <proto/timer.h> -#include "utils/schedule.h" #include "amiga/os3support.h" struct Device *TimerBase; @@ -28,9 +27,42 @@ struct TimerIFace *ITimer; struct TimeRequest *tioreq; struct MsgPort *msgport; -void ami_schedule_open_timer(void); -void ami_schedule_close_timer(void); +/** + * Schedule a callback. + * + * \param t interval before the callback should be made / ms + * \param callback callback function + * \param p user parameter, passed to callback function + * \return NSERROR_OK on sucess or appropriate error on faliure + * + * The callback function will be called as soon as possible after t ms have + * passed. + */ +nserror ami_schedule(int t, void (*callback)(void *p), void *p); + +/** + * Initialise amiga scheduler + * + * /return true if initialised ok or false on error. + */ BOOL ami_schedule_create(void); + +/** + * Finalise amiga scheduler + * + */ void ami_schedule_free(void); + +/** + * Process events up to current time. + * + * This implementation only takes the top entry off the heap, it does not + * venture to later scheduled events until the next time it is called - + * immediately afterwards, if we're in a timer signalled loop. + */ void schedule_run(BOOL poll); + +void ami_schedule_open_timer(void); +void ami_schedule_close_timer(void); + #endif diff --git a/amiga/tree.c b/amiga/tree.c index 8cffdb214..fa1252831 100644 --- a/amiga/tree.c +++ b/amiga/tree.c @@ -1390,11 +1390,11 @@ void ami_tree_redraw_request(int x, int y, int width, int height, void *data) atrr_data->height = height; atrr_data->twin = (struct treeview_window *)data; - /**TODO: Queue these requests properly like the main browser code does + /** /todo Queue these requests properly like the main browser code does **/ if(nsoption_bool(direct_render) == false) - schedule(0, ami_tree_redraw_req, atrr_data); + ami_schedule(0, ami_tree_redraw_req, atrr_data); else - schedule(0, ami_tree_redraw_req_dr, atrr_data); + am_schedule(0, ami_tree_redraw_req_dr, atrr_data); } |