anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | /* |
| 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 __THREAD_POOL_H |
| 20 | #define __THREAD_POOL_H |
| 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "C"{ |
| 24 | #endif |
| 25 | |
| 26 | struct thread_pool; |
| 27 | typedef void (* JobFunction) (void *); |
| 28 | |
| 29 | /* |
| 30 | * Creates new thread pool |
| 31 | * on success return pointer to thread_pool |
| 32 | * on failure return NULL |
| 33 | */ |
| 34 | extern struct thread_pool *thread_pool_new(int count); |
| 35 | |
| 36 | /* |
| 37 | * Stops all threads and |
| 38 | * destroy the thread pool |
| 39 | * on success return 0 |
| 40 | * on failure return -1 |
| 41 | */ |
| 42 | extern int thread_pool_destroy(struct thread_pool *pool); |
| 43 | |
| 44 | /* |
| 45 | * Queues the job to thread pool |
| 46 | * idle threads will pick the job |
| 47 | * on success it return 0 |
| 48 | * on failure returns -ve values |
| 49 | */ |
| 50 | extern int insert_job(struct thread_pool *pool, JobFunction function, |
| 51 | void *userdata); |
| 52 | |
| 53 | #ifdef __cplusplus |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | #endif |
| 58 | |