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 contains common utility function for handling message ques.
27 #ifndef CA_QUEUEING_THREAD_H_
28 #define CA_QUEUEING_THREAD_H_
32 #include "cathreadpool.h"
41 /** Thread function to be invoked. **/
42 typedef void (*CAThreadTask)(void *threadData);
44 /** Data destroy function. **/
45 typedef void (*CADataDestroyFunction)(void *data, uint32_t size);
49 /** Thread pool of the thread started. **/
50 ca_thread_pool_t threadPool;
51 /** mutex for synchronization. **/
53 /** conditional mutex for synchronization. **/
55 /** Thread function to be invoked. **/
56 CAThreadTask threadTask;
57 /** Data destroy function. **/
58 CADataDestroyFunction destroy;
59 /** Variable to inform the thread to stop. **/
61 /** Que on which the thread is operating. **/
66 * Initializes the queuing thread.
67 * @param[in] thread thread data for each thread.
68 * @param[in] handle thread pool handle created.
69 * @param[in] task function to be called for each data.
70 * @param[in] destroy function to data destroy.
71 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
73 CAResult_t CAQueueingThreadInitialize(CAQueueingThread_t *thread, ca_thread_pool_t handle,
74 CAThreadTask task, CADataDestroyFunction destroy);
77 * Start the queuing thread.
78 * @param[in] thread thread data that needs to be started.
79 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
81 CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread);
84 * Add queuing thread data for new thread.
85 * @param[in] thread thread data for new thread control.
86 * @param[in] data data that needs to be given for each thread.
87 * @param[in] size length of the data.
88 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
90 CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data, uint32_t size);
93 * Stop the queuing thread.
94 * @param[in] thread thread data that needs to be started.
95 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
98 CAResult_t CAQueueingThreadStop(CAQueueingThread_t *thread);
101 * Terminate the queuing thread.
102 * @param[in] thread thread data for each thread.
103 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
106 CAResult_t CAQueueingThreadDestroy(CAQueueingThread_t *thread);
112 #endif /* CA_QUEUEING_THREAD_H_ */