Lines Matching defs:handle
29 int uv__fsevents_init(uv_fs_event_t* handle) {
34 int uv__fsevents_close(uv_fs_event_t* handle) {
84 uv_fs_event_t* handle;
109 uv_fs_event_t* handle,
151 #define UV__FSEVENTS_PROCESS(handle, block) \
157 uv_mutex_lock(&(handle)->cf_mutex); \
159 uv__queue_move(&(handle)->cf_events, &events); \
161 err = (handle)->cf_error; \
162 (handle)->cf_error = 0; \
163 uv_mutex_unlock(&(handle)->cf_mutex); \
169 /* NOTE: Checking uv__is_active() is required here, because handle \
170 * callback may close handle and invoking it after it will lead to \
172 if (!uv__is_closing((handle)) && uv__is_active((handle))) \
177 if (err != 0 && !uv__is_closing((handle)) && uv__is_active((handle))) \
178 (handle)->cb((handle), NULL, 0, err); \
182 /* Runs in UV loop's thread, when there're events to report to handle */
184 uv_fs_event_t* handle;
186 handle = cb->data;
188 UV__FSEVENTS_PROCESS(handle, {
189 handle->cb(handle, event->path[0] ? event->path : NULL, event->events, 0);
194 /* Runs in CF thread, pushed event into handle's event list */
195 static void uv__fsevents_push_event(uv_fs_event_t* handle,
199 uv_mutex_lock(&handle->cf_mutex);
203 uv__queue_add(&handle->cf_events, events);
207 handle->cf_error = err;
208 uv_mutex_unlock(&handle->cf_mutex);
210 uv_async_send(handle->cf_cb);
226 uv_fs_event_t* handle;
239 /* For each handle */
242 handle = uv__queue_data(q, uv_fs_event_t, cf_member);
256 if (handle->realpath_len == 0)
259 /* Filter out paths that are outside handle's request */
260 if (len < handle->realpath_len)
266 if (handle->realpath_len != len &&
267 handle->realpath_len > 1 &&
268 path[handle->realpath_len] != '/')
271 if (memcmp(path, handle->realpath, handle->realpath_len) != 0)
274 if (!(handle->realpath_len == 1 && handle->realpath[0] == '/')) {
276 path += handle->realpath_len;
277 len -= handle->realpath_len;
287 while (len < handle->realpath_len && path[-1] != '/') {
301 if ((handle->cf_flags & UV_FS_EVENT_RECURSIVE) == 0 && *path != '\0') {
325 uv__fsevents_push_event(handle, &head, 0);
497 * Main thread will block until the removal of handle from the list,
539 #define V(handle, symbol) \
541 *(void **)(&p ## symbol) = dlsym((handle), #symbol); \
756 if (s->handle == NULL)
768 uv_fs_event_t* handle,
777 item->handle = handle;
794 /* Runs in UV loop to initialize handle */
795 int uv__fsevents_init(uv_fs_event_t* handle) {
799 err = uv__fsevents_loop_init(handle->loop);
804 handle->realpath = realpath(handle->path, NULL);
805 if (handle->realpath == NULL)
807 handle->realpath_len = strlen(handle->realpath);
810 uv__queue_init(&handle->cf_events);
811 handle->cf_error = 0;
817 handle->cf_cb = uv__malloc(sizeof(*handle->cf_cb));
818 if (handle->cf_cb == NULL) {
823 handle->cf_cb->data = handle;
824 uv_async_init(handle->loop, handle->cf_cb, uv__fsevents_cb);
825 handle->cf_cb->flags |= UV_HANDLE_INTERNAL;
826 uv_unref((uv_handle_t*) handle->cf_cb);
828 err = uv_mutex_init(&handle->cf_mutex);
832 /* Insert handle into the list */
833 state = handle->loop->cf_state;
835 uv__queue_insert_tail(&state->fsevent_handles, &handle->cf_member);
841 assert(handle != NULL);
842 err = uv__cf_loop_signal(handle->loop, handle, kUVCFLoopSignalRegular);
849 uv_mutex_destroy(&handle->cf_mutex);
852 uv__free(handle->cf_cb);
853 handle->cf_cb = NULL;
856 uv__free(handle->realpath);
857 handle->realpath = NULL;
858 handle->realpath_len = 0;
864 /* Runs in UV loop to de-initialize handle */
865 int uv__fsevents_close(uv_fs_event_t* handle) {
869 if (handle->cf_cb == NULL)
872 /* Remove handle from the list */
873 state = handle->loop->cf_state;
875 uv__queue_remove(&handle->cf_member);
881 assert(handle != NULL);
882 err = uv__cf_loop_signal(handle->loop, handle, kUVCFLoopSignalClosing);
889 uv_close((uv_handle_t*) handle->cf_cb, (uv_close_cb) uv__free);
890 handle->cf_cb = NULL;
893 UV__FSEVENTS_PROCESS(handle, {
897 uv_mutex_destroy(&handle->cf_mutex);
898 uv__free(handle->realpath);
899 handle->realpath = NULL;
900 handle->realpath_len = 0;