X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fhelper%2Fjim-eventloop.c;h=fae46e899e7dda40951db1f5012faed8c93f1d69;hb=3c8a0e72f38e47bfc78dc7ab44ce2ec16cfac53b;hp=7858842afaa2fbb82f8d15c016aa42103c9d0483;hpb=1d5623919bcafc2add41f6c67ce6c5fcc7ecc3d3;p=openocd.git diff --git a/src/helper/jim-eventloop.c b/src/helper/jim-eventloop.c index 7858842afa..fae46e899e 100644 --- a/src/helper/jim-eventloop.c +++ b/src/helper/jim-eventloop.c @@ -2,25 +2,25 @@ * * Copyright 2005 Salvatore Sanfilippo * Copyright 2005 Clemens Hintze - * Copyright 2005 patthoyts - Pat Thoyts - * Copyright 2008 oharboe - Øyvind Harboe - oyvind.harboe@zylin.com + * Copyright 2005 patthoyts - Pat Thoyts + * Copyright 2008 oharboe - Øyvind Harboe - oyvind.harboe@zylin.com * Copyright 2008 Andrew Lunn * Copyright 2008 Duane Ellis * Copyright 2008 Uwe Klein - * + * * The FreeBSD license - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A @@ -33,7 +33,7 @@ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation * are those of the authors and should not be interpreted as representing * official policies, either expressed or implied, of the Jim Tcl Project. @@ -44,13 +44,15 @@ * - more complete [after] command with [after info] and other subcommands. * - Win32 port */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #define JIM_EXTENSION #define __JIM_EVENTLOOP_CORE__ #ifdef __ECOS #include -#endif -#ifdef __ECOS +#include #include #include #else @@ -58,19 +60,10 @@ #include "jim-eventloop.h" #endif -/* POSIX includes */ -#include -#include -#include -#include -#include - extern int errno; -/* --- */ - /* File event structure */ typedef struct Jim_FileEvent { void *handle; - int mask; /* one of JIM_EVENT_(READABLE|WRITABLE|EXCEPTION) */ + int mask; /* one of JIM_EVENT_(READABLE | WRITABLE | EXCEPTION) */ Jim_FileProc *fileProc; Jim_EventFinalizerProc *finalizerProc; void *clientData; @@ -122,7 +115,7 @@ void Jim_DeleteFileHandler(Jim_Interp *interp, void *handle) Jim_EventLoop *eventLoop = Jim_GetAssocData(interp, "eventloop"); fe = eventLoop->fileEventHead; - while(fe) { + while (fe) { if (fe->handle == handle) { if (prev == NULL) eventLoop->fileEventHead = fe->next; @@ -139,12 +132,12 @@ void Jim_DeleteFileHandler(Jim_Interp *interp, void *handle) } // The same for signals. -void Jim_CreateSignalHandler(Jim_Interp *interp, int signum, +void Jim_CreateSignalHandler(Jim_Interp *interp, int signum, Jim_FileProc *proc, void *clientData, Jim_EventFinalizerProc *finalizerProc) { } -void Jim_DeleteSignalHandler(Jim_Interp *interp, int signum) +void Jim_DeleteSignalHandler(Jim_Interp *interp, int signum) { } @@ -198,9 +191,9 @@ jim_wide Jim_DeleteTimeHandler(Jim_Interp *interp, jim_wide id) JimGetTime(&cur_sec, &cur_ms); te = eventLoop->timeEventHead; - if (id >= eventLoop->timeEventNextId) + if (id >= eventLoop->timeEventNextId) return -2; /* wrong event ID */ - while(te) { + while (te) { if (te->id == id) { remain = (te->when_sec - cur_sec) * 1000; remain += (te->when_ms - cur_ms) ; @@ -230,7 +223,7 @@ static Jim_TimeEvent *JimSearchNearestTimer(Jim_EventLoop *eventLoop) Jim_TimeEvent *te = eventLoop->timeEventHead; Jim_TimeEvent *nearest = NULL; - while(te) { + while (te) { if (!nearest || te->when_sec < nearest->when_sec || (te->when_sec == nearest->when_sec && te->when_ms < nearest->when_ms)) @@ -240,6 +233,12 @@ static Jim_TimeEvent *JimSearchNearestTimer(Jim_EventLoop *eventLoop) return nearest; } +/* --- POSIX version of Jim_ProcessEvents, for now the only available --- */ +#define JIM_FILE_EVENTS 1 +#define JIM_TIME_EVENTS 2 +#define JIM_ALL_EVENTS (JIM_FILE_EVENTS | JIM_TIME_EVENTS) +#define JIM_DONT_WAIT 4 + /* Process every pending time event, then every pending file event * (that may be registered by time event callbacks just processed). * Without special flags the function sleeps until some file event @@ -269,9 +268,9 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags) /* Check file events */ while (fe != NULL) { - int fd = fileno(fe->handle); + int fd = fileno((FILE*)fe->handle); - if (fe->mask & JIM_EVENT_READABLE) + if (fe->mask & JIM_EVENT_READABLE) FD_SET(fd, &rfds); if (fe->mask & JIM_EVENT_WRITABLE) FD_SET(fd, &wfds); if (fe->mask & JIM_EVENT_EXCEPTION) FD_SET(fd, &efds); @@ -298,7 +297,7 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags) JimGetTime(&now_sec, &now_ms); tvp = &tv; dt = 1000 * (shortest->when_sec - now_sec); - dt += ( shortest->when_ms - now_ms); + dt += (shortest->when_ms - now_ms); if (dt < 0) { dt = 1; } @@ -310,7 +309,7 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags) // fprintf(stderr,"No Event\n"); } - retval = select(maxfd+1, &rfds, &wfds, &efds, tvp); + retval = select(maxfd + 1, &rfds, &wfds, &efds, tvp); if (retval < 0) { switch (errno) { case EINTR: fprintf(stderr,"select EINTR\n"); break; @@ -319,8 +318,8 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags) } } else if (retval > 0) { fe = eventLoop->fileEventHead; - while(fe != NULL) { - int fd = fileno(fe->handle); + while (fe != NULL) { + int fd = fileno((FILE*)fe->handle); // fprintf(stderr,"fd: %d mask: %02x \n",fd,fe->mask); @@ -361,7 +360,7 @@ int Jim_ProcessEvents(Jim_Interp *interp, int flags) /* Check time events */ te = eventLoop->timeEventHead; maxId = eventLoop->timeEventNextId-1; - while(te) { + while (te) { long now_sec, now_ms; jim_wide id; @@ -400,7 +399,7 @@ void JimELAssocDataDeleProc(Jim_Interp *interp, void *data) Jim_EventLoop *eventLoop = data; fe = eventLoop->fileEventHead; - while(fe) { + while (fe) { next = fe->next; if (fe->finalizerProc) fe->finalizerProc(interp, fe->clientData); @@ -409,7 +408,7 @@ void JimELAssocDataDeleProc(Jim_Interp *interp, void *data) } te = eventLoop->timeEventHead; - while(te) { + while (te) { next = te->next; if (te->finalizerProc) te->finalizerProc(interp, te->clientData); @@ -419,7 +418,7 @@ void JimELAssocDataDeleProc(Jim_Interp *interp, void *data) Jim_Free(data); } -static int JimELVwaitCommand(Jim_Interp *interp, int argc, +static int JimELVwaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { Jim_Obj *oldValue; @@ -461,7 +460,7 @@ void JimAfterTimeEventFinalizer(Jim_Interp *interp, void *clientData) Jim_DecrRefCount(interp, objPtr); } -static int JimELAfterCommand(Jim_Interp *interp, int argc, +static int JimELAfterCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { jim_wide ms, id; @@ -498,7 +497,7 @@ static int JimELAfterCommand(Jim_Interp *interp, int argc, int tlen ; jim_wide remain = 0; const char *tok = Jim_GetString(argv[2], &tlen); - if ( sscanf(tok,"after#%lld",&id) == 1) { + if (sscanf(tok,"after#%" JIM_WIDE_MODIFIER, &id) == 1) { remain = Jim_DeleteTimeHandler(interp, id); if (remain > -2) { Jim_SetResult(interp, Jim_NewIntObj(interp, remain)); @@ -510,15 +509,13 @@ static int JimELAfterCommand(Jim_Interp *interp, int argc, } default: fprintf(stderr,"unserviced option to after %d\n",option); - } + } return JIM_OK; } /* This extension is not dynamically loaded, instead it's linked statically, which is why we shouldn't use the unspecific 'Jim_OnLoad' name */ -#define Jim_OnLoad Jim_EventLoopOnLoad - -int Jim_OnLoad(Jim_Interp *interp) +int Jim_EventLoopOnLoad(Jim_Interp *interp) { Jim_EventLoop *eventLoop;