📄 waitfor.c
字号:
if (XFD_ANYSET(&tmp_set))#endif QueueWorkProc(EstablishNewConnections, NULL, (pointer)&LastSelectMask);#ifdef DPMSExtension if (XFD_ANYSET (&devicesReadable) && (DPMSPowerLevel != DPMSModeOn)) DPMSSet(DPMSModeOn);#endif if (XFD_ANYSET (&devicesReadable) || XFD_ANYSET (&clientsReadable)) break; } } nready = 0; if (XFD_ANYSET (&clientsReadable)) {#ifndef WIN32 for (i=0; i<howmany(XFD_SETSIZE, NFDBITS); i++) { int highest_priority; while (clientsReadable.fds_bits[i]) { int client_priority, client_index; curclient = ffsl(clientsReadable.fds_bits[i]) - 1; client_index = ConnectionTranslation[curclient + (i * sizeof(fd_mask) * 8)];#else int highest_priority; fd_set savedClientsReadable; XFD_COPYSET(&clientsReadable, &savedClientsReadable); for (i = 0; i < XFD_SETCOUNT(&savedClientsReadable); i++) { int client_priority, client_index; curclient = XFD_FD(&savedClientsReadable, i); client_index = ConnectionTranslation[curclient];#endif#ifdef XSYNC /* We implement "strict" priorities. * Only the highest priority client is returned to * dix. If multiple clients at the same priority are * ready, they are all returned. This means that an * aggressive client could take over the server. * This was not considered a big problem because * aggressive clients can hose the server in so many * other ways :) */ client_priority = clients[client_index]->priority; if (nready == 0 || client_priority > highest_priority) { /* Either we found the first client, or we found * a client whose priority is greater than all others * that have been found so far. Either way, we want * to initialize the list of clients to contain just * this client. */ pClientsReady[0] = client_index; highest_priority = client_priority; nready = 1; } /* the following if makes sure that multiple same-priority * clients get batched together */ else if (client_priority == highest_priority)#endif { pClientsReady[nready++] = client_index; }#ifndef WIN32 clientsReadable.fds_bits[i] &= ~(((fd_mask)1) << curclient); }#else FD_CLR(curclient, &clientsReadable);#endif } } return nready;}#if 0/* * This is not always a macro. */ANYSET(src) FdMask *src;{ int i; for (i=0; i<mskcnt; i++) if (src[ i ]) return (TRUE); return (FALSE);}#endif#else /* AMOEBA */#define dbprintf(list) /* printf list */intWaitForSomething(pClientsReady) int *pClientsReady;{ register int i, wt, nt; struct timeval *wtp; long alwaysCheckForInput[2]; int nready; int timeout; unsigned long now; WakeupInitWaiters(); /* Be sure to check for input on every sweep in the dispatcher. * This routine should be in InitInput, but since this is more * or less a device dependent routine, and the semantics of it * are device independent I decided to put it here. */ alwaysCheckForInput[0] = 0; alwaysCheckForInput[1] = 1; SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]); while (1) { /* deal with any blocked jobs */ if (workQueue) ProcessWorkQueue(); if (ANYSET(ClientsWithInput)) { FdSet clientsReadable; int highest_priority; COPYBITS(ClientsWithInput, clientsReadable); dbprintf(("WaitFor: ")); nready = 0; for (i=0; i < mskcnt; i++) { while (clientsReadable[i]) { int client_priority, curclient, client_index; curclient = ffsl(clientsReadable[i]) - 1; client_index = ConnectionTranslation[curclient + (i * sizeof(fd_mask) * 8)]; dbprintf(("%d has input\n", curclient));#ifdef XSYNC client_priority = clients[client_index]->priority; if (nready == 0 || client_priority > highest_priority) { pClientsReady[0] = client_index; highest_priority = client_priority; nready = 1; } else if (client_priority == highest_priority)#endif { pClientsReady[nready++] = client_index; } clientsReadable[i] &= ~(((FdMask)1) << curclient); } } break; } wt = -1; now = GetTimeInMillis(); if (timers) { while (timers && timers->expires <= now) DoTimer(timers, now, &timers); if (timers) { timeout = timers->expires - now; wt = timeout; } } if (ScreenSaverTime) { timeout = ScreenSaverTime - TimeSinceLastInputEvent(); if (timeout <= 0) { /* may be forced by AutoResetServer() */ long timeSinceSave; timeSinceSave = -timeout; if ((timeSinceSave >= timeTilFrob) && (timeTilFrob >= 0)) { SaveScreens(SCREEN_SAVER_ON, ScreenSaverActive); if (ScreenSaverInterval) /* round up to the next ScreenSaverInterval */ timeTilFrob = ScreenSaverInterval * ((timeSinceSave + ScreenSaverInterval) / ScreenSaverInterval); else timeTilFrob = -1; } timeout = timeTilFrob - timeSinceSave; } else { if (timeout > ScreenSaverTime) timeout = ScreenSaverTime; timeTilFrob = 0; } if (wt < 0 || (timeTilFrob >= 0 && wt > timeout)) { wt = timeout; } } /* Check for new clients. We do this here and not in the listener * threads because we cannot be sure that dix is re-entrant, and * we need to call some dix routines during startup. */ if (nNewConns) { QueueWorkProc(EstablishNewConnections, NULL, (pointer) 0); } /* Call device dependent block handlers, which may want to * specify a different timeout (e.g. used for key auto-repeat). */ wtp = (struct timeval *) NULL; BlockHandler((pointer)&wtp, (pointer)NULL); if (wtp) wt = (wtp->tv_sec * 1000) + (wtp->tv_usec / 1000); if (NewOutputPending) FlushAllOutput(); /* TODO: XTESTEXT1 */ nready = AmFindReadyClients(pClientsReady, AllSockets); /* If we found some work, or the iop server has us informed about * new device events, we return. */ if (nready || AmoebaEventsAvailable()) break; if (dispatchException) return 0; /* Nothing interesting is available. Go to sleep with a timeout. * The other threads will wake us when needed. */ i = SleepMainThread(wt); /* Wake up any of the sleeping handlers */ WakeupHandler((unsigned long)0, (pointer)NULL); /* TODO: XTESTEXT1 */ if (dispatchException) return 0; if (i == -1) { /* An error or timeout occurred */ return 0; } } dbprintf(("WaitForSomething: %d clients ready\n", nready)); return nready;}#endif /* AMOEBA */static voidDoTimer(timer, now, prev) register OsTimerPtr timer; CARD32 now; OsTimerPtr *prev;{ CARD32 newTime; *prev = timer->next; timer->next = NULL; newTime = (*timer->callback)(timer, now, timer->arg); if (newTime) TimerSet(timer, 0, newTime, timer->callback, timer->arg);}OsTimerPtrTimerSet(timer, flags, millis, func, arg) register OsTimerPtr timer; int flags; CARD32 millis; OsTimerCallback func; pointer arg;{ register OsTimerPtr *prev; CARD32 now = GetTimeInMillis(); if (!timer) { timer = (OsTimerPtr)xalloc(sizeof(struct _OsTimerRec)); if (!timer) return NULL; } else { for (prev = &timers; *prev; prev = &(*prev)->next) { if (*prev == timer) { *prev = timer->next; if (flags & TimerForceOld) (void)(*timer->callback)(timer, now, timer->arg); break; } } } if (!millis) return timer; if (!(flags & TimerAbsolute)) millis += now; timer->expires = millis; timer->callback = func; timer->arg = arg; if (millis <= now) { timer->next = NULL; millis = (*timer->callback)(timer, now, timer->arg); if (!millis) return timer; } for (prev = &timers; *prev && millis > (*prev)->expires; prev = &(*prev)->next) ; timer->next = *prev; *prev = timer; return timer;}BoolTimerForce(timer) register OsTimerPtr timer;{ register OsTimerPtr *prev; register CARD32 newTime; for (prev = &timers; *prev; prev = &(*prev)->next) { if (*prev == timer) { DoTimer(timer, GetTimeInMillis(), prev); return TRUE; } } return FALSE;}voidTimerCancel(timer) register OsTimerPtr timer;{ register OsTimerPtr *prev; if (!timer) return; for (prev = &timers; *prev; prev = &(*prev)->next) { if (*prev == timer) { *prev = timer->next; break; } }}voidTimerFree(timer) register OsTimerPtr timer;{ if (!timer) return; TimerCancel(timer); xfree(timer);}voidTimerCheck(){ register CARD32 now = GetTimeInMillis(); while (timers && timers->expires <= now) DoTimer(timers, now, &timers);}voidTimerInit(){ OsTimerPtr timer; while (timer = timers) { timers = timer->next; xfree(timer); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -