summaryrefslogtreecommitdiff
path: root/mainloop.h
blob: 70ed4d48caca111b6a8bfa490b9901661ff30434 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef _MAINLOOP_H
#define _MAINLOOP_H

#include <glib.h>
#include "jobqueue.h"
#include "epoll.h"

typedef struct MainLoop MainLoop;

typedef void (* MainFdFunc) (int	    fd,
			     EPollEventType mask,
			     gpointer       data);

MainLoop *main_loop_new (Executor *executor);
Executor *main_loop_get_executor (MainLoop *loop);
void	  main_loop_add_fd (MainLoop       *loop,
			    int	            fd,
			    JobQueue	   *queue,
			    MainFdFunc      func,
			    gpointer        data);
void	  main_loop_set_fd_poll_mask (MainLoop *loop,
				      int	fd,
				      EPollEventType poll_mask);
void      main_loop_remove_fd (MainLoop        *loop,
			       int		fd);

/* Missing: */

/* Maybe these functions really belong in the JobQueue?
 * That would require support from the executor though.
 * But fundamentally these are valid (in a threaded server)
 * without fds, which is what the main loop provides.
 * The executor already has a gcond_wait() that could be
 * made a timed one.
 *
 * Note that a good priority queue is going to be needed in
 * whatever class eventually implements these.
 *
 * Also, note that cancellation support is essential for these
 * tasks.
 *
 * Yes, should probably happen in JobQueue + Executor:
 *
 *		executor should maintain all jobs in a priority queue
 *		sorted by execution time. 
 *
 *		normal jobs get an execution time of "now", where timeout
 *		jobs get an execution of sometime in the future.
 *
 *		this avoids starvation of timeouts since a timeout will
 *		eventually move to the front of the queue (with a time
 *		in the past possibly)
 *
 *		
 * 
 */
#if 0
void	  main_loop_add_timeout (MainLoop      *loop,
				 JobQueue      *queue,
				 MainFunc    *task);
void	  main_loop_add_idle    (MainLoop      *loop,
				 JobQueue      *queue,
				 MainFunc    *task);
#endif

#endif /* _MAINLOO_H_ */