PULSAR  1.0.0
Parallel Ultra Light Systolic Array Runtime
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
icl_deque.h File Reference
#include <limits.h>
#include <stdlib.h>
#include <pthread.h>
#include "icl_list.h"
Include dependency graph for icl_deque.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  icl_deque_s
 

Typedefs

typedef icl_list_t icl_node_t
 
typedef struct icl_deque_s icl_deque_t
 

Functions

icl_deque_ticl_deque_new ()
 deque constructor More...
 
int icl_deque_destroy (icl_deque_t *deque, void(*free_func)(void *))
 deque destructor More...
 
icl_node_ticl_deque_first (icl_deque_t *deque)
 Get the first node in the deque. More...
 
icl_node_ticl_deque_next (icl_deque_t *deque, icl_node_t *node)
 Get the next node in the deque. More...
 
icl_node_ticl_deque_append (icl_deque_t *deque, void *data)
 Insert the node at the end of the deque. More...
 
icl_node_ticl_deque_prepend (icl_deque_t *deque, void *data)
 Insert the node at the front of the deque. More...
 
int icl_deque_delete (icl_deque_t *deque, icl_node_t *node, void(*free_func)(void *))
 Delete the node from the deque. More...
 
int icl_deque_size (icl_deque_t *deque)
 Return the deque size. More...
 

Typedef Documentation

typedef struct icl_deque_s icl_deque_t

Definition at line 27 of file icl_deque.h.

Function Documentation

icl_node_t* icl_deque_append ( icl_deque_t deque,
void *  data 
)

Insert the node at the end of the deque.

Parameters
deque
data
Returns
the new node. NULL on error.

Definition at line 118 of file icl_deque.c.

References icl_list_append(), icl_deque_s::list, icl_deque_s::size, and icl_deque_s::spinlock.

119 {
120  if (deque == NULL || data == NULL)
121  return NULL;
122 
123  pthread_spin_lock(&deque->spinlock);
124  icl_node_t *node = icl_list_append(deque->list, data);
125  deque->size++;
126  pthread_spin_unlock(&deque->spinlock);
127 
128  return node;
129 }
icl_list_t * icl_list_append(icl_list_t *head, void *data)
Insert a node at the end of this list.
Definition: icl_list.c:326
icl_list_t * list
Definition: icl_deque.h:30
pthread_spinlock_t spinlock
Definition: icl_deque.h:29

Here is the call graph for this function:

Here is the caller graph for this function:

int icl_deque_delete ( icl_deque_t deque,
icl_node_t node,
void(*)(void *)  free_func 
)

Delete the node from the deque.

Parameters
deque
node
free_funcfunction that frees the node's data
Return values
0success
-1failure

Definition at line 164 of file icl_deque.c.

References icl_list_delete(), icl_deque_s::list, icl_deque_s::size, and icl_deque_s::spinlock.

165 {
166  if (deque == NULL || node == NULL)
167  return -1;
168 
169  pthread_spin_lock(&deque->spinlock);
170  if (icl_list_delete(deque->list, node, free_func) == 0) {
171  pthread_spin_unlock(&deque->spinlock);
172  deque->size--;
173  return 0;
174  }
175  else {
176  pthread_spin_unlock(&deque->spinlock);
177  return -1;
178  }
179 }
icl_list_t * list
Definition: icl_deque.h:30
int icl_list_delete(icl_list_t *head, icl_list_t *pos, void(*free_function)(void *))
Delete the specified node.
Definition: icl_list.c:83
pthread_spinlock_t spinlock
Definition: icl_deque.h:29

Here is the call graph for this function:

Here is the caller graph for this function:

int icl_deque_destroy ( icl_deque_t deque,
void(*)(void *)  free_func 
)

deque destructor

Parameters
deque
free_funcfunction that frees the node's data
Return values
0success
-1failure

Definition at line 53 of file icl_deque.c.

References icl_list_destroy(), icl_deque_s::list, and icl_deque_s::spinlock.

54 {
55  if (deque == NULL)
56  return -1;
57 
58  if (pthread_spin_destroy(&deque->spinlock) != 0)
59  return -1;
60 
61  if (icl_list_destroy(deque->list, free_func) != 0)
62  return -1;
63 
64  free(deque);
65  return 0;
66 }
int icl_list_destroy(icl_list_t *head, void(*free_function)(void *))
Frees the resources associated with this linked list.
Definition: icl_list.c:173
icl_list_t * list
Definition: icl_deque.h:30
pthread_spinlock_t spinlock
Definition: icl_deque.h:29

