summaryrefslogtreecommitdiffhomepage
path: root/digital/zigbit/bitcloud/stack/Components/SystemEnvironment/include/queue.h
blob: 0a7f8094d447d4d9cbf9b281809e3a2243223ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**********************************************************************//**
  \file queue.h

  \brief

  \author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

  \internal
  History:
    21/05/07 D. Ovechkin - Created
**************************************************************************/
#ifndef _QUEUE_H
#define _QUEUE_H

#include <types.h>

/***************************************************************************
  Declare a queue and reset to the default state
  Every queue should be declared with this macros!
  Any queue element passed as parameter to functions should have as first
  field pointer for adding to a queue.

  Parameters:
    queue - the name of object.
  Returns:
    None
****************************************************************************/
#define DECLARE_QUEUE(queue) QueueDescriptor_t queue = {.head = NULL,}

// Type of queue element
typedef struct _QueueElement_t
{
  struct _QueueElement_t *next;
} QueueElement_t;

// Queue descriptor
typedef struct
{
  QueueElement_t *head;
} QueueDescriptor_t;

/***************************************************************************
  Reset a queue
  Parameters:
    queue - pointer to a queue descriptor
  Returns:
    None
****************************************************************************/
INLINE void resetQueue(QueueDescriptor_t *queue)
{
  queue->head = NULL;
}

/***************************************************************************
  Get a element from a queue. Element is got from the head
  Parameters:
    queue - pointer to a queue descriptor
  Returns:
    None
****************************************************************************/
INLINE void *getQueueElem(const QueueDescriptor_t *queue)
{
  return queue->head;
}

/***************************************************************************
  Get next element of queue after current element. The movement is made from
  head to tail. At the beginning of looking for elements the head element
  should be obtained.
  Parameters:
    currElement - current element
  Returns:
    NULL     - no next element
    NOT NULL - next element is got
****************************************************************************/
INLINE void* getNextQueueElem(const void *currElem)
{
  return currElem? ((const QueueElement_t*) currElem)->next: NULL;
}

bool isQueueElem(const QueueDescriptor_t *const queue, const void *const element);
void  putQueueElem(QueueDescriptor_t *queue, void *element);
void *deleteHeadQueueElem(QueueDescriptor_t *queue);
bool  deleteQueueElem(QueueDescriptor_t *queue, void *element);

#endif
//eof queue.h