preliminary kqueue support
[sleepy_penguin.git] / ext / sleepy_penguin / init.c
blobcab97ed551437e2609a61ed1eee8dcc0dd440544
1 #define _GNU_SOURCE
2 #include <unistd.h>
3 #include <sys/types.h>
4 #define L1_CACHE_LINE_MAX 128 /* largest I've seen (Pentium 4) */
5 size_t rb_sp_l1_cache_line_size;
7 #ifdef HAVE_SYS_EVENT_H
8 void sleepy_penguin_init_kqueue(void);
9 #else
10 # define sleepy_penguin_init_kqueue() for(;0;)
11 #endif
13 #ifdef HAVE_SYS_EPOLL_H
14 void sleepy_penguin_init_epoll(void);
15 #else
16 # define sleepy_penguin_init_epoll() for(;0;)
17 #endif
19 #ifdef HAVE_SYS_TIMERFD_H
20 void sleepy_penguin_init_timerfd(void);
21 #else
22 # define sleepy_penguin_init_timerfd() for(;0;)
23 #endif
25 #ifdef HAVE_SYS_EVENTFD_H
26 void sleepy_penguin_init_eventfd(void);
27 #else
28 # define sleepy_penguin_init_eventfd() for(;0;)
29 #endif
31 #ifdef HAVE_SYS_INOTIFY_H
32 void sleepy_penguin_init_inotify(void);
33 #else
34 # define sleepy_penguin_init_inotify() for(;0;)
35 #endif
37 #ifdef HAVE_SYS_SIGNALFD_H
38 void sleepy_penguin_init_signalfd(void);
39 #else
40 # define sleepy_penguin_init_signalfd() for(;0;)
41 #endif
43 static size_t l1_cache_line_size_detect(void)
45 #ifdef _SC_LEVEL1_DCACHE_LINESIZE
46 long tmp = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
48 if (tmp > 0 && tmp <= L1_CACHE_LINE_MAX)
49 return (size_t)tmp;
50 #endif /* _SC_LEVEL1_DCACHE_LINESIZE */
51 return L1_CACHE_LINE_MAX;
54 void Init_sleepy_penguin_ext(void)
56 rb_sp_l1_cache_line_size = l1_cache_line_size_detect();
58 sleepy_penguin_init_kqueue();
59 sleepy_penguin_init_epoll();
60 sleepy_penguin_init_timerfd();
61 sleepy_penguin_init_eventfd();
62 sleepy_penguin_init_inotify();
63 sleepy_penguin_init_signalfd();