blob: 9ebd3f3ac5cd7adf072499838b6544c059bb09c1 [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
3 * Copyright (c) 2017 Intel Corporation
4 * Copyright (c) 2019, Infosys Ltd.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef __TPOOL_QUEUE_H
20#define __TPOOL_QUEUE_H
21
22struct node {
23 void *data;
24 struct node *next;
25};
26
27struct Queue {
28 int length;
29 struct node *head;
30 struct node *tail;
31};
32
33struct thread_pool {
34 struct Queue *thread_queue; /* queue to store thread ids */
35 struct Queue *job_queue; /* for storing jobs */
36
37 pthread_mutex_t queue_mutex; /* protection to job_queue */
38 pthread_cond_t job_received; /* synchronisation with worker threads */
39
40 pthread_t dispatch_thread; /* signals threads if new work in job_queue*/
41
42 int idle_threads; /* count of idle threads */
43};
44
45struct Job {
46 JobFunction function;
47 void *arg;
48};
49
50struct Queue;
51
52typedef void (* QueueDataFreeFunc)(void *data);
53
54extern struct Queue *queue_new();
55extern void queue_destroy(struct Queue *queue, QueueDataFreeFunc function);
56
57extern int queue_push_tail(struct Queue *queue, void *data);
58extern void *queue_pop_head(struct Queue *queue);
59extern int queue_get_length(struct Queue *queue);
60
61#endif
62