Here is the call graph for this function:

Here is the caller graph for this function:

icl_node_t* icl_deque_first ( icl_deque_t deque)

Get the first node in the deque.

Parameters
deque
Returns
the node at the front of the deque. NULL if empty or error.

Definition at line 76 of file icl_deque.c.

References icl_list_first(), icl_deque_s::list, and icl_deque_s::spinlock.

77 {
78  if (deque == NULL)
79  return NULL;
80 
81  pthread_spin_lock(&deque->spinlock);
82  icl_node_t *node = icl_list_first(deque->list);
83  pthread_spin_unlock(&deque->spinlock);
84 
85  return node;
86 }
icl_list_t * icl_list_first(icl_list_t *head)
Get the first item in this linked list.
Definition: icl_list.c:221
icl_list_t * list
Definition: icl_deque.h:30
pthread_spinlock_t spinlock
Definition: icl_deque.h:29

Here is the call graph for this function:

Here is the caller graph for this function:

icl_deque_t* icl_deque_new ( )

deque constructor

Returns
new deque. NULL on error.

Definition at line 23 of file icl_deque.c.

References icl_list_new(), icl_deque_s::list, icl_deque_s::size, and icl_deque_s::spinlock.

24 {
25  icl_deque_t *deque = (icl_deque_t*)malloc(sizeof(icl_deque_t));
26  if (deque == NULL)
27  return NULL;
28 
29  deque->list = icl_list_new();
30  if (deque->list == NULL) {
31  free(deque);
32  return NULL;
33  }
34  if (pthread_spin_init(&deque->spinlock, PTHREAD_PROCESS_PRIVATE) != 0) {
35  free(deque->list);
36  free(deque);
37  return NULL;
38  }
39  deque->size = 0;
40  return deque;
41 }
icl_list_t * icl_list_new()
Create new linked list.
Definition: icl_list.c:23
icl_list_t * list
Definition: icl_deque.h:30
pthread_spinlock_t spinlock
Definition: icl_deque.h:29

Here is the call graph for this function:

Here is the caller graph for this function:

icl_node_t* icl_deque_next ( icl_deque_t deque,
icl_node_t node 
)

Get the next node in the deque.

Parameters
deque
node
Returns
next node. NULL if empty or error.

Definition at line 97 of file icl_deque.c.

References icl_list_next(), icl_deque_s::list, and icl_deque_s::spinlock.

98 {
99  if (deque == NULL)
100  return NULL;
101 
102  pthread_spin_lock(&deque->spinlock);
103  icl_node_t *next = icl_list_next(deque->list, node);
104  pthread_spin_unlock(&deque->spinlock);
105 
106  return next;
107 }
icl_list_t * list
Definition: icl_deque.h:30
pthread_spinlock_t spinlock
Definition: icl_deque.h:29
icl_list_t * icl_list_next(icl_list_t *head, icl_list_t *pos)
Get the node following the specified node.
Definition: icl_list.c:254

Here is the call graph for this function:

icl_node_t* icl_deque_prepend ( icl_deque_t deque,
void *  data 
)

Insert the node at the front of the deque.

Parameters
deque
data
Returns
the new node. NULL on error.

Definition at line 140 of file icl_deque.c.

References icl_list_prepend(), icl_deque_s::list, icl_deque_s::size, and icl_deque_s::spinlock.

141 {
142  if (deque == NULL || data == NULL)
143  return NULL;
144 
145  pthread_spin_lock(&deque->spinlock);
146  icl_node_t *node = icl_list_prepend(deque->list, data);
147  deque->size++;
148  pthread_spin_unlock(&deque->spinlock);
149 
150  return node;
151 }
icl_list_t * icl_list_prepend(icl_list_t *head, void *data)
Insert a node at the beginning of this list.
Definition: icl_list.c:312
icl_list_t * list
Definition: icl_deque.h:30
pthread_spinlock_t spinlock
Definition: icl_deque.h:29

Here is the call graph for this function:

int icl_deque_size ( icl_deque_t deque)

Return the deque size.

Parameters
deque
Returns
size of the deque. -1 on error.

Definition at line 189 of file icl_deque.c.

References icl_deque_s::size, and icl_deque_s::spinlock.

190 {
191  if (deque == NULL)
192  return -1;
193 
194  pthread_spin_lock(&deque->spinlock);
195  int size = deque->size;
196  pthread_spin_unlock(&deque->spinlock);
197  return size;
198 }
pthread_spinlock_t spinlock
Definition: icl_deque.h:29

Here is the caller graph for this function: