Lines Matching refs:me

82 static apr_status_t thread_pool_construct(apr_thread_pool_t * me,  in thread_pool_construct()  argument
89 me->thd_max = max_threads; in thread_pool_construct()
90 me->idle_max = init_threads; in thread_pool_construct()
91 me->threshold = init_threads / 2; in thread_pool_construct()
92 rv = apr_thread_mutex_create(&me->lock, APR_THREAD_MUTEX_NESTED, in thread_pool_construct()
93 me->pool); in thread_pool_construct()
97 rv = apr_thread_cond_create(&me->cond, me->pool); in thread_pool_construct()
99 apr_thread_mutex_destroy(me->lock); in thread_pool_construct()
102 me->tasks = apr_palloc(me->pool, sizeof(*me->tasks)); in thread_pool_construct()
103 if (!me->tasks) { in thread_pool_construct()
106 APR_RING_INIT(me->tasks, apr_thread_pool_task, link); in thread_pool_construct()
107 me->scheduled_tasks = apr_palloc(me->pool, sizeof(*me->scheduled_tasks)); in thread_pool_construct()
108 if (!me->scheduled_tasks) { in thread_pool_construct()
111 APR_RING_INIT(me->scheduled_tasks, apr_thread_pool_task, link); in thread_pool_construct()
112 me->recycled_tasks = apr_palloc(me->pool, sizeof(*me->recycled_tasks)); in thread_pool_construct()
113 if (!me->recycled_tasks) { in thread_pool_construct()
116 APR_RING_INIT(me->recycled_tasks, apr_thread_pool_task, link); in thread_pool_construct()
117 me->busy_thds = apr_palloc(me->pool, sizeof(*me->busy_thds)); in thread_pool_construct()
118 if (!me->busy_thds) { in thread_pool_construct()
121 APR_RING_INIT(me->busy_thds, apr_thread_list_elt, link); in thread_pool_construct()
122 me->idle_thds = apr_palloc(me->pool, sizeof(*me->idle_thds)); in thread_pool_construct()
123 if (!me->idle_thds) { in thread_pool_construct()
126 APR_RING_INIT(me->idle_thds, apr_thread_list_elt, link); in thread_pool_construct()
127 me->recycled_thds = apr_palloc(me->pool, sizeof(*me->recycled_thds)); in thread_pool_construct()
128 if (!me->recycled_thds) { in thread_pool_construct()
131 APR_RING_INIT(me->recycled_thds, apr_thread_list_elt, link); in thread_pool_construct()
132 me->thd_cnt = me->idle_cnt = me->task_cnt = me->scheduled_task_cnt = 0; in thread_pool_construct()
133 me->tasks_run = me->tasks_high = me->thd_high = me->thd_timed_out = 0; in thread_pool_construct()
134 me->idle_wait = 0; in thread_pool_construct()
135 me->terminated = 0; in thread_pool_construct()
137 me->task_idx[i] = NULL; in thread_pool_construct()
142 apr_thread_mutex_destroy(me->lock); in thread_pool_construct()
143 apr_thread_cond_destroy(me->cond); in thread_pool_construct()
151 static apr_thread_pool_task_t *pop_task(apr_thread_pool_t * me) in pop_task() argument
157 if (me->scheduled_task_cnt > 0) { in pop_task()
158 task = APR_RING_FIRST(me->scheduled_tasks); in pop_task()
161 APR_RING_SENTINEL(me->scheduled_tasks, apr_thread_pool_task, in pop_task()
165 --me->scheduled_task_cnt; in pop_task()
171 if (me->task_cnt == 0) { in pop_task()
175 task = APR_RING_FIRST(me->tasks); in pop_task()
177 assert(task != APR_RING_SENTINEL(me->tasks, apr_thread_pool_task, link)); in pop_task()
178 --me->task_cnt; in pop_task()
180 if (task == me->task_idx[seg]) { in pop_task()
181 me->task_idx[seg] = APR_RING_NEXT(task, link); in pop_task()
182 if (me->task_idx[seg] == APR_RING_SENTINEL(me->tasks, in pop_task()
184 || TASK_PRIORITY_SEG(me->task_idx[seg]) != seg) { in pop_task()
185 me->task_idx[seg] = NULL; in pop_task()
192 static apr_interval_time_t waiting_time(apr_thread_pool_t * me) in waiting_time() argument
196 task = APR_RING_FIRST(me->scheduled_tasks); in waiting_time()
199 APR_RING_SENTINEL(me->scheduled_tasks, apr_thread_pool_task, in waiting_time()
207 static struct apr_thread_list_elt *elt_new(apr_thread_pool_t * me, in elt_new() argument
212 if (APR_RING_EMPTY(me->recycled_thds, apr_thread_list_elt, link)) { in elt_new()
213 elt = apr_pcalloc(me->pool, sizeof(*elt)); in elt_new()
219 elt = APR_RING_FIRST(me->recycled_thds); in elt_new()
240 apr_thread_pool_t *me = param; in thread_pool_func() local
245 apr_thread_mutex_lock(me->lock); in thread_pool_func()
246 elt = elt_new(me, t); in thread_pool_func()
248 apr_thread_mutex_unlock(me->lock); in thread_pool_func()
252 while (!me->terminated && elt->state != TH_STOP) { in thread_pool_func()
255 --me->idle_cnt; in thread_pool_func()
259 APR_RING_INSERT_TAIL(me->busy_thds, elt, apr_thread_list_elt, link); in thread_pool_func()
260 task = pop_task(me); in thread_pool_func()
261 while (NULL != task && !me->terminated) { in thread_pool_func()
262 ++me->tasks_run; in thread_pool_func()
264 apr_thread_mutex_unlock(me->lock); in thread_pool_func()
267 apr_thread_mutex_lock(me->lock); in thread_pool_func()
268 APR_RING_INSERT_TAIL(me->recycled_tasks, task, in thread_pool_func()
274 task = pop_task(me); in thread_pool_func()
281 if ((me->idle_cnt >= me->idle_max in thread_pool_func()
282 && !(me->scheduled_task_cnt && 0 >= me->idle_max) in thread_pool_func()
283 && !me->idle_wait) in thread_pool_func()
284 || me->terminated || elt->state != TH_RUN) { in thread_pool_func()
285 --me->thd_cnt; in thread_pool_func()
286 if ((TH_PROBATION == elt->state) && me->idle_wait) in thread_pool_func()
287 ++me->thd_timed_out; in thread_pool_func()
288 APR_RING_INSERT_TAIL(me->recycled_thds, elt, in thread_pool_func()
290 apr_thread_mutex_unlock(me->lock); in thread_pool_func()
297 ++me->idle_cnt; in thread_pool_func()
298 APR_RING_INSERT_TAIL(me->idle_thds, elt, apr_thread_list_elt, link); in thread_pool_func()
305 if (me->scheduled_task_cnt) in thread_pool_func()
306 wait = waiting_time(me); in thread_pool_func()
307 else if (me->idle_cnt > me->idle_max) { in thread_pool_func()
308 wait = me->idle_wait; in thread_pool_func()
315 apr_thread_cond_timedwait(me->cond, me->lock, wait); in thread_pool_func()
318 apr_thread_cond_wait(me->cond, me->lock); in thread_pool_func()
323 --me->thd_cnt; in thread_pool_func()
324 apr_thread_mutex_unlock(me->lock); in thread_pool_func()
329 static apr_status_t thread_pool_cleanup(void *me) in thread_pool_cleanup() argument
331 apr_thread_pool_t *_myself = me; in thread_pool_cleanup()
343 APU_DECLARE(apr_status_t) apr_thread_pool_create(apr_thread_pool_t ** me, in apr_thread_pool_create() argument
352 *me = NULL; in apr_thread_pool_create()
387 *me = tp; in apr_thread_pool_create()
393 APU_DECLARE(apr_status_t) apr_thread_pool_destroy(apr_thread_pool_t * me) in apr_thread_pool_destroy() argument
395 apr_pool_destroy(me->pool); in apr_thread_pool_destroy()
402 static apr_thread_pool_task_t *task_new(apr_thread_pool_t * me, in task_new() argument
409 if (APR_RING_EMPTY(me->recycled_tasks, apr_thread_pool_task, link)) { in task_new()
410 t = apr_pcalloc(me->pool, sizeof(*t)); in task_new()
416 t = APR_RING_FIRST(me->recycled_tasks); in task_new()
440 static apr_thread_pool_task_t *add_if_empty(apr_thread_pool_t * me, in add_if_empty() argument
448 if (me->task_idx[seg]) { in add_if_empty()
449 assert(APR_RING_SENTINEL(me->tasks, apr_thread_pool_task, link) != in add_if_empty()
450 me->task_idx[seg]); in add_if_empty()
451 t_next = me->task_idx[seg]; in add_if_empty()
454 if (APR_RING_SENTINEL(me->tasks, apr_thread_pool_task, link) == in add_if_empty()
463 if (me->task_idx[next]) { in add_if_empty()
464 APR_RING_INSERT_BEFORE(me->task_idx[next], t, link); in add_if_empty()
469 APR_RING_INSERT_TAIL(me->tasks, t, apr_thread_pool_task, link); in add_if_empty()
471 me->task_idx[seg] = t; in add_if_empty()
479 static apr_status_t schedule_task(apr_thread_pool_t *me, in schedule_task() argument
487 apr_thread_mutex_lock(me->lock); in schedule_task()
489 t = task_new(me, func, param, 0, owner, time); in schedule_task()
491 apr_thread_mutex_unlock(me->lock); in schedule_task()
494 t_loc = APR_RING_FIRST(me->scheduled_tasks); in schedule_task()
498 ++me->scheduled_task_cnt; in schedule_task()
505 APR_RING_SENTINEL(me->scheduled_tasks, apr_thread_pool_task, in schedule_task()
507 ++me->scheduled_task_cnt; in schedule_task()
508 APR_RING_INSERT_TAIL(me->scheduled_tasks, t, in schedule_task()
515 if (0 == me->thd_cnt) { in schedule_task()
516 rv = apr_thread_create(&thd, NULL, thread_pool_func, me, me->pool); in schedule_task()
518 ++me->thd_cnt; in schedule_task()
519 if (me->thd_cnt > me->thd_high) in schedule_task()
520 me->thd_high = me->thd_cnt; in schedule_task()
523 apr_thread_cond_signal(me->cond); in schedule_task()
524 apr_thread_mutex_unlock(me->lock); in schedule_task()
528 static apr_status_t add_task(apr_thread_pool_t *me, apr_thread_start_t func, in add_task() argument
537 apr_thread_mutex_lock(me->lock); in add_task()
539 t = task_new(me, func, param, priority, owner, 0); in add_task()
541 apr_thread_mutex_unlock(me->lock); in add_task()
545 t_loc = add_if_empty(me, t); in add_task()
551 while (APR_RING_SENTINEL(me->tasks, apr_thread_pool_task, link) != in add_task()
558 if (t_loc == me->task_idx[TASK_PRIORITY_SEG(t)]) { in add_task()
559 me->task_idx[TASK_PRIORITY_SEG(t)] = t; in add_task()
564 me->task_cnt++; in add_task()
565 if (me->task_cnt > me->tasks_high) in add_task()
566 me->tasks_high = me->task_cnt; in add_task()
567 if (0 == me->thd_cnt || (0 == me->idle_cnt && me->thd_cnt < me->thd_max && in add_task()
568 me->task_cnt > me->threshold)) { in add_task()
569 rv = apr_thread_create(&thd, NULL, thread_pool_func, me, me->pool); in add_task()
571 ++me->thd_cnt; in add_task()
572 if (me->thd_cnt > me->thd_high) in add_task()
573 me->thd_high = me->thd_cnt; in add_task()
577 apr_thread_cond_signal(me->cond); in add_task()
578 apr_thread_mutex_unlock(me->lock); in add_task()
583 APU_DECLARE(apr_status_t) apr_thread_pool_push(apr_thread_pool_t *me, in apr_thread_pool_push() argument
589 return add_task(me, func, param, priority, 1, owner); in apr_thread_pool_push()
592 APU_DECLARE(apr_status_t) apr_thread_pool_schedule(apr_thread_pool_t *me, in apr_thread_pool_schedule() argument
598 return schedule_task(me, func, param, owner, time); in apr_thread_pool_schedule()
601 APU_DECLARE(apr_status_t) apr_thread_pool_top(apr_thread_pool_t *me, in apr_thread_pool_top() argument
607 return add_task(me, func, param, priority, 0, owner); in apr_thread_pool_top()
610 static apr_status_t remove_scheduled_tasks(apr_thread_pool_t *me, in remove_scheduled_tasks() argument
616 t_loc = APR_RING_FIRST(me->scheduled_tasks); in remove_scheduled_tasks()
618 APR_RING_SENTINEL(me->scheduled_tasks, apr_thread_pool_task, in remove_scheduled_tasks()
623 --me->scheduled_task_cnt; in remove_scheduled_tasks()
631 static apr_status_t remove_tasks(apr_thread_pool_t *me, void *owner) in remove_tasks() argument
637 t_loc = APR_RING_FIRST(me->tasks); in remove_tasks()
638 while (t_loc != APR_RING_SENTINEL(me->tasks, apr_thread_pool_task, link)) { in remove_tasks()
641 --me->task_cnt; in remove_tasks()
643 if (t_loc == me->task_idx[seg]) { in remove_tasks()
644 me->task_idx[seg] = APR_RING_NEXT(t_loc, link); in remove_tasks()
645 if (me->task_idx[seg] == APR_RING_SENTINEL(me->tasks, in remove_tasks()
648 || TASK_PRIORITY_SEG(me->task_idx[seg]) != seg) { in remove_tasks()
649 me->task_idx[seg] = NULL; in remove_tasks()
659 static void wait_on_busy_threads(apr_thread_pool_t *me, void *owner) in wait_on_busy_threads() argument
665 apr_thread_mutex_lock(me->lock); in wait_on_busy_threads()
666 elt = APR_RING_FIRST(me->busy_thds); in wait_on_busy_threads()
667 while (elt != APR_RING_SENTINEL(me->busy_thds, apr_thread_list_elt, link)) { in wait_on_busy_threads()
683 apr_thread_mutex_unlock(me->lock); in wait_on_busy_threads()
685 apr_thread_mutex_lock(me->lock); in wait_on_busy_threads()
687 elt = APR_RING_FIRST(me->busy_thds); in wait_on_busy_threads()
689 apr_thread_mutex_unlock(me->lock); in wait_on_busy_threads()
693 APU_DECLARE(apr_status_t) apr_thread_pool_tasks_cancel(apr_thread_pool_t *me, in apr_thread_pool_tasks_cancel() argument
698 apr_thread_mutex_lock(me->lock); in apr_thread_pool_tasks_cancel()
699 if (me->task_cnt > 0) { in apr_thread_pool_tasks_cancel()
700 rv = remove_tasks(me, owner); in apr_thread_pool_tasks_cancel()
702 if (me->scheduled_task_cnt > 0) { in apr_thread_pool_tasks_cancel()
703 rv = remove_scheduled_tasks(me, owner); in apr_thread_pool_tasks_cancel()
705 apr_thread_mutex_unlock(me->lock); in apr_thread_pool_tasks_cancel()
706 wait_on_busy_threads(me, owner); in apr_thread_pool_tasks_cancel()
711 APU_DECLARE(apr_size_t) apr_thread_pool_tasks_count(apr_thread_pool_t *me) in apr_thread_pool_tasks_count() argument
713 return me->task_cnt; in apr_thread_pool_tasks_count()
717 apr_thread_pool_scheduled_tasks_count(apr_thread_pool_t *me) in apr_thread_pool_scheduled_tasks_count() argument
719 return me->scheduled_task_cnt; in apr_thread_pool_scheduled_tasks_count()
722 APU_DECLARE(apr_size_t) apr_thread_pool_threads_count(apr_thread_pool_t *me) in apr_thread_pool_threads_count() argument
724 return me->thd_cnt; in apr_thread_pool_threads_count()
727 APU_DECLARE(apr_size_t) apr_thread_pool_busy_count(apr_thread_pool_t *me) in apr_thread_pool_busy_count() argument
729 return me->thd_cnt - me->idle_cnt; in apr_thread_pool_busy_count()
732 APU_DECLARE(apr_size_t) apr_thread_pool_idle_count(apr_thread_pool_t *me) in apr_thread_pool_idle_count() argument
734 return me->idle_cnt; in apr_thread_pool_idle_count()
738 apr_thread_pool_tasks_run_count(apr_thread_pool_t * me) in apr_thread_pool_tasks_run_count() argument
740 return me->tasks_run; in apr_thread_pool_tasks_run_count()
744 apr_thread_pool_tasks_high_count(apr_thread_pool_t * me) in apr_thread_pool_tasks_high_count() argument
746 return me->tasks_high; in apr_thread_pool_tasks_high_count()
750 apr_thread_pool_threads_high_count(apr_thread_pool_t * me) in apr_thread_pool_threads_high_count() argument
752 return me->thd_high; in apr_thread_pool_threads_high_count()
756 apr_thread_pool_threads_idle_timeout_count(apr_thread_pool_t * me) in apr_thread_pool_threads_idle_timeout_count() argument
758 return me->thd_timed_out; in apr_thread_pool_threads_idle_timeout_count()
762 APU_DECLARE(apr_size_t) apr_thread_pool_idle_max_get(apr_thread_pool_t *me) in apr_thread_pool_idle_max_get() argument
764 return me->idle_max; in apr_thread_pool_idle_max_get()
768 apr_thread_pool_idle_wait_get(apr_thread_pool_t * me) in apr_thread_pool_idle_wait_get() argument
770 return me->idle_wait; in apr_thread_pool_idle_wait_get()
778 static struct apr_thread_list_elt *trim_threads(apr_thread_pool_t *me, in trim_threads() argument
785 apr_thread_mutex_lock(me->lock); in trim_threads()
787 thds = me->idle_thds; in trim_threads()
788 n = me->idle_cnt; in trim_threads()
791 thds = me->busy_thds; in trim_threads()
792 n = me->thd_cnt - me->idle_cnt; in trim_threads()
795 apr_thread_mutex_unlock(me->lock); in trim_threads()
808 me->idle_cnt = *cnt; in trim_threads()
821 apr_thread_mutex_unlock(me->lock); in trim_threads()
828 static apr_size_t trim_idle_threads(apr_thread_pool_t *me, apr_size_t cnt) in trim_idle_threads() argument
834 elt = trim_threads(me, &cnt, 1); in trim_idle_threads()
836 apr_thread_mutex_lock(me->lock); in trim_idle_threads()
837 apr_thread_cond_broadcast(me->cond); in trim_idle_threads()
838 apr_thread_mutex_unlock(me->lock); in trim_idle_threads()
848 apr_thread_mutex_lock(me->lock); in trim_idle_threads()
849 APR_RING_SPLICE_TAIL(me->recycled_thds, head, tail, in trim_idle_threads()
851 apr_thread_mutex_unlock(me->lock); in trim_idle_threads()
861 static apr_size_t trim_busy_threads(apr_thread_pool_t *me, apr_size_t cnt) in trim_busy_threads() argument
863 trim_threads(me, &cnt, 0); in trim_busy_threads()
867 APU_DECLARE(apr_size_t) apr_thread_pool_idle_max_set(apr_thread_pool_t *me, in apr_thread_pool_idle_max_set() argument
870 me->idle_max = cnt; in apr_thread_pool_idle_max_set()
871 cnt = trim_idle_threads(me, cnt); in apr_thread_pool_idle_max_set()
876 apr_thread_pool_idle_wait_set(apr_thread_pool_t * me, in apr_thread_pool_idle_wait_set() argument
881 oldtime = me->idle_wait; in apr_thread_pool_idle_wait_set()
882 me->idle_wait = timeout; in apr_thread_pool_idle_wait_set()
887 APU_DECLARE(apr_size_t) apr_thread_pool_thread_max_get(apr_thread_pool_t *me) in apr_thread_pool_thread_max_get() argument
889 return me->thd_max; in apr_thread_pool_thread_max_get()
896 APU_DECLARE(apr_size_t) apr_thread_pool_thread_max_set(apr_thread_pool_t *me, in apr_thread_pool_thread_max_set() argument
901 me->thd_max = cnt; in apr_thread_pool_thread_max_set()
902 if (0 == cnt || me->thd_cnt <= cnt) { in apr_thread_pool_thread_max_set()
906 n = me->thd_cnt - cnt; in apr_thread_pool_thread_max_set()
907 if (n >= me->idle_cnt) { in apr_thread_pool_thread_max_set()
908 trim_busy_threads(me, n - me->idle_cnt); in apr_thread_pool_thread_max_set()
909 trim_idle_threads(me, 0); in apr_thread_pool_thread_max_set()
912 trim_idle_threads(me, me->idle_cnt - n); in apr_thread_pool_thread_max_set()
917 APU_DECLARE(apr_size_t) apr_thread_pool_threshold_get(apr_thread_pool_t *me) in apr_thread_pool_threshold_get() argument
919 return me->threshold; in apr_thread_pool_threshold_get()
922 APU_DECLARE(apr_size_t) apr_thread_pool_threshold_set(apr_thread_pool_t *me, in apr_thread_pool_threshold_set() argument
927 ov = me->threshold; in apr_thread_pool_threshold_set()
928 me->threshold = val; in apr_thread_pool_threshold_set()