Lines Matching refs:tp
41 struct lws_threadpool *tp; member
64 struct lws_threadpool *tp; member
164 lws_threadpool_dump(struct lws_threadpool *tp) in lws_threadpool_dump() argument
171 pthread_mutex_lock(&tp->lock); /* ======================== tpool lock */ in lws_threadpool_dump()
174 tp->name, tp->queue_depth, tp->running_tasks, in lws_threadpool_dump()
175 tp->done_queue_depth); in lws_threadpool_dump()
178 c = &tp->task_queue_head; in lws_threadpool_dump()
188 if (count != tp->queue_depth) in lws_threadpool_dump()
190 __func__, tp->queue_depth, count); in lws_threadpool_dump()
193 for (n = 0; n < tp->threads_in_pool; n++) { in lws_threadpool_dump()
194 struct lws_pool *pool = &tp->pool_list[n]; in lws_threadpool_dump()
204 if (count != tp->running_tasks) in lws_threadpool_dump()
206 __func__, tp->running_tasks, count); in lws_threadpool_dump()
209 c = &tp->task_done_head; in lws_threadpool_dump()
219 if (count != tp->done_queue_depth) in lws_threadpool_dump()
221 __func__, tp->done_queue_depth, count); in lws_threadpool_dump()
223 pthread_mutex_unlock(&tp->lock); /* --------------- tp unlock */ in lws_threadpool_dump()
245 __func__, task->tp, task->args.wsi); in lws_threadpool_task_cleanup_destroy()
254 struct lws_threadpool *tp = task->tp; in __lws_threadpool_reap() local
258 c = &tp->task_done_head; in __lws_threadpool_reap()
265 tp->done_queue_depth--; in __lws_threadpool_reap()
268 tp->name, task->args.wsi); in __lws_threadpool_reap()
293 struct lws_threadpool *tp; in lws_threadpool_tsi_context() local
298 tp = context->tp_list_head; in lws_threadpool_tsi_context()
299 while (tp) { in lws_threadpool_tsi_context()
304 for (n = 0; n < tp->threads_in_pool; n++) { in lws_threadpool_tsi_context()
305 struct lws_pool *pool = &tp->pool_list[n]; in lws_threadpool_tsi_context()
330 c = &tp->task_done_head; in lws_threadpool_tsi_context()
354 tp = tp->tp_list; in lws_threadpool_tsi_context()
376 pool->tp->name, task, task->name, task->args.wsi); in lws_threadpool_worker_sync()
392 "wsi to sync to\n", __func__, pool->tp->name, in lws_threadpool_worker_sync()
433 __func__, pool->tp->name, task, in lws_threadpool_worker_sync()
461 struct lws_threadpool *tp = pool->tp; in lws_threadpool_worker() local
464 while (!tp->destroying) { in lws_threadpool_worker()
468 pthread_mutex_lock(&tp->lock); /* =================== tp lock */ in lws_threadpool_worker()
474 while (!tp->task_queue_head && !tp->destroying) in lws_threadpool_worker()
475 pthread_cond_wait(&tp->wake_idle, &tp->lock); in lws_threadpool_worker()
477 if (tp->destroying) { in lws_threadpool_worker()
478 pthread_mutex_unlock(&tp->lock); /* ------ tp unlock */ in lws_threadpool_worker()
482 c = &tp->task_queue_head; in lws_threadpool_worker()
500 tp->queue_depth--; in lws_threadpool_worker()
507 pthread_mutex_unlock(&tp->lock); /* ------ tp unlock */ in lws_threadpool_worker()
518 __func__, tp->name, pool->worker_index, buf); in lws_threadpool_worker()
519 tp->running_tasks++; in lws_threadpool_worker()
521 pthread_mutex_unlock(&tp->lock); /* --------------- tp unlock */ in lws_threadpool_worker()
550 if (tp->destroying || !task->args.wsi) { in lws_threadpool_worker()
587 pthread_mutex_lock(&tp->lock); /* =================== tp lock */ in lws_threadpool_worker()
589 tp->running_tasks--; in lws_threadpool_worker()
596 pool->task->task_queue_next = tp->task_done_head; in lws_threadpool_worker()
597 tp->task_done_head = task; in lws_threadpool_worker()
598 tp->done_queue_depth++; in lws_threadpool_worker()
607 __func__, tp->name, pool->worker_index, in lws_threadpool_worker()
620 __func__, tp->name, pool->worker_index, in lws_threadpool_worker()
635 pthread_mutex_unlock(&tp->lock); /* --------------- tp unlock */ in lws_threadpool_worker()
650 struct lws_threadpool *tp; in lws_threadpool_create() local
654 tp = lws_malloc(sizeof(*tp) + (sizeof(struct lws_pool) * args->threads), in lws_threadpool_create()
656 if (!tp) in lws_threadpool_create()
659 memset(tp, 0, sizeof(*tp) + (sizeof(struct lws_pool) * args->threads)); in lws_threadpool_create()
660 tp->pool_list = (struct lws_pool *)(tp + 1); in lws_threadpool_create()
661 tp->max_queue_depth = args->max_queue_depth; in lws_threadpool_create()
664 n = vsnprintf(tp->name, sizeof(tp->name) - 1, format, ap); in lws_threadpool_create()
669 tp->context = context; in lws_threadpool_create()
670 tp->tp_list = context->tp_list_head; in lws_threadpool_create()
671 context->tp_list_head = tp; in lws_threadpool_create()
675 pthread_mutex_init(&tp->lock, NULL); in lws_threadpool_create()
676 pthread_cond_init(&tp->wake_idle, NULL); in lws_threadpool_create()
682 tp->pool_list[n].tp = tp; in lws_threadpool_create()
683 tp->pool_list[n].worker_index = n; in lws_threadpool_create()
684 pthread_mutex_init(&tp->pool_list[n].lock, NULL); in lws_threadpool_create()
685 if (pthread_create(&tp->pool_list[n].thread, NULL, in lws_threadpool_create()
686 lws_threadpool_worker, &tp->pool_list[n])) { in lws_threadpool_create()
690 lws_snprintf(name, sizeof(name), "%s-%d", tp->name, n); in lws_threadpool_create()
691 pthread_setname_np(tp->pool_list[n].thread, name); in lws_threadpool_create()
693 tp->threads_in_pool++; in lws_threadpool_create()
697 return tp; in lws_threadpool_create()
701 lws_threadpool_finish(struct lws_threadpool *tp) in lws_threadpool_finish() argument
705 pthread_mutex_lock(&tp->lock); /* ======================== tpool lock */ in lws_threadpool_finish()
709 tp->destroying = 1; in lws_threadpool_finish()
713 c = &tp->task_queue_head; in lws_threadpool_finish()
717 task->task_queue_next = tp->task_done_head; in lws_threadpool_finish()
718 tp->task_done_head = task; in lws_threadpool_finish()
720 tp->queue_depth--; in lws_threadpool_finish()
721 tp->done_queue_depth++; in lws_threadpool_finish()
727 pthread_mutex_unlock(&tp->lock); /* -------------------- tpool unlock */ in lws_threadpool_finish()
729 pthread_cond_broadcast(&tp->wake_idle); in lws_threadpool_finish()
733 lws_threadpool_destroy(struct lws_threadpool *tp) in lws_threadpool_destroy() argument
742 lws_context_lock(tp->context, __func__); in lws_threadpool_destroy()
744 ptp = &tp->context->tp_list_head; in lws_threadpool_destroy()
746 if (*ptp == tp) { in lws_threadpool_destroy()
747 *ptp = tp->tp_list; in lws_threadpool_destroy()
753 lws_context_unlock(tp->context); in lws_threadpool_destroy()
756 pthread_mutex_lock(&tp->lock); /* ======================== tpool lock */ in lws_threadpool_destroy()
758 tp->destroying = 1; in lws_threadpool_destroy()
759 pthread_cond_broadcast(&tp->wake_idle); in lws_threadpool_destroy()
760 pthread_mutex_unlock(&tp->lock); /* -------------------- tpool unlock */ in lws_threadpool_destroy()
762 lws_threadpool_dump(tp); in lws_threadpool_destroy()
764 for (n = 0; n < tp->threads_in_pool; n++) { in lws_threadpool_destroy()
765 task = tp->pool_list[n].task; in lws_threadpool_destroy()
772 pthread_join(tp->pool_list[n].thread, &retval); in lws_threadpool_destroy()
773 pthread_mutex_destroy(&tp->pool_list[n].lock); in lws_threadpool_destroy()
777 task = tp->task_done_head; in lws_threadpool_destroy()
781 tp->done_queue_depth--; in lws_threadpool_destroy()
785 pthread_mutex_destroy(&tp->lock); in lws_threadpool_destroy()
787 lws_free(tp); in lws_threadpool_destroy()
798 struct lws_threadpool *tp; in lws_threadpool_dequeue() local
806 tp = task->tp; in lws_threadpool_dequeue()
807 pthread_mutex_lock(&tp->lock); /* ======================== tpool lock */ in lws_threadpool_dequeue()
809 if (task->outlive && !tp->destroying) { in lws_threadpool_dequeue()
820 c = &tp->task_queue_head; in lws_threadpool_dequeue()
828 task->task_queue_next = tp->task_done_head; in lws_threadpool_dequeue()
829 tp->task_done_head = task; in lws_threadpool_dequeue()
831 tp->queue_depth--; in lws_threadpool_dequeue()
832 tp->done_queue_depth++; in lws_threadpool_dequeue()
836 __func__, tp, task->args.wsi); in lws_threadpool_dequeue()
845 c = &tp->task_done_head; in lws_threadpool_dequeue()
851 tp->done_queue_depth--; in lws_threadpool_dequeue()
859 for (n = 0; n < tp->threads_in_pool; n++) { in lws_threadpool_dequeue()
860 if (!tp->pool_list[n].task || tp->pool_list[n].task != task) in lws_threadpool_dequeue()
867 pthread_mutex_lock(&tp->pool_list[n].lock); in lws_threadpool_dequeue()
881 pthread_mutex_unlock(&tp->pool_list[n].lock); in lws_threadpool_dequeue()
884 "for wsi %p\n", __func__, tp, task->args.wsi); in lws_threadpool_dequeue()
889 if (n == tp->threads_in_pool) { in lws_threadpool_dequeue()
892 __func__, tp, task->args.wsi); in lws_threadpool_dequeue()
898 pthread_mutex_unlock(&tp->lock); /* -------------------- tpool unlock */ in lws_threadpool_dequeue()
904 lws_threadpool_enqueue(struct lws_threadpool *tp, in lws_threadpool_enqueue() argument
911 if (tp->destroying) in lws_threadpool_enqueue()
914 pthread_mutex_lock(&tp->lock); /* ======================== tpool lock */ in lws_threadpool_enqueue()
921 if (tp->queue_depth == tp->max_queue_depth) { in lws_threadpool_enqueue()
923 tp->max_queue_depth); in lws_threadpool_enqueue()
939 task->tp = tp; in lws_threadpool_enqueue()
950 task->task_queue_next = tp->task_queue_head; in lws_threadpool_enqueue()
952 tp->task_queue_head = task; in lws_threadpool_enqueue()
953 tp->queue_depth++; in lws_threadpool_enqueue()
963 __func__, tp->name, task, task->name, args->wsi, in lws_threadpool_enqueue()
964 tp->queue_depth); in lws_threadpool_enqueue()
969 pthread_cond_signal(&tp->wake_idle); in lws_threadpool_enqueue()
972 pthread_mutex_unlock(&tp->lock); /* -------------------- tpool unlock */ in lws_threadpool_enqueue()
984 struct lws_threadpool *tp; in lws_threadpool_task_status_wsi() local
990 tp = (*task)->tp; in lws_threadpool_task_status_wsi()
998 pthread_mutex_lock(&tp->lock); /* ================ tpool lock */ in lws_threadpool_task_status_wsi()
1001 __func__, tp->name, buf); in lws_threadpool_task_status_wsi()
1004 pthread_mutex_unlock(&tp->lock); /* ------------ tpool unlock */ in lws_threadpool_task_status_wsi()