Lines Matching refs:thread

64 #define	LINK_THREAD(thread)	LINK(thread, &_thread_registry)  argument
174 pthread_t thread; member
248 static void _free_thread_status(struct thread_status *thread) in _free_thread_status() argument
250 if (thread->current_task) in _free_thread_status()
251 dm_task_destroy(thread->current_task); in _free_thread_status()
252 dm_free(thread->device.uuid); in _free_thread_status()
253 dm_free(thread->device.name); in _free_thread_status()
254 dm_free(thread); in _free_thread_status()
461 struct thread_status *thread; in _lookup_thread_status() local
463 dm_list_iterate_items(thread, &_thread_registry) in _lookup_thread_status()
464 if (!strcmp(data->device_uuid, thread->device.uuid)) in _lookup_thread_status()
465 return thread; in _lookup_thread_status()
494 struct thread_status *thread; in _timeout_thread() local
499 dm_list_iterate_items_gen(thread, &_timeout_registry, timeout_list) { in _timeout_thread()
500 if (thread->next_time <= curr_time) { in _timeout_thread()
501 thread->next_time = curr_time + thread->timeout; in _timeout_thread()
502 pthread_kill(thread->thread, SIGALRM); in _timeout_thread()
505 if (thread->next_time < timeout.tv_sec || !timeout.tv_sec) in _timeout_thread()
506 timeout.tv_sec = thread->next_time; in _timeout_thread()
518 static int _register_for_timeout(struct thread_status *thread) in _register_for_timeout() argument
524 thread->next_time = time(NULL) + thread->timeout; in _register_for_timeout()
526 if (dm_list_empty(&thread->timeout_list)) { in _register_for_timeout()
527 dm_list_add(&_timeout_registry, &thread->timeout_list); in _register_for_timeout()
544 static void _unregister_for_timeout(struct thread_status *thread) in _unregister_for_timeout() argument
547 if (!dm_list_empty(&thread->timeout_list)) { in _unregister_for_timeout()
548 dm_list_del(&thread->timeout_list); in _unregister_for_timeout()
549 dm_list_init(&thread->timeout_list); in _unregister_for_timeout()
594 static int _event_wait(struct thread_status *thread, struct dm_task **task) in _event_wait() argument
606 thread->current_task = dmt; in _event_wait()
608 if (!dm_task_set_uuid(dmt, thread->device.uuid) || in _event_wait()
609 !dm_task_set_event_nr(dmt, thread->event_nr)) in _event_wait()
620 thread->current_events |= DM_EVENT_DEVICE_ERROR; in _event_wait()
624 thread->event_nr = info.event_nr; in _event_wait()
625 } else if (thread->events & DM_EVENT_TIMEOUT && errno == EINTR) { in _event_wait()
626 thread->current_events |= DM_EVENT_TIMEOUT; in _event_wait()
628 } else if (thread->status == DM_THREAD_SHUTDOWN && errno == EINTR) { in _event_wait()
635 thread->device.name); in _event_wait()
646 thread->current_task = NULL; in _event_wait()
654 static int _do_register_device(struct thread_status *thread) in _do_register_device() argument
656 return thread->dso_data->register_device(thread->device.name, in _do_register_device()
657 thread->device.uuid, in _do_register_device()
658 thread->device.major, in _do_register_device()
659 thread->device.minor, in _do_register_device()
660 &(thread->dso_private)); in _do_register_device()
664 static int _do_unregister_device(struct thread_status *thread) in _do_unregister_device() argument
666 return thread->dso_data->unregister_device(thread->device.name, in _do_unregister_device()
667 thread->device.uuid, in _do_unregister_device()
668 thread->device.major, in _do_unregister_device()
669 thread->device.minor, in _do_unregister_device()
670 &(thread->dso_private)); in _do_unregister_device()
674 static void _do_process_event(struct thread_status *thread, struct dm_task *task) in _do_process_event() argument
676 thread->dso_data->process_event(task, thread->current_events, &(thread->dso_private)); in _do_process_event()
682 struct thread_status *thread = arg, *thread_iter; in _monitor_unregister() local
684 if (!_do_unregister_device(thread)) in _monitor_unregister()
686 thread->device.name); in _monitor_unregister()
687 if (thread->current_task) in _monitor_unregister()
688 dm_task_destroy(thread->current_task); in _monitor_unregister()
689 thread->current_task = NULL; in _monitor_unregister()
692 if (thread->events & DM_EVENT_TIMEOUT) { in _monitor_unregister()
697 _unregister_for_timeout(thread); in _monitor_unregister()
703 if (thread_iter == thread) { in _monitor_unregister()
704 thread->status = DM_THREAD_DONE; in _monitor_unregister()
708 thread->status = DM_THREAD_DONE; in _monitor_unregister()
709 UNLINK_THREAD(thread); in _monitor_unregister()
710 LINK(thread, &_thread_registry_unused); in _monitor_unregister()
734 struct thread_status *thread = arg; in _monitor_thread() local
739 pthread_cleanup_push(_monitor_unregister, thread); in _monitor_thread()
743 thread->status = DM_THREAD_RUNNING; in _monitor_thread()
748 thread->current_events = 0; in _monitor_thread()
750 wait_error = _event_wait(thread, &task); in _monitor_thread()
761 thread->current_events & DM_EVENT_TIMEOUT) { in _monitor_thread()
763 task = _get_device_status(thread); in _monitor_thread()
765 if (!(thread->current_task = task)) in _monitor_thread()
783 if (thread->status == DM_THREAD_SHUTDOWN) { in _monitor_thread()
789 if (thread->events & thread->current_events) { in _monitor_thread()
791 thread->processing = 1; in _monitor_thread()
794 _do_process_event(thread, task); in _monitor_thread()
796 thread->current_task = NULL; in _monitor_thread()
799 thread->processing = 0; in _monitor_thread()
803 thread->current_task = NULL; in _monitor_thread()
813 static int _create_thread(struct thread_status *thread) in _create_thread() argument
815 return _pthread_create_smallstack(&thread->thread, _monitor_thread, thread); in _create_thread()
818 static int _terminate_thread(struct thread_status *thread) in _terminate_thread() argument
820 return pthread_kill(thread->thread, SIGALRM); in _terminate_thread()
928 struct thread_status *thread, *thread_new = NULL; in _register_for_event() local
971 if (!(thread = _lookup_thread_status(message_data))) { in _register_for_event()
977 thread = thread_new; in _register_for_event()
982 if ((ret = -_create_thread(thread))) { in _register_for_event()
984 _do_unregister_device(thread); in _register_for_event()
985 _free_thread_status(thread); in _register_for_event()
988 LINK_THREAD(thread); in _register_for_event()
992 thread->events |= message_data->events.field; in _register_for_event()
1015 struct thread_status *thread; in _unregister_for_event() local
1023 if (!(thread = _lookup_thread_status(message_data))) { in _unregister_for_event()
1029 if (thread->status == DM_THREAD_DONE) { in _unregister_for_event()
1036 thread->events &= ~message_data->events.field; in _unregister_for_event()
1038 if (!(thread->events & DM_EVENT_TIMEOUT)) in _unregister_for_event()
1039 _unregister_for_timeout(thread); in _unregister_for_event()
1044 if (!thread->events) { in _unregister_for_event()
1045 UNLINK_THREAD(thread); in _unregister_for_event()
1046 LINK(thread, &_thread_registry_unused); in _unregister_for_event()
1060 struct thread_status *thread) in _registered_device() argument
1066 const char *dso = thread->dso_data->dso_name; in _registered_device()
1067 const char *dev = thread->device.uuid; in _registered_device()
1068 unsigned events = ((thread->status == DM_THREAD_RUNNING) in _registered_device()
1069 && (thread->events)) ? thread->events : thread-> in _registered_device()
1083 struct thread_status *thread) in _want_registered_device() argument
1087 return !strcmp(dso_name, thread->dso_data->dso_name) && in _want_registered_device()
1088 !strcmp(device_uuid, thread->device.uuid) && in _want_registered_device()
1089 (thread->status == DM_THREAD_RUNNING || in _want_registered_device()
1090 (thread->events & DM_EVENT_REGISTRATION_PENDING)); in _want_registered_device()
1094 return !strcmp(dso_name, thread->dso_data->dso_name) && in _want_registered_device()
1095 (thread->status == DM_THREAD_RUNNING || in _want_registered_device()
1096 (thread->events & DM_EVENT_REGISTRATION_PENDING)); in _want_registered_device()
1100 return !strcmp(device_uuid, thread->device.uuid) && in _want_registered_device()
1101 (thread->status == DM_THREAD_RUNNING || in _want_registered_device()
1102 (thread->events & DM_EVENT_REGISTRATION_PENDING)); in _want_registered_device()
1109 struct thread_status *thread, *hit = NULL; in _get_registered_dev() local
1114 dm_list_iterate_items(thread, &_thread_registry) in _get_registered_dev()
1117 thread)) { in _get_registered_dev()
1118 hit = thread; in _get_registered_dev()
1134 thread = hit; in _get_registered_dev()
1137 if (dm_list_end(&_thread_registry, &thread->list)) in _get_registered_dev()
1140 thread = dm_list_item(thread->list.n, struct thread_status); in _get_registered_dev()
1141 if (_want_registered_device(message_data->dso_name, NULL, thread)) { in _get_registered_dev()
1142 hit = thread; in _get_registered_dev()
1168 struct thread_status *thread; in _set_timeout() local
1171 if ((thread = _lookup_thread_status(message_data))) in _set_timeout()
1172 thread->timeout = message_data->timeout.secs; in _set_timeout()
1175 return thread ? 0 : -ENODEV; in _set_timeout()
1180 struct thread_status *thread; in _get_timeout() local
1187 if ((thread = _lookup_thread_status(message_data))) { in _get_timeout()
1190 thread->timeout); in _get_timeout()
1197 return thread ? 0 : -ENODEV; in _get_timeout()
1445 struct thread_status *thread; in _cleanup_unused_threads() local
1449 thread = dm_list_item(l, struct thread_status); in _cleanup_unused_threads()
1450 if (thread->processing) in _cleanup_unused_threads()
1453 if (thread->status == DM_THREAD_RUNNING) { in _cleanup_unused_threads()
1454 thread->status = DM_THREAD_SHUTDOWN; in _cleanup_unused_threads()
1458 if (thread->status == DM_THREAD_SHUTDOWN) { in _cleanup_unused_threads()
1459 if (!thread->events) { in _cleanup_unused_threads()
1461 ret = _terminate_thread(thread); in _cleanup_unused_threads()
1464 thread->status = DM_THREAD_DONE; in _cleanup_unused_threads()
1477 thread->status = DM_THREAD_RUNNING; in _cleanup_unused_threads()
1478 LINK_THREAD(thread); in _cleanup_unused_threads()
1483 if (thread->status == DM_THREAD_DONE) { in _cleanup_unused_threads()
1485 pthread_join(thread->thread, NULL); in _cleanup_unused_threads()
1486 _lib_put(thread->dso_data); in _cleanup_unused_threads()
1487 _free_thread_status(thread); in _cleanup_unused_threads()