Tizen 2.1 base
[platform/core/system/sync-agent.git] / src / framework / utility / fw_list.c
1 /*
2  * sync-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #include "utility/sync_util.h"
19 #include "utility/fw_list.h"
20
21 #ifndef EXPORT_API
22 #define EXPORT_API __attribute__ ((visibility("default")))
23 #endif
24
25 #ifndef SYNC_AGENT_LOG
26 #undef LOG_TAG
27 #define LOG_TAG "AF_UTIL_LIST"
28 #endif
29
30 void util_list_add_node(util_list_node_s * new_node, util_list_node_s * head_ptr)
31 {
32         _EXTERN_FUNC_ENTER;
33
34         *(volatile util_list_node_s **)&new_node->next = head_ptr->next;
35         new_node->prev = head_ptr;
36         head_ptr->next->prev = new_node;
37         head_ptr->next = new_node;
38
39         _EXTERN_FUNC_EXIT;
40 }
41
42 void util_list_delete_node(util_list_node_s * target_node)
43 {
44         _EXTERN_FUNC_ENTER;
45
46         util_list_node_s *prev = target_node->prev;
47         util_list_node_s *next = target_node->next;
48
49         next->prev = prev;
50         *(volatile util_list_node_s **)&prev->next = next;
51
52         _EXTERN_FUNC_EXIT;
53 }
54
55 void util_list_move_node(util_list_node_s * list, util_list_node_s * head_ptr)
56 {
57         _EXTERN_FUNC_ENTER;
58
59         util_list_delete_node(list);
60         util_list_add_node(list, head_ptr);
61
62         _EXTERN_FUNC_EXIT;
63 }
64
65 int util_list_node_count(const util_list_node_s * head_ptr)
66 {
67         _EXTERN_FUNC_ENTER;
68
69         int volatile count = 0;
70
71         util_list_node_s *cursor_ptr = head_ptr->next;
72         while (cursor_ptr != head_ptr) {
73                 count++;
74                 cursor_ptr = cursor_ptr->next;
75         }
76
77         _EXTERN_FUNC_EXIT;
78
79         return count;
80 }
81
82 void util_list_init(util_list_node_s * node_ptr)
83 {
84         _EXTERN_FUNC_ENTER;
85
86         node_ptr->next = node_ptr;
87         node_ptr->prev = node_ptr;
88
89         _EXTERN_FUNC_EXIT;
90 }