• Home
  • Raw
  • Download

Lines Matching refs:selector

58 static void setInSelect(Selector* selector, bool inSelect) {  in setInSelect()  argument
59 pthread_mutex_lock(&selector->inSelectLock); in setInSelect()
60 selector->inSelect = inSelect; in setInSelect()
61 pthread_mutex_unlock(&selector->inSelectLock); in setInSelect()
64 static bool isInSelect(Selector* selector) { in isInSelect() argument
65 pthread_mutex_lock(&selector->inSelectLock); in isInSelect()
66 bool inSelect = selector->inSelect; in isInSelect()
67 pthread_mutex_unlock(&selector->inSelectLock); in isInSelect()
71 void selectorWakeUp(Selector* selector) { in selectorWakeUp() argument
72 if (!isInSelect(selector)) { in selectorWakeUp()
78 if (write(selector->wakeupPipe[1], garbage, sizeof(garbage)) < 0) { in selectorWakeUp()
88 Selector* selector = calloc(1, sizeof(Selector)); in selectorCreate() local
89 if (selector == NULL) { in selectorCreate()
92 selector->selectableFds = arrayCreate(); in selectorCreate()
95 if (pipe(selector->wakeupPipe) < 0) { in selectorCreate()
99 ALOGD("Wakeup fd: %d", selector->wakeupPipe[0]); in selectorCreate()
101 SelectableFd* wakeupFd = selectorAdd(selector, selector->wakeupPipe[0]); in selectorCreate()
107 pthread_mutex_init(&selector->inSelectLock, NULL); in selectorCreate()
109 return selector; in selectorCreate()
112 SelectableFd* selectorAdd(Selector* selector, int fd) { in selectorAdd() argument
113 assert(selector != NULL); in selectorAdd()
117 selectableFd->selector = selector; in selectorAdd()
120 arrayAdd(selector->selectableFds, selectableFd); in selectorAdd()
142 static void prepareForSelect(Selector* selector) { in prepareForSelect() argument
143 fd_set* exceptFds = &selector->exceptFds; in prepareForSelect()
144 fd_set* readFds = &selector->readFds; in prepareForSelect()
145 fd_set* writeFds = &selector->writeFds; in prepareForSelect()
151 Array* selectableFds = selector->selectableFds; in prepareForSelect()
153 selector->maxFd = 0; in prepareForSelect()
186 if (fd > selector->maxFd) { in prepareForSelect()
187 selector->maxFd = fd; in prepareForSelect()
214 static void fireEvents(Selector* selector) { in fireEvents() argument
215 Array* selectableFds = selector->selectableFds; in fireEvents()
221 &selector->exceptFds); in fireEvents()
223 &selector->readFds); in fireEvents()
225 &selector->writeFds); in fireEvents()
229 void selectorLoop(Selector* selector) { in selectorLoop() argument
231 if (selector->looping) { in selectorLoop()
234 selector->looping = true; in selectorLoop()
237 setInSelect(selector, true); in selectorLoop()
239 prepareForSelect(selector); in selectorLoop()
244 int result = select(selector->maxFd + 1, &selector->readFds, in selectorLoop()
245 &selector->writeFds, &selector->exceptFds, NULL); in selectorLoop()
249 setInSelect(selector, false); in selectorLoop()
260 fireEvents(selector); in selectorLoop()