diff options
author | Vladislav Vaintroub <wlad@montyprogram.com> | 2012-04-12 01:40:44 +0200 |
---|---|---|
committer | Vladislav Vaintroub <wlad@montyprogram.com> | 2012-04-12 01:40:44 +0200 |
commit | 85a025f30c5196c22c5b1d7960912fe9b3f0d6c0 (patch) | |
tree | 2833559321620a5f5c0ed5f5ab5c4b8ef85f740f /sql/threadpool_unix.cc | |
parent | f544b21fcb0a05caeb2e375d8156da890b34c88a (diff) | |
download | mariadb-git-85a025f30c5196c22c5b1d7960912fe9b3f0d6c0.tar.gz |
Threadpool - use EV_ONESHOT with kevent, to prevent race condition when 2
threads are retrieving events at the same time.
Diffstat (limited to 'sql/threadpool_unix.cc')
-rw-r--r-- | sql/threadpool_unix.cc | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/sql/threadpool_unix.cc b/sql/threadpool_unix.cc index 407905fd5f6..f5ea771883d 100644 --- a/sql/threadpool_unix.cc +++ b/sql/threadpool_unix.cc @@ -295,7 +295,7 @@ int io_poll_create() int io_poll_start_read(int pollfd, int fd, void *data) { struct kevent ke; - EV_SET(&ke, fd, EVFILT_READ, EV_ADD|EV_ENABLE|EV_CLEAR, + EV_SET(&ke, fd, EVFILT_READ, EV_ADD|EV_ONESHOT, 0, 0, data); return kevent(pollfd, &ke, 1, 0, 0, 0); } @@ -303,6 +303,9 @@ int io_poll_start_read(int pollfd, int fd, void *data) int io_poll_associate_fd(int pollfd, int fd, void *data) { + struct kevent ke; + EV_SET(&ke, fd, EVFILT_READ, EV_ADD|EV_ONESHOT, + 0, 0, data); return io_poll_start_read(pollfd,fd, data); } @@ -330,17 +333,6 @@ int io_poll_wait(int pollfd, struct kevent *events, int maxevents, int timeout_m (timeout_ms >= 0)?&ts:NULL); } while (ret == -1 && errno == EINTR); - if (ret > 0) - { - /* Disable monitoring for the events we that we dequeued */ - for (int i=0; i < ret; i++) - { - struct kevent *ke = &events[i]; - EV_SET(ke, ke->ident, EVFILT_READ, EV_ADD|EV_DISABLE, - 0, 0, ke->udata); - } - kevent(pollfd, events, ret, 0, 0, 0); - } return ret; } |