1 /* ****************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
24 * This file provides APIs related to thread pool.
27 #ifndef __UTHREAD_POOL_H_
28 #define __UTHREAD_POOL_H_
37 #endif /* __cplusplus */
41 * @brief Callback type can be registered to thread pool.
43 typedef void (*u_thread_func)(void *);
46 * @struct u_thread_msg_t
47 * @brief Structure to maintain the data which needs to send to task function.
56 * @var u_thread_pool_t
57 * @brief Thread pool type.
59 typedef void *u_thread_pool_t;
62 * This function creates a newly allocated thread pool.
64 * @param num_of_threads The number of worker thread used in this pool.
65 * @param thread_pool_handle Handle to newly create thread pool.
66 * @return Error code, CA_STATUS_OK if success, else error number.
68 CAResult_t u_thread_pool_init(uint32_t num_of_threads, u_thread_pool_t *thread_pool_handle);
71 * This function adds a routine to be executed by the thread pool at some future time.
73 * @param thread_pool The thread pool structure.
74 * @param method The routine to be executed.
75 * @param data The data to be passed to the routine.
77 * @return CA_STATUS_OK on success.
78 * @return Error on failure.
80 CAResult_t u_thread_pool_add_task(u_thread_pool_t thread_pool, u_thread_func method,
84 * This function stops all the worker threads (stop & exit). And frees all the allocated memory.
85 * Function will return only after joining all threads executing the currently scheduled tasks.
87 * @param thread_pool The thread pool structure.
89 void u_thread_pool_free(u_thread_pool_t thread_pool);
93 #endif /* __cplusplus */
95 #endif /* __UTHREAD_POOL_H_ */