… | |
… | |
281 | perror (msg); |
281 | perror (msg); |
282 | abort (); |
282 | abort (); |
283 | } |
283 | } |
284 | } |
284 | } |
285 | |
285 | |
286 | static void *(*alloc)(void *ptr, size_t size) = realloc; |
286 | static void *(*alloc)(void *ptr, long size); |
287 | |
287 | |
288 | void |
288 | void |
289 | ev_set_allocator (void *(*cb)(void *ptr, size_t size)) |
289 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
290 | { |
290 | { |
291 | alloc = cb; |
291 | alloc = cb; |
292 | } |
292 | } |
293 | |
293 | |
294 | inline_speed void * |
294 | inline_speed void * |
295 | ev_realloc (void *ptr, size_t size) |
295 | ev_realloc (void *ptr, long size) |
296 | { |
296 | { |
297 | ptr = alloc (ptr, size); |
297 | ptr = alloc ? alloc (ptr, size) : realloc (ptr, size); |
298 | |
298 | |
299 | if (!ptr && size) |
299 | if (!ptr && size) |
300 | { |
300 | { |
301 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", (long)size); |
301 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
302 | abort (); |
302 | abort (); |
303 | } |
303 | } |
304 | |
304 | |
305 | return ptr; |
305 | return ptr; |
306 | } |
306 | } |
… | |
… | |
324 | { |
324 | { |
325 | W w; |
325 | W w; |
326 | int events; |
326 | int events; |
327 | } ANPENDING; |
327 | } ANPENDING; |
328 | |
328 | |
|
|
329 | #if EV_USE_INOTIFY |
329 | typedef struct |
330 | typedef struct |
330 | { |
331 | { |
331 | #if EV_USE_INOTIFY |
|
|
332 | WL head; |
332 | WL head; |
333 | #endif |
|
|
334 | } ANFS; |
333 | } ANFS; |
|
|
334 | #endif |
335 | |
335 | |
336 | #if EV_MULTIPLICITY |
336 | #if EV_MULTIPLICITY |
337 | |
337 | |
338 | struct ev_loop |
338 | struct ev_loop |
339 | { |
339 | { |
… | |
… | |
985 | array_free (check, EMPTY0); |
985 | array_free (check, EMPTY0); |
986 | |
986 | |
987 | backend = 0; |
987 | backend = 0; |
988 | } |
988 | } |
989 | |
989 | |
|
|
990 | void inline_size infy_fork (EV_P); |
|
|
991 | |
990 | void inline_size |
992 | void inline_size |
991 | loop_fork (EV_P) |
993 | loop_fork (EV_P) |
992 | { |
994 | { |
993 | #if EV_USE_PORT |
995 | #if EV_USE_PORT |
994 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
996 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
… | |
… | |
996 | #if EV_USE_KQUEUE |
998 | #if EV_USE_KQUEUE |
997 | if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
999 | if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
998 | #endif |
1000 | #endif |
999 | #if EV_USE_EPOLL |
1001 | #if EV_USE_EPOLL |
1000 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
1002 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
|
|
1003 | #endif |
|
|
1004 | #if EV_USE_INOTIFY |
|
|
1005 | infy_fork (EV_A); |
1001 | #endif |
1006 | #endif |
1002 | |
1007 | |
1003 | if (ev_is_active (&sigev)) |
1008 | if (ev_is_active (&sigev)) |
1004 | { |
1009 | { |
1005 | /* default loop */ |
1010 | /* default loop */ |
… | |
… | |
1831 | ev_set_priority (&fs_w, EV_MAXPRI); |
1836 | ev_set_priority (&fs_w, EV_MAXPRI); |
1832 | ev_io_start (EV_A_ &fs_w); |
1837 | ev_io_start (EV_A_ &fs_w); |
1833 | } |
1838 | } |
1834 | } |
1839 | } |
1835 | |
1840 | |
|
|
1841 | void inline_size |
|
|
1842 | infy_fork (EV_P) |
|
|
1843 | { |
|
|
1844 | int slot; |
|
|
1845 | |
|
|
1846 | if (fs_fd < 0) |
|
|
1847 | return; |
|
|
1848 | |
|
|
1849 | close (fs_fd); |
|
|
1850 | fs_fd = inotify_init (); |
|
|
1851 | |
|
|
1852 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
|
|
1853 | { |
|
|
1854 | WL w_ = fs_hash [slot].head; |
|
|
1855 | fs_hash [slot].head = 0; |
|
|
1856 | |
|
|
1857 | while (w_) |
|
|
1858 | { |
|
|
1859 | ev_stat *w = (ev_stat *)w_; |
|
|
1860 | w_ = w_->next; /* lets us add this watcher */ |
|
|
1861 | |
|
|
1862 | w->wd = -1; |
|
|
1863 | |
|
|
1864 | if (fs_fd >= 0) |
|
|
1865 | infy_add (EV_A_ w); /* re-add, no matter what */ |
|
|
1866 | else |
|
|
1867 | ev_timer_start (EV_A_ &w->timer); |
|
|
1868 | } |
|
|
1869 | |
|
|
1870 | } |
|
|
1871 | } |
|
|
1872 | |
1836 | #endif |
1873 | #endif |
1837 | |
1874 | |
1838 | void |
1875 | void |
1839 | ev_stat_stat (EV_P_ ev_stat *w) |
1876 | ev_stat_stat (EV_P_ ev_stat *w) |
1840 | { |
1877 | { |
… | |
… | |
1852 | /* we copy this here each the time so that */ |
1889 | /* we copy this here each the time so that */ |
1853 | /* prev has the old value when the callback gets invoked */ |
1890 | /* prev has the old value when the callback gets invoked */ |
1854 | w->prev = w->attr; |
1891 | w->prev = w->attr; |
1855 | ev_stat_stat (EV_A_ w); |
1892 | ev_stat_stat (EV_A_ w); |
1856 | |
1893 | |
1857 | if (memcmp (&w->prev, &w->attr, sizeof (ev_statdata))) |
1894 | /* memcmp doesn't work on netbsd, they.... do stuff to their struct stat */ |
|
|
1895 | if ( |
|
|
1896 | w->prev.st_dev != w->attr.st_dev |
|
|
1897 | || w->prev.st_ino != w->attr.st_ino |
|
|
1898 | || w->prev.st_mode != w->attr.st_mode |
|
|
1899 | || w->prev.st_nlink != w->attr.st_nlink |
|
|
1900 | || w->prev.st_uid != w->attr.st_uid |
|
|
1901 | || w->prev.st_gid != w->attr.st_gid |
|
|
1902 | || w->prev.st_rdev != w->attr.st_rdev |
|
|
1903 | || w->prev.st_size != w->attr.st_size |
|
|
1904 | || w->prev.st_atime != w->attr.st_atime |
|
|
1905 | || w->prev.st_mtime != w->attr.st_mtime |
|
|
1906 | || w->prev.st_ctime != w->attr.st_ctime |
1858 | { |
1907 | ) { |
1859 | #if EV_USE_INOTIFY |
1908 | #if EV_USE_INOTIFY |
1860 | infy_del (EV_A_ w); |
1909 | infy_del (EV_A_ w); |
1861 | infy_add (EV_A_ w); |
1910 | infy_add (EV_A_ w); |
1862 | ev_stat_stat (EV_A_ w); /* avoid race... */ |
1911 | ev_stat_stat (EV_A_ w); /* avoid race... */ |
1863 | #endif |
1912 | #endif |