Home | History | Annotate | Download | only in src

Lines Matching defs:reactor

21 #include "osi/include/reactor.h"
44 list_t *invalidation_list; // reactor objects that have been unregistered.
53 reactor_t *reactor; // the reactor instance this object is registered with.
60 static reactor_status_t run_reactor(reactor_t *reactor, int iterations);
106 void reactor_free(reactor_t *reactor) {
107 if (!reactor)
110 list_free(reactor->invalidation_list);
111 close(reactor->event_fd);
112 close(reactor->epoll_fd);
113 osi_free(reactor);
116 reactor_status_t reactor_start(reactor_t *reactor) {
117 assert(reactor != NULL);
118 return run_reactor(reactor, 0);
121 reactor_status_t reactor_run_once(reactor_t *reactor) {
122 assert(reactor != NULL);
123 return run_reactor(reactor, 1);
126 void reactor_stop(reactor_t *reactor) {
127 assert(reactor != NULL);
129 eventfd_write(reactor->event_fd, EVENT_REACTOR_STOP);
132 reactor_object_t *reactor_register(reactor_t *reactor,
136 assert(reactor != NULL);
142 object->reactor = reactor;
157 if (epoll_ctl(reactor->epoll_fd, EPOLL_CTL_ADD, fd, &event) == -1) {
180 if (epoll_ctl(object->reactor->epoll_fd, EPOLL_CTL_MOD, object->fd, &event) == -1) {
196 reactor_t *reactor = obj->reactor;
198 if (epoll_ctl(reactor->epoll_fd, EPOLL_CTL_DEL, obj->fd, NULL) == -1)
201 if (reactor->is_running && pthread_equal(pthread_self(), reactor->run_thread)) {
202 reactor->object_removed = true;
206 pthread_mutex_lock(&reactor->list_lock);
207 list_append(reactor->invalidation_list, obj);
208 pthread_mutex_unlock(&reactor->list_lock);
211 // currently executing. The reactor thread must then either be before
214 // it won't be referenced because the reactor thread will check the
216 // are waiting until the reactor thread drops all references to |obj|.
224 // Runs the reactor loop for a maximum of |iterations|.
226 // |reactor| may not be NULL.
227 static reactor_status_t run_reactor(reactor_t *reactor, int iterations) {
228 assert(reactor != NULL);
230 reactor->run_thread = pthread_self();
231 reactor->is_running = true;
235 pthread_mutex_lock(&reactor->list_lock);
236 list_clear(reactor->invalidation_list);
237 pthread_mutex_unlock(&reactor->list_lock);
240 OSI_NO_INTR(ret = epoll_wait(reactor->epoll_fd, events, MAX_EVENTS, -1));
243 reactor->is_running = false;
250 // out of the reactor loop.
253 eventfd_read(reactor->event_fd, &value);
254 reactor->is_running = false;
260 pthread_mutex_lock(&reactor->list_lock);
261 if (list_contains(reactor->invalidation_list, object)) {
262 pthread_mutex_unlock(&reactor->list_lock);
268 pthread_mutex_unlock(&reactor->list_lock);
270 reactor->object_removed = false;
273 if (!reactor->object_removed && events[j].events & EPOLLOUT && object->write_ready)
277 if (reactor->object_removed) {
284 reactor->is_running = false;