design_pattern_for_c  V 1.00
dp_util.c
Go to the documentation of this file.
1 
5 #include "dp_util.h"
7 void dputil_lock(void *handle) {
8  if(!handle) {
9  return;
10  }
11  pthread_mutex_lock((pthread_mutex_t *)handle);
12 }
14 void dputil_unlock(void *handle) {
15  if(!handle) {
16  return;
17  }
18  pthread_mutex_unlock((pthread_mutex_t *)handle);
19 }
20 
22  /* add to tail */
23  data->prev = this->tail;
24  //slide tail
25  if(this->tail) {
26  this->tail->next = data;
27  }
28  this->tail = data;
29 
30  /* if head is null, set to head */
31  if(!this->head) {
32  this->head = data;
33  }
34 }
35 
37 
38  /*add to tail*/
39  if(!prev) {
40  dputil_list_push(this, data);
41  return;
42  }
43 
44  //there is a prev.
45  data->next = prev->next;
46  data->prev = prev;
47 
48  //only to care prev has next or not
49  if(prev->next) {
50  prev->next->prev = data;
51  } else {
52  //there is no next=> prev is tail
53  this->tail = data;
54  }
55 
56  prev->next = data;
57 }
58 
60  if(!data) {
61  return;
62  }
63 
64  /* update content */
65  if(this->head == data) {
66  this->head = data->next;
67  } else {
68  /* else case, account is not head. So there is a prev. */
69  data->prev->next = data->next;
70  }
71 
72  if(this->tail == data) {
73  this->tail = data->prev;
74  } else {
75  /* else case, account is not tail. So there is a next. */
76  data->next->prev = data->prev;
77  }
78 }
79 
81  DPUtilListData data = this->head;
82  dputil_list_pull(this, data);
83  return data;
84 }
85 
Utility headers
void dputil_unlock(void *handle)
unlock
Definition: dp_util.c:14
void * handle
Definition: event_thread.c:30
void dputil_list_insert(DPUtilList this, DPUtilListData prev, DPUtilListData data)
list insert to point
Definition: dp_util.c:36
void dputil_lock(void *handle)
lock
Definition: dp_util.c:7
void dputil_list_push(DPUtilList this, DPUtilListData data)
list push
Definition: dp_util.c:21
DPUtilListData prev
Definition: dp_list.h:17
DPUtilListData dputil_list_pop(DPUtilList this)
list pop
Definition: dp_util.c:80
DPUtilListData next
Definition: dp_list.h:16
void dputil_list_pull(DPUtilList this, DPUtilListData data)
list pull
Definition: dp_util.c:59