-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.h
More file actions
47 lines (34 loc) · 1.33 KB
/
queue.h
File metadata and controls
47 lines (34 loc) · 1.33 KB
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
// Copyright (C) 2024 Aleksei Rogov <alekzzzr@gmail.com>. All rights reserved.
#include <stdint.h>
#ifndef _QUEUE_H
#define _QUEUE_H
#define QUEUE_SUCCESS 0
#define QUEUE_PARAM_ERROR -1
#define QUEUE_ALLOC_ERROR -2
#define QUEUE_SIZE_ERROR -3
#define QUEUE_IS_EMPTY -4
struct MT_QUEUE {
struct MT_QUEUE *next; // Pointer to next queue entry
struct MT_QUEUE *last; // Pointer to last queue entry
uint32_t object_size; // Entry size in bytes
uint32_t queue_length; // Queue length
};
// Create a 'queue' and add an 'object' to it if '*queue' is NULL, or add an 'object' to an existing queue otherwise
// Return QUEUE_SUCCESS if no errors
int mt_queue_push(void **queue, void *object, size_t object_size);
// Get an object from the beginning of the 'queue' and remove it
// Return QUEUE_SUCCESS if no errors
int mt_queue_pop(void **queue, void *object, size_t object_size);
// Destroy queue
// Return QUEUE_SUCCESS if no errors
int mt_qeue_destroy(void **queue);
// Access first element
// Return QUEUE_SUCCESS if no errors
int mt_queue_front(void **queue, void *object, size_t object_size);
// Access last element
// Return QUEUE_SUCCESS if no errors
int mt_queue_back(void **queue, void *object, size_t object_size);
// Get queue length
// Return QUEUE_SUCCESS if no errors
int mt_queue_length(void **queue);
#endif