summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPaton J. Lewis <palewis@adobe.com>2013-03-27 10:25:07 +1100
committerStephen Rothwell <sfr@canb.auug.org.au>2013-03-28 15:41:30 +1100
commite167bbe211e62dba7a0685a417402b5844b80835 (patch)
tree26f551a099f7492eb0fc6d491b902d57bb090dcc /include
parent58431ccc4320f274b5948f7181e5989f0894d1c6 (diff)
epoll: support for disabling items, and a self-test app
It is not currently possible to reliably delete epoll items when using the same epoll set from multiple threads. After calling epoll_ctl with EPOLL_CTL_DEL, another thread might still be executing code related to an event for that epoll item (in response to epoll_wait). Therefore the deleting thread does not know when it is safe to delete resources pertaining to the associated epoll item because another thread might be using those resources. The deleting thread could wait an arbitrary amount of time after calling epoll_ctl with EPOLL_CTL_DEL and before deleting the item, but this is inefficient and could result in the destruction of resources before another thread is done handling an event returned by epoll_wait. This patch enhances epoll_ctl to support EPOLL_CTL_DISABLE, which disables an epoll item. If epoll_ctl returns -EBUSY in this case, then another thread may handling a return from epoll_wait for this item. Otherwise if epoll_ctl returns 0, then it is safe to delete the epoll item. This allows multiple threads to use a mutex to determine when it is safe to delete an epoll item and its associated resources, which allows epoll items to be deleted both efficiently and without error in a multi-threaded environment. Note that EPOLL_CTL_DISABLE is only useful in conjunction with EPOLLONESHOT, and using EPOLL_CTL_DISABLE on an epoll item without EPOLLONESHOT returns -EINVAL. This patch also adds a new test_epoll self-test program to both demonstrate the need for this feature and test it. Signed-off-by: Paton J. Lewis <palewis@adobe.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Jason Baron <jbaron@redhat.com> Cc: Paul Holland <pholland@adobe.com> Cc: Davide Libenzi <davidel@xmailserver.org> Cc: Michael Kerrisk <mtk.manpages@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/uapi/linux/eventpoll.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/uapi/linux/eventpoll.h b/include/uapi/linux/eventpoll.h
index 2c267bcbb85c..8c99ce7202c5 100644
--- a/include/uapi/linux/eventpoll.h
+++ b/include/uapi/linux/eventpoll.h
@@ -25,6 +25,7 @@
#define EPOLL_CTL_ADD 1
#define EPOLL_CTL_DEL 2
#define EPOLL_CTL_MOD 3
+#define EPOLL_CTL_DISABLE 4
/*
* Request the handling of system wakeup events so as to prevent system suspends