/*
* UCW Library -- Main Loop
*
- * (c) 2004--2011 Martin Mares <mj@ucw.cz>
+ * (c) 2004--2012 Martin Mares <mj@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
#undef LOCAL_DEBUG
-#include "ucw/lib.h"
-#include "ucw/heap.h"
-#include "ucw/mainloop.h"
-#include "ucw/threads.h"
-#include "ucw/gary.h"
+#include <ucw/lib.h>
+#include <ucw/heap.h>
+#include <ucw/mainloop.h>
+#include <ucw/threads.h>
+#include <ucw/gary.h>
+#include <ucw/process.h>
+#include <ucw/time.h>
#include <stdio.h>
#include <string.h>
static void
main_get_time_ctx(struct main_context *m)
{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- m->now_seconds = tv.tv_sec;
- m->now = (timestamp_t)tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ m->now = get_timestamp();
}
static struct main_context *
m->epoll_fd = epoll_create(64);
if (m->epoll_fd < 0)
die("epoll_create() failed: %m");
- m->epoll_events = xmalloc(EPOLL_BUF_SIZE * sizeof(struct epoll_event *));
+ m->epoll_events = xmalloc(EPOLL_BUF_SIZE * sizeof(struct epoll_event));
clist_init(&m->file_recalc_list);
#else
m->poll_table_obsolete = 1;
{
uns events = 0;
if (fi->read_handler)
- events |= POLLIN | POLLHUP | POLLERR;
+ events |= POLLIN;
if (fi->write_handler)
- events |= POLLOUT | POLLERR;
+ events |= POLLOUT;
return events;
}
// XXX: Can be called on a non-current context
DBG("MAIN: Deleting file %p (fd=%d)", fi, fi->fd);
- ASSERT(file_is_active(fi));
+ if (!file_is_active(fi))
+ return;
clist_unlink(&fi->n);
m->file_cnt--;
#ifdef CONFIG_UCW_EPOLL
struct main_context *m = main_current();
DBG("MAIN: Adding hook %p", ho);
- ASSERT(!hook_is_active(ho));
+ if (hook_is_active(ho))
+ clist_unlink(&ho->n);
clist_add_tail(&m->hook_list, &ho->n);
}
hook_del(struct main_hook *ho)
{
DBG("MAIN: Deleting hook %p", ho);
- ASSERT(hook_is_active(ho));
- clist_unlink(&ho->n);
+ if (hook_is_active(ho))
+ clist_unlink(&ho->n);
}
static void
process_del(struct main_process *mp)
{
DBG("MAIN: Deleting process %p (pid=%d)", mp, mp->pid);
- ASSERT(process_is_active(mp));
- clist_unlink(&mp->n);
+ if (process_is_active(mp))
+ clist_unlink(&mp->n);
}
int
// XXX: Can be called on a non-current context
DBG("MAIN: Deleting signal %p (sig=%d)", ms, ms->signum);
- ASSERT(signal_is_active(ms));
+ if (!signal_is_active(ms))
+ return;
clist_unlink(&ms->n);
int another = 0;
signal_del_ctx(main_current(), ms);
}
-#ifdef CONFIG_DEBUG
+#ifdef CONFIG_UCW_DEBUG
void
file_debug(struct main_file *fi)
struct main_file *fi;
while (fi = clist_head(&m->file_active_list))
{
- if (fi->events & (POLLIN | POLLHUP | POLLERR))
+ if (fi->read_handler && (fi->events & (POLLIN | POLLHUP)))
{
- fi->events &= ~(POLLIN | POLLHUP | POLLERR);
+ fi->events &= ~(POLLIN | POLLHUP);
do
DBG("MAIN: Read event on fd %d", fi->fd);
while (fi->read_handler && fi->read_handler(fi));
continue;
}
- if (fi->events & (POLLOUT | POLLERR))
+ if (fi->write_handler && (fi->events & (POLLOUT | POLLHUP | POLLERR)))
{
- fi->events &= ~(POLLOUT | POLLERR);
+ fi->events &= ~(POLLOUT | POLLHUP | POLLERR);
do
DBG("MAIN: Write event on fd %d", fi->fd);
while (fi->write_handler && fi->write_handler(fi));