23 #include "precompiled.h"
31 #include <sys/inotify.h>
111 struct inotify_event *pevent;
120 pevent = (
struct inotify_event *) &buffer[buffer_i];
122 event_size = offsetof(
struct inotify_event, name) + pevent->len;
125 ne.
code = pevent->mask;
131 buffer_i += event_size;
144 while(select(
inotifyfd+1, &fdrset, NULL, NULL, NULL) < 0)
152 else if(errno == EBADF)
161 debug_printf(L
"inotify_event_loop: select error errno=%d\n", errno);
187 LOGERROR(L
"Error initializing inotify file descriptor; hotloading will be disabled, errno=%d", err);
197 LOGERROR(L
"Error creating inotify event loop thread; hotloading will be disabled, err=%d", ret);
208 int wd = inotify_add_watch(
inotifyfd, realpath(
OsString(path).c_str(), resolved), IN_CREATE | IN_DELETE | IN_CLOSE_WRITE);
212 dirWatch.swap(tmpDirWatch);
213 dirWatch->path = path;
214 dirWatch->reqnum = wd;
215 g_paths.insert(std::make_pair(wd, dirWatch));
227 std::vector<NotificationEvent> polled_notifications;
233 for(
size_t i = 0; i < polled_notifications.size(); ++i)
237 switch(polled_notifications[i].code)
252 DirWatchMap::iterator it =
g_paths.find(polled_notifications[i].wd);
255 OsPath filename =
Path(
OsString(it->second->path).append(polled_notifications[i].filename));
260 debug_printf(L
"dir_watch_Poll: Notification with invalid watch descriptor wd=%d\n", polled_notifications[i].wd);
std::vector< DirWatchNotification > DirWatchNotifications
static DirWatchMap g_paths
static void * inotify_event_loop(void *)
static pthread_t g_event_loop_thread
std::map< int, PDirWatch > DirWatchMap
LIB_API Status dir_watch_Add(const OsPath &path, PDirWatch &dirWatch)
start watching a single directory for changes.
static std::vector< NotificationEvent > g_notifications
static void inotify_deinit()
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
int pthread_create(pthread_t *thread_id, const void *attr, void *(*func)(void *), void *arg)
static void inotify_event_loop_process_events()
shared_ptr< DirWatch > PDirWatch
LIB_API Status dir_watch_Poll(DirWatchNotifications ¬ifications)
return all pending directory watch notifications.
int read(int fd, void *buf, size_t nbytes)
int pthread_mutex_lock(pthread_mutex_t *m)
i64 Status
Error handling system.
static pthread_mutex_t g_mutex
int pthread_mutex_unlock(pthread_mutex_t *m)
#define WARN_RETURN(status)
int pthread_join(pthread_t thread, void **value_ptr)
#define PTHREAD_MUTEX_INITIALIZER
int pthread_cancel(pthread_t thread)
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
static std::string OsString(const OsPath &path)