aboutsummaryrefslogtreecommitdiff
path: root/src/gensvm_queue.c
blob: 1994a54f2f755eff6a520f7fe6941a25046e1877 (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
/**
 * @file gensvm_queue.c
 * @author Gertjan van den Burg
 * @date May, 2016
 * @brief Functions for initializing and freeing a GenQueue
 *
 */

#include "gensvm_queue.h"

/**
 * @brief Initialize a GenQueue structure
 *
 * @details
 * A GenQueue structure is initialized and the default value for the
 * parameters are set. A pointer to the initialized queue  is returned.
 *
 * @returns 	initialized GenQueue
 */
struct GenQueue *gensvm_init_queue()
{
	struct GenQueue *q = Malloc(struct GenQueue, 1);

	q->tasks = NULL;
	q->N = 0;
	q->i = 0;

	return q;
}

/**
 * @brief Free the GenQueue struct
 *
 * @details
 * Freeing the allocated memory of the GenQueue means freeing every GenTask
 * struct and then freeing the Queue.
 *
 * @param[in] 	q 	GenQueue to be freed
 *
 */
void gensvm_free_queue(struct GenQueue *q)
{
	long i;
	for (i=0; i<q->N; i++) {
		gensvm_free_task(q->tasks[i]);
	}
	free(q->tasks);
	free(q);
	q = NULL;
}

/**
 * @brief Get new GenTask from GenQueue
 *
 * @details
 * Return a pointer to the next GenTask in the GenQueue. If no GenTask 
 * instances are left, NULL is returned. The internal counter GenQueue::i is 
 * used for finding the next GenTask.
 *
 * @param[in] 	q 	GenQueue instance
 * @returns 		pointer to next GenTask
 *
 */
struct GenTask *get_next_task(struct GenQueue *q)
{
	long i = q->i;
	if (i < q->N) {
		q->i++;
		return q->tasks[i];
	}
	return NULL;
}