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.
18 #include "utility/sync_util.h"
19 #include "utility/fw_ref.h"
24 #define EXPORT_API __attribute__ ((visibility("default")))
27 #ifndef SYNC_AGENT_LOG
29 #define LOG_TAG "AF_REF"
32 EXPORT_API sync_agent_util_ref_object_s *sync_agent_create_referenced_object(void *data, sync_agent_free_cb data_free_func)
36 retvm_if(data == NULL, NULL, "data parameter is NULL !!!");
37 // retvm_if(data_free_func == NULL, NULL, "data_free_func parameter is 0 !!!");
39 sync_agent_util_ref_object_s *ref = (sync_agent_util_ref_object_s *) malloc(sizeof(sync_agent_util_ref_object_s));
46 ref->free_func = data_free_func;
56 EXPORT_API sync_agent_util_ref_object_s *sync_agent_get_referenced_object(sync_agent_util_ref_object_s * object)
60 retvm_if(object == NULL, NULL, "object parameter is NULL !!!");
62 g_atomic_int_inc(&(object->refcount));
69 EXPORT_API void *sync_agent_get_original_object(sync_agent_util_ref_object_s * object)
73 retvm_if(object == NULL, NULL, "object parameter is NULL !!!");
80 EXPORT_API bool sync_agent_compare_object(sync_agent_util_ref_object_s * object1, sync_agent_util_ref_object_s * object2)
84 retvm_if(object1 == NULL, false, "object1 parameter is NULL !!!");
85 retvm_if(object2 == NULL, false, "object2 parameter is NULL !!!");
87 if ((object1->data) == (object2->data)) {
96 EXPORT_API void sync_agent_unref_referenced_object(sync_agent_util_ref_object_s * ref)
100 retm_if(ref == NULL, "ref parameter is NULL !!!");
102 if (g_atomic_int_dec_and_test(&(ref->refcount))) {
103 if (ref->free_func != NULL)
104 ref->free_func(ref->data);