summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_thread_pool.h
blob: 75899a06a3efab5b23e105facab7c64ccb902f59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) NGINX, Inc.
 */

#ifndef _NXT_UNIX_THREAD_POOL_H_INCLUDED_
#define _NXT_UNIX_THREAD_POOL_H_INCLUDED_


typedef void (*nxt_thread_pool_init_t)(void);


struct nxt_thread_pool_s {
    nxt_atomic_t             ready;
    nxt_atomic_t             waiting;
    nxt_atomic_t             threads;
    nxt_uint_t               max_threads;

    nxt_sem_t                sem;
    nxt_nsec_t               timeout;

    nxt_task_t               task;

    nxt_locked_work_queue_t  work_queue;

    nxt_thread_handle_t      main;

    nxt_event_engine_t       *engine;
    nxt_thread_pool_init_t   init;
    nxt_work_handler_t       exit;
};


NXT_EXPORT nxt_thread_pool_t *nxt_thread_pool_create(nxt_uint_t max_threads,
    nxt_nsec_t timeout, nxt_thread_pool_init_t init,
    nxt_event_engine_t *engine, nxt_work_handler_t exit);
NXT_EXPORT void nxt_thread_pool_destroy(nxt_thread_pool_t *tp);
NXT_EXPORT nxt_int_t nxt_thread_pool_post(nxt_thread_pool_t *tp,
    nxt_work_handler_t handler, nxt_task_t *task, void *obj, void *data);


#endif /* _NXT_UNIX_THREAD_POOL_H_INCLUDED_ */