diff options
author | Gluster Ant <bugzilla-bot@gluster.org> | 2018-09-12 17:52:45 +0530 |
---|---|---|
committer | Nigel Babu <nigelb@redhat.com> | 2018-09-12 17:52:45 +0530 |
commit | e16868dede6455cab644805af6fe1ac312775e13 (patch) | |
tree | 15aebdb4fff2d87cf8a72f836816b3aa634da58d /libglusterfs/src/event.c | |
parent | 45a71c0548b6fd2c757aa2e7b7671a1411948894 (diff) |
Land part 2 of clang-format changes
Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4
Signed-off-by: Nigel Babu <nigelb@redhat.com>
Diffstat (limited to 'libglusterfs/src/event.c')
-rw-r--r-- | libglusterfs/src/event.c | 367 |
1 files changed, 180 insertions, 187 deletions
diff --git a/libglusterfs/src/event.c b/libglusterfs/src/event.c index 2598cd305a8..5b4d43e8650 100644 --- a/libglusterfs/src/event.c +++ b/libglusterfs/src/event.c @@ -23,173 +23,164 @@ #include "libglusterfs-messages.h" #include "syscall.h" - - struct event_pool * -event_pool_new (int count, int eventthreadcount) +event_pool_new(int count, int eventthreadcount) { - struct event_pool *event_pool = NULL; - extern struct event_ops event_ops_poll; + struct event_pool *event_pool = NULL; + extern struct event_ops event_ops_poll; #ifdef HAVE_SYS_EPOLL_H - extern struct event_ops event_ops_epoll; + extern struct event_ops event_ops_epoll; - event_pool = event_ops_epoll.new (count, eventthreadcount); + event_pool = event_ops_epoll.new(count, eventthreadcount); - if (event_pool) { - event_pool->ops = &event_ops_epoll; - } else { - gf_msg ("event", GF_LOG_WARNING, 0, LG_MSG_FALLBACK_TO_POLL, - "falling back to poll based event handling"); - } + if (event_pool) { + event_pool->ops = &event_ops_epoll; + } else { + gf_msg("event", GF_LOG_WARNING, 0, LG_MSG_FALLBACK_TO_POLL, + "falling back to poll based event handling"); + } #endif - if (!event_pool) { - event_pool = event_ops_poll.new (count, eventthreadcount); + if (!event_pool) { + event_pool = event_ops_poll.new(count, eventthreadcount); - if (event_pool) - event_pool->ops = &event_ops_poll; - } + if (event_pool) + event_pool->ops = &event_ops_poll; + } - return event_pool; + return event_pool; } - int -event_register (struct event_pool *event_pool, int fd, - event_handler_t handler, - void *data, int poll_in, int poll_out) +event_register(struct event_pool *event_pool, int fd, event_handler_t handler, + void *data, int poll_in, int poll_out) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - ret = event_pool->ops->event_register (event_pool, fd, handler, data, - poll_in, poll_out); + ret = event_pool->ops->event_register(event_pool, fd, handler, data, + poll_in, poll_out); out: - return ret; + return ret; } - int -event_unregister (struct event_pool *event_pool, int fd, int idx) +event_unregister(struct event_pool *event_pool, int fd, int idx) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - ret = event_pool->ops->event_unregister (event_pool, fd, idx); + ret = event_pool->ops->event_unregister(event_pool, fd, idx); out: - return ret; + return ret; } - int -event_unregister_close (struct event_pool *event_pool, int fd, int idx) +event_unregister_close(struct event_pool *event_pool, int fd, int idx) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - ret = event_pool->ops->event_unregister_close (event_pool, fd, idx); + ret = event_pool->ops->event_unregister_close(event_pool, fd, idx); out: - return ret; + return ret; } - int -event_select_on (struct event_pool *event_pool, int fd, int idx_hint, - int poll_in, int poll_out) +event_select_on(struct event_pool *event_pool, int fd, int idx_hint, + int poll_in, int poll_out) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - ret = event_pool->ops->event_select_on (event_pool, fd, idx_hint, - poll_in, poll_out); + ret = event_pool->ops->event_select_on(event_pool, fd, idx_hint, poll_in, + poll_out); out: - return ret; + return ret; } - int -event_dispatch (struct event_pool *event_pool) +event_dispatch(struct event_pool *event_pool) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - ret = event_pool->ops->event_dispatch (event_pool); - if (ret) - goto out; + ret = event_pool->ops->event_dispatch(event_pool); + if (ret) + goto out; out: - return ret; + return ret; } int -event_reconfigure_threads (struct event_pool *event_pool, int value) +event_reconfigure_threads(struct event_pool *event_pool, int value) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - /* call event refresh function */ - ret = event_pool->ops->event_reconfigure_threads (event_pool, - value); + /* call event refresh function */ + ret = event_pool->ops->event_reconfigure_threads(event_pool, value); out: - return ret; + return ret; } int -event_pool_destroy (struct event_pool *event_pool) +event_pool_destroy(struct event_pool *event_pool) { - int ret = -1; - int destroy = 0, activethreadcount = 0; + int ret = -1; + int destroy = 0, activethreadcount = 0; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - pthread_mutex_lock (&event_pool->mutex); - { - destroy = event_pool->destroy; - activethreadcount = event_pool->activethreadcount; - } - pthread_mutex_unlock (&event_pool->mutex); + pthread_mutex_lock(&event_pool->mutex); + { + destroy = event_pool->destroy; + activethreadcount = event_pool->activethreadcount; + } + pthread_mutex_unlock(&event_pool->mutex); - if (!destroy || (activethreadcount > 0)) { - goto out; - } + if (!destroy || (activethreadcount > 0)) { + goto out; + } - ret = event_pool->ops->event_pool_destroy (event_pool); + ret = event_pool->ops->event_pool_destroy(event_pool); out: - return ret; + return ret; } int -poller_destroy_handler (int fd, int idx, int gen, void *data, - int poll_out, int poll_in, int poll_err) +poller_destroy_handler(int fd, int idx, int gen, void *data, int poll_out, + int poll_in, int poll_err) { - struct event_destroy_data *destroy = NULL; - int readfd = -1, ret = -1; - char buf = '\0'; - - destroy = data; - readfd = destroy->readfd; - if (readfd < 0) { - goto out; - } + struct event_destroy_data *destroy = NULL; + int readfd = -1, ret = -1; + char buf = '\0'; - while (sys_read (readfd, &buf, 1) > 0) { - } + destroy = data; + readfd = destroy->readfd; + if (readfd < 0) { + goto out; + } + + while (sys_read(readfd, &buf, 1) > 0) { + } - ret = 0; + ret = 0; out: - event_handled (destroy->pool, fd, idx, gen); + event_handled(destroy->pool, fd, idx, gen); - return ret; + return ret; } /* This function destroys all the poller threads. @@ -204,109 +195,111 @@ out: * threads are destroyed) */ int -event_dispatch_destroy (struct event_pool *event_pool) +event_dispatch_destroy(struct event_pool *event_pool) { - int ret = -1, threadcount = 0; - int fd[2] = {-1}; - int idx = -1; - int flags = 0; - struct timespec sleep_till = {0, }; - struct event_destroy_data data = {0, }; - - GF_VALIDATE_OR_GOTO ("event", event_pool, out); - - ret = pipe (fd); - if (ret < 0) - goto out; - - /* Make the read end of the pipe nonblocking */ - flags = fcntl(fd[0], F_GETFL); - flags |= O_NONBLOCK; - ret = fcntl(fd[0], F_SETFL, flags); - if (ret < 0) - goto out; - - /* Make the write end of the pipe nonblocking */ - flags = fcntl(fd[1], F_GETFL); - flags |= O_NONBLOCK; - ret = fcntl(fd[1], F_SETFL, flags); - if (ret < 0) - goto out; - - data.pool = event_pool; - data.readfd = fd[1]; - - /* From the main thread register an event on the pipe fd[0], - */ - idx = event_register (event_pool, fd[0], poller_destroy_handler, - &data, 1, 0); - if (idx < 0) - goto out; - - /* Enter the destroy mode first, set this before reconfiguring to 0 - * threads, to prevent further reconfigure to thread count > 0. + int ret = -1, threadcount = 0; + int fd[2] = {-1}; + int idx = -1; + int flags = 0; + struct timespec sleep_till = { + 0, + }; + struct event_destroy_data data = { + 0, + }; + + GF_VALIDATE_OR_GOTO("event", event_pool, out); + + ret = pipe(fd); + if (ret < 0) + goto out; + + /* Make the read end of the pipe nonblocking */ + flags = fcntl(fd[0], F_GETFL); + flags |= O_NONBLOCK; + ret = fcntl(fd[0], F_SETFL, flags); + if (ret < 0) + goto out; + + /* Make the write end of the pipe nonblocking */ + flags = fcntl(fd[1], F_GETFL); + flags |= O_NONBLOCK; + ret = fcntl(fd[1], F_SETFL, flags); + if (ret < 0) + goto out; + + data.pool = event_pool; + data.readfd = fd[1]; + + /* From the main thread register an event on the pipe fd[0], + */ + idx = event_register(event_pool, fd[0], poller_destroy_handler, &data, 1, + 0); + if (idx < 0) + goto out; + + /* Enter the destroy mode first, set this before reconfiguring to 0 + * threads, to prevent further reconfigure to thread count > 0. + */ + pthread_mutex_lock(&event_pool->mutex); + { + threadcount = event_pool->eventthreadcount; + event_pool->destroy = 1; + } + pthread_mutex_unlock(&event_pool->mutex); + + ret = event_reconfigure_threads(event_pool, 0); + if (ret < 0) + goto out; + + /* Write something onto the write end of the pipe(fd[1]) so that + * poll wakes up and calls the handler, poller_destroy_handler() + */ + pthread_mutex_lock(&event_pool->mutex); + { + /* Write to pipe(fd[1]) and then wait for 1 second or until + * a poller thread that is dying, broadcasts. Make sure we + * do not loop forever by limiting to 10 retries */ - pthread_mutex_lock (&event_pool->mutex); - { - threadcount = event_pool->eventthreadcount; - event_pool->destroy = 1; + int retry = 0; + + while (event_pool->activethreadcount > 0 && + (retry++ < (threadcount + 10))) { + if (sys_write(fd[1], "dummy", 6) == -1) { + break; + } + sleep_till.tv_sec = time(NULL) + 1; + ret = pthread_cond_timedwait(&event_pool->cond, &event_pool->mutex, + &sleep_till); + if (ret) { + gf_msg_debug("event", 0, + "thread cond-timedwait failed " + "active-thread-count: %d, " + "retry: %d", + event_pool->activethreadcount, retry); + } } - pthread_mutex_unlock (&event_pool->mutex); + } + pthread_mutex_unlock(&event_pool->mutex); - ret = event_reconfigure_threads (event_pool, 0); - if (ret < 0) - goto out; + ret = event_unregister(event_pool, fd[0], idx); - /* Write something onto the write end of the pipe(fd[1]) so that - * poll wakes up and calls the handler, poller_destroy_handler() - */ - pthread_mutex_lock (&event_pool->mutex); - { - /* Write to pipe(fd[1]) and then wait for 1 second or until - * a poller thread that is dying, broadcasts. Make sure we - * do not loop forever by limiting to 10 retries - */ - int retry = 0; - - while (event_pool->activethreadcount > 0 - && (retry++ < (threadcount + 10))) { - if (sys_write (fd[1], "dummy", 6) == -1) { - break; - } - sleep_till.tv_sec = time (NULL) + 1; - ret = pthread_cond_timedwait (&event_pool->cond, - &event_pool->mutex, - &sleep_till); - if (ret) { - gf_msg_debug ("event", 0, - "thread cond-timedwait failed " - "active-thread-count: %d, " - "retry: %d", - event_pool->activethreadcount, - retry); - } - } - } - pthread_mutex_unlock (&event_pool->mutex); - - ret = event_unregister (event_pool, fd[0], idx); - - out: - if (fd[0] != -1) - sys_close (fd[0]); - if (fd[1] != -1) - sys_close (fd[1]); +out: + if (fd[0] != -1) + sys_close(fd[0]); + if (fd[1] != -1) + sys_close(fd[1]); - return ret; + return ret; } int -event_handled (struct event_pool *event_pool, int fd, int idx, int gen) +event_handled(struct event_pool *event_pool, int fd, int idx, int gen) { - int ret = 0; + int ret = 0; - if (event_pool->ops->event_handled) - ret = event_pool->ops->event_handled (event_pool, fd, idx, gen); + if (event_pool->ops->event_handled) + ret = event_pool->ops->event_handled(event_pool, fd, idx, gen); - return ret; + return ret; } |