Clubcos  0.0.0
Clubcos - Clubc Operating System
 모두 데이타 구조 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 매크로 페이지들
linkedlist.h
이 파일의 문서화 페이지로 가기
1 // Copyright (c) 2014, 임경현 (dlarudgus20)
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
32 #ifndef LINKEDLIST_H_
33 #define LINKEDLIST_H_
34 
35 #include <stddef.h>
36 #include <stdint.h>
37 
42 typedef struct tagLinkedListNode
43 {
44  struct tagLinkedListNode * volatile pNext;
45  struct tagLinkedListNode * volatile pPrev;
47 
51 typedef struct tagLinkedList
52 {
54 
60  uint32_t size;
61 } LinkedList;
62 
67 static inline void ckLinkedListInit(LinkedList *pList)
68 {
69  // circular linked list
70  pList->dummy.pNext = &pList->dummy;
71  pList->dummy.pPrev = &pList->dummy;
72  pList->size = 0;
73 }
74 
80 static inline LinkedListNode *ckLinkedListHead(LinkedList *pList) { return pList->dummy.pNext; }
86 static inline LinkedListNode *ckLinkedListTail(LinkedList *pList) { return pList->dummy.pPrev; }
87 
107 
113 static inline void ckLinkedListPushBack(LinkedList *pList, LinkedListNode *pNode)
114 {
115  pList->size++;
116 
117  LinkedListNode *dummy = &pList->dummy;
118  LinkedListNode *tail = dummy->pPrev;
119 
120  pNode->pNext = dummy;
121  pNode->pPrev = tail;
122  dummy->pPrev = pNode;
123  tail->pNext = pNode;
124 }
125 
131 static inline LinkedListNode *ckLinkedListPopFront(LinkedList *pList)
132 {
133  LinkedListNode *dummy = &pList->dummy;
134  LinkedListNode *ptr = dummy->pNext;
135  LinkedListNode *next = ptr->pNext;
136 
137  if (ptr == dummy)
138  return NULL;
139 
140  dummy->pNext = next;
141  next->pPrev = dummy;
142 
143  pList->size--;
144  return ptr;
145 }
146 
152 static inline void ckLinkedListErase(LinkedList *pList, LinkedListNode *pNode)
153 {
154  LinkedListNode *prev = pNode->pPrev;
155  LinkedListNode *next = pNode->pNext;
156 
157  prev->pNext = next;
158  next->pPrev = prev;
159  pList->size--;
160 }
161 
162 #endif /* LINKEDLIST_H_ */
void ckLinkedListPushBack_lockfree(LinkedList *pList, LinkedListNode *pNode)
단일 소비자/생산자 환경에서 lock-free하게 요소를 LinkedList 맨 뒤에 삽입합니다.
Definition: linkedlist.c:34
이중 환형 연결 리스트의 한 노드를 나타내는 구조체입니다.
Definition: linkedlist.h:42
struct tagLinkedListNode *volatile pNext
Definition: linkedlist.h:44
uint32_t size
연결 리스트의 요소의 갯수입니다.
Definition: linkedlist.h:60
struct tagLinkedListNode LinkedListNode
이중 환형 연결 리스트의 한 노드를 나타내는 구조체입니다.
struct tagLinkedList LinkedList
이중 환형 연결 리스트 구조체입니다.
이중 환형 연결 리스트 구조체입니다.
Definition: linkedlist.h:51
LinkedListNode * ckLinkedListPopFront_lockfree(LinkedList *pList)
단일 소비자/생산자 환경에서 lock-free하게 LinkedList 의 맨 앞 요소를 빼옵니다.
Definition: linkedlist.c:55
struct tagLinkedListNode *volatile pPrev
Definition: linkedlist.h:45
LinkedListNode dummy
Definition: linkedlist.h:53