summaryrefslogtreecommitdiffstats
path: root/src/io-epoll.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/io-epoll.c')
-rw-r--r--src/io-epoll.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/io-epoll.c b/src/io-epoll.c
index 5e28de8..8ac230f 100644
--- a/src/io-epoll.c
+++ b/src/io-epoll.c
@@ -17,11 +17,23 @@
#include <sys/socket.h>
#include <libtf/io.h>
-#include <libtf/fiber.h>
+#include <libtf/scheduler.h>
+
+struct tf_poll_data {
+ int epoll_fd;
+ int num_waiters;
+};
+
+struct tf_poll_data *tf_epoll_get_data(void)
+{
+ struct tf_scheduler *sched = tf_scheduler_get_current();
+ TF_BUILD_BUG_ON(sizeof(struct tf_poll_data) > sizeof(sched->poll_data));
+ return (struct tf_poll_data *) &sched->poll_data;
+}
static int tf_fd_created(struct tf_fd *fd)
{
- struct tf_poll_data *pd = &tf_get_scheduler()->poll_data;
+ struct tf_poll_data *pd = tf_epoll_get_data();
struct epoll_event ev;
int r;
@@ -39,7 +51,7 @@ static int tf_fd_created(struct tf_fd *fd)
static int tf_fd_destroyed(struct tf_fd *fd)
{
- struct tf_poll_data *pd = &tf_get_scheduler()->poll_data;
+ struct tf_poll_data *pd = tf_epoll_get_data();
if (fd->flags & TF_FD_AUTOCLOSE)
return 0;
@@ -50,17 +62,17 @@ static int tf_fd_destroyed(struct tf_fd *fd)
static void tf_fd_monitor(struct tf_fd *fd, int events)
{
- struct tf_poll_data *pd = &tf_get_scheduler()->poll_data;
+ struct tf_poll_data *pd = tf_epoll_get_data();
TF_BUG_ON(fd->waiting_fiber != NULL);
fd->events = events | EPOLLERR | EPOLLHUP;
- fd->waiting_fiber = tf_get_fiber();
+ fd->waiting_fiber = tf_scheduler_get_current()->active_fiber;
pd->num_waiters++;
}
static void tf_fd_unmonitor(struct tf_fd *fd)
{
- struct tf_poll_data *pd = &tf_get_scheduler()->poll_data;
+ struct tf_poll_data *pd = tf_epoll_get_data();
fd->waiting_fiber = NULL;
fd->events = 0;
@@ -69,7 +81,7 @@ static void tf_fd_unmonitor(struct tf_fd *fd)
void tf_poll_init(void)
{
- struct tf_poll_data *pd = &tf_get_scheduler()->poll_data;
+ struct tf_poll_data *pd = tf_epoll_get_data();
pd->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
pd->num_waiters = 0;
@@ -78,7 +90,7 @@ void tf_poll_init(void)
int tf_poll(tf_mtime_diff_t timeout)
{
- struct tf_poll_data *pd = &tf_get_scheduler()->poll_data;
+ struct tf_poll_data *pd = tf_epoll_get_data();
struct epoll_event events[64];
struct tf_fd *fd;
int r, i, ret;
@@ -95,7 +107,7 @@ int tf_poll(tf_mtime_diff_t timeout)
for (i = 0; i < r; i++) {
fd = (struct tf_fd *) events[i].data.ptr;
if (likely(fd->events & events[i].events))
- tf_wakeup(fd->waiting_fiber, TF_WAKEUP_FD);
+ __tf_fiber_wakeup(fd->waiting_fiber, TF_WAKEUP_FD);
}
ret = TF_WAKEUP_FD;
timeout = 0;
@@ -106,7 +118,7 @@ int tf_poll(tf_mtime_diff_t timeout)
void tf_poll_close(void)
{
- struct tf_poll_data *pd = &tf_get_scheduler()->poll_data;
+ struct tf_poll_data *pd = tf_epoll_get_data();
close(pd->epoll_fd);
}