1
#ifndef __tascel_SharedQueue_h__
2
#define __tascel_SharedQueue_h__
4
#include "TerminationDetector.h"
9
* A set of task queues shared among processes.
11
* Each process has a local queue with a maximum number of possible tasks.
12
* A process can steal tasks from any other process's queue and have
13
* tasks stolen from its own queue.
15
* This implementation forces the entire queue on a given proc to be locked
16
* during any modification by itself or by any other proc.
21
* The local queue state which other procs can modify.
24
int dirty; /**< whether a steal has occurred */
25
int head; /**< the head of the queue */
26
int tail; /**< the tail of the queue */
27
int size; /**< the number of tasks in the queue */
30
const int max_ntsks; /**< max number of tasks allowed in queue */
31
const int tsk_size; /**< size of a single task */
32
char **q; /**< addresses of queue data on all procs */
33
sq_state_t **sq_state; /**< addresses of queue state on all procs */
34
int *head; /**< pointer to this procs head state */
35
int *tail; /**< pointer to this procs tail state */
36
int *size; /**< pointer to this procs size state */
37
int *dirty; /**< pointer to this procs dirty state */
38
TerminationDetector td; /**< the TerminationDetector */
42
* Constructs the SharedQueue instance.
44
* @param[in] tsk_size size of a single task
45
* @param[in] max_ntsks max number of tasks in a queue
47
* @pre tsk_size must be the same value on all procs
48
* @pre max_ntsks must be the same value on all procs
50
SharedQueue(int tsk_size, int max_ntsks);
53
* Destroys the SharedQueue instance.
58
* Returns true if the local queue is empty.
60
* @return true if the local queue is empty.
65
* Retrieves a task from the local queue.
67
* @param[out] dscr the retrieved task
68
* @param[in] dlen size of the retrieved task
70
* @pre dscr is not NULL
71
* @pre dlen == tsk_size
73
* @return true if task was successfully retrieved
75
bool getTask(void *dscr, int dlen);
78
* Adds a task to the local queue.
80
* @param[in] dscr the task to add
81
* @param[in] dlen size of the added task
83
* @pre dscr is not NULL
84
* @pre dlen == tsk_size
86
* @return true if task was successfully added
88
void addTask(void *dscr, int dlen);
91
* Steals one or more tasks from the given proc.
93
* @param[in] proc to steal from
98
* Returns true if all of the tasks have been processed.
100
* @return true if all of the tasks have been processed.
102
bool hasTerminated();
105
* Runs the termination detector.
112
#endif /*__tascel_SharedQueue_h__*/