Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: use container_of() instead of w->data
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Jan 18, 2012
1 parent dd7e6f0 commit ee10cb7
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/unix/core.c
Expand Up @@ -234,7 +234,6 @@ void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle,
handle->flags = 0;

ev_init(&handle->next_watcher, uv__next);
handle->next_watcher.data = handle;

/* Ref the loop until this handle is closed. See uv__finish_close. */
ev_ref(loop->ev);
Expand Down Expand Up @@ -307,9 +306,9 @@ void uv__finish_close(uv_handle_t* handle) {
}


void uv__next(EV_P_ ev_idle* watcher, int revents) {
uv_handle_t* handle = watcher->data;
assert(watcher == &handle->next_watcher);
void uv__next(EV_P_ ev_idle* w, int revents) {
uv_handle_t* handle = container_of(w, uv_handle_t, next_watcher);

assert(revents == EV_IDLE);

/* For now this function is only to handle the closing event, but we might
Expand Down Expand Up @@ -347,7 +346,7 @@ void uv__req_init(uv_loop_t* loop, uv_req_t* req) {


static void uv__prepare(EV_P_ ev_prepare* w, int revents) {
uv_prepare_t* prepare = w->data;
uv_prepare_t* prepare = container_of(w, uv_prepare_t, prepare_watcher);

if (prepare->prepare_cb) {
prepare->prepare_cb(prepare, 0);
Expand All @@ -360,8 +359,6 @@ int uv_prepare_init(uv_loop_t* loop, uv_prepare_t* prepare) {
loop->counters.prepare_init++;

ev_prepare_init(&prepare->prepare_watcher, uv__prepare);
prepare->prepare_watcher.data = prepare;

prepare->prepare_cb = NULL;

return 0;
Expand Down Expand Up @@ -397,7 +394,7 @@ int uv_prepare_stop(uv_prepare_t* prepare) {


static void uv__check(EV_P_ ev_check* w, int revents) {
uv_check_t* check = w->data;
uv_check_t* check = container_of(w, uv_check_t, check_watcher);

if (check->check_cb) {
check->check_cb(check, 0);
Expand All @@ -410,8 +407,6 @@ int uv_check_init(uv_loop_t* loop, uv_check_t* check) {
loop->counters.check_init++;

ev_check_init(&check->check_watcher, uv__check);
check->check_watcher.data = check;

check->check_cb = NULL;

return 0;
Expand Down Expand Up @@ -447,7 +442,7 @@ int uv_check_stop(uv_check_t* check) {


static void uv__idle(EV_P_ ev_idle* w, int revents) {
uv_idle_t* idle = (uv_idle_t*)(w->data);
uv_idle_t* idle = container_of(w, uv_idle_t, idle_watcher);

if (idle->idle_cb) {
idle->idle_cb(idle, 0);
Expand All @@ -461,8 +456,6 @@ int uv_idle_init(uv_loop_t* loop, uv_idle_t* idle) {
loop->counters.idle_init++;

ev_idle_init(&idle->idle_watcher, uv__idle);
idle->idle_watcher.data = idle;

idle->idle_cb = NULL;

return 0;
Expand Down Expand Up @@ -517,7 +510,7 @@ int uv_is_active(uv_handle_t* handle) {


static void uv__async(EV_P_ ev_async* w, int revents) {
uv_async_t* async = w->data;
uv_async_t* async = container_of(w, uv_async_t, async_watcher);

if (async->async_cb) {
async->async_cb(async, 0);
Expand All @@ -530,8 +523,6 @@ int uv_async_init(uv_loop_t* loop, uv_async_t* async, uv_async_cb async_cb) {
loop->counters.async_init++;

ev_async_init(&async->async_watcher, uv__async);
async->async_watcher.data = async;

async->async_cb = async_cb;

/* Note: This does not have symmetry with the other libev wrappers. */
Expand All @@ -549,7 +540,7 @@ int uv_async_send(uv_async_t* async) {


static void uv__timer_cb(EV_P_ ev_timer* w, int revents) {
uv_timer_t* timer = w->data;
uv_timer_t* timer = container_of(w, uv_timer_t, timer_watcher);

if (!ev_is_active(w)) {
ev_ref(EV_A);
Expand All @@ -566,7 +557,6 @@ int uv_timer_init(uv_loop_t* loop, uv_timer_t* timer) {
loop->counters.timer_init++;

ev_init(&timer->timer_watcher, uv__timer_cb);
timer->timer_watcher.data = timer;

return 0;
}
Expand Down

0 comments on commit ee10cb7

Please sign in to comment.