3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include "utility/fw_async_queue.h"
20 #include "utility/fw_async_queue_internal.h"
21 #include "utility/sync_util.h"
24 #define EXPORT_API __attribute__ ((visibility("default")))
27 #ifndef SYNC_AGENT_LOG
29 #define LOG_TAG "AF_UTIL_FW_AYNC_QUEUE"
32 EXPORT_API sync_agent_util_async_queue_s *sync_agent_alloc_async_queue()
36 #if !GLIB_CHECK_VERSION (2, 32, 0)
37 if (!g_thread_supported()) {
42 sync_agent_util_async_queue_s *queue = (sync_agent_util_async_queue_s *) calloc(1, sizeof(sync_agent_util_async_queue_s));
47 queue->pQueue = g_async_queue_new();
48 if (queue->pQueue == NULL) {
57 util_destroy_async_queue(queue);
61 void util_destroy_async_queue(sync_agent_util_async_queue_s * queue)
65 retm_if(queue == NULL, "queue parameter is NULL !!");
68 if (queue->pQueue != NULL) {
69 g_async_queue_unref(queue->pQueue);
78 void util_lock_async_queue(sync_agent_util_async_queue_s * queue)
82 retm_if(queue == NULL, "queue parameter is NULL !!");
84 if (queue != NULL && queue->pQueue != NULL) {
85 g_async_queue_lock(queue->pQueue);
87 _DEBUG_INFO("Invalid fw_async_queue\n");
93 void util_unlock_async_queue(sync_agent_util_async_queue_s * queue)
97 retm_if(queue == NULL, "queue parameter is NULL !!");
99 if (queue != NULL && queue->pQueue != NULL) {
100 g_async_queue_unlock(queue->pQueue);
102 _DEBUG_INFO("Invalid fw_async_queue\n");
108 EXPORT_API void *sync_agent_receive_msg_async_queue(sync_agent_util_async_queue_s * queue)
112 retvm_if(queue == NULL, NULL, "queue parameter is NULL !!");
116 return g_async_queue_pop(queue->pQueue);
119 EXPORT_API void sync_agent_send_msg_async_queue(sync_agent_util_async_queue_s * queue, void *msg)
123 retm_if(queue == NULL, "queue parameter is NULL !!");
125 g_async_queue_push(queue->pQueue, msg);
130 void util_send_msg_async_queue_with_compare_priority(sync_agent_util_async_queue_s * queue, void *msg, sync_agent_compare_priority_cb cpf, void *user_data)
134 retm_if(queue == NULL, "queue parameter is NULL !!");
137 g_async_queue_push(queue->pQueue, msg);
139 g_async_queue_push_sorted(queue->pQueue, msg, cpf, user_data);
145 EXPORT_API int sync_agent_async_queue_length(sync_agent_util_async_queue_s * queue)
149 retvm_if(queue == NULL, -1, "queue parameter is NULL !!");
153 return g_async_queue_length(queue->pQueue);