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
| | /*
* Copyright (C) 2012-2013, Eric Wong <normalperson@yhbt.net>
* License: GPLv3 or later (see COPYING for details)
*/
#if (defined(HAVE_EPOLL_WAIT) && defined(HAVE_PPOLL)) \
|| defined(HAVE_EPOLL_PWAIT)
# define MOG_SELFPIPE 0
#else
# define MOG_SELFPIPE 1
#endif
struct mog_selfwake {
struct mog_queue *queue;
struct mog_fd *writer;
};
/* only for pipe */
struct mog_selfpipe {
struct mog_fd *reader; /* points to mog_selfwake */
};
#if MOG_SELFPIPE
struct mog_fd * mog_selfwake_new(void);
void mog_selfwake_trigger(struct mog_fd *);
void mog_selfwake_drain(struct mog_fd *);
#define mog_selfwake_put(mfd) mog_fd_put((mfd))
static inline void mog_selfwake_interrupt(void) {}
void mog_selfwake_wait(struct mog_fd *);
#else /* use Linux-only facilities like epoll_pwait or ppoll */
static inline void mog_selfwake_wait(struct mog_fd *mfd)
{
mog_sleep(-1);
}
static inline struct mog_fd * mog_selfwake_new(void) { return NULL; }
static inline void mog_selfwake_trigger(struct mog_fd *mfd) {}
static inline void mog_selfwake_drain(struct mog_fd *mfd) {}
static inline void mog_selfwake_put(struct mog_fd *mfd) {}
static inline void mog_selfwake_interrupt(void)
{
CHECK(int, 0, kill(getpid(), SIGURG));
}
#endif /* Linux-only stuff */
|