-
Notifications
You must be signed in to change notification settings - Fork 0
/
messagequeues.h
55 lines (42 loc) · 1.72 KB
/
messagequeues.h
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
/*
* File: messagequeues.h
* Author: danni
*
* Created on May 24, 2010, 9:06 PM
*/
#ifndef _MESSAGEQUEUES_H
#define _MESSAGEQUEUES_H
#include "globaldefs.h"
#include "datatypes.h"
#include <semaphore.h>
#define WAIT_FOR_PRM(pid) (sem_wait(&PROCESSES_mutex[1][pid]))
#define DONE_WITH_PRM(pid) (sem_post(&PROCESSES_mutex[1][pid]))
int BufferSize;
sem_t** PROCESSES_mutex; // Controls access to critical section
sem_t* PROCESSES_empty; // counts number of empty buffer slots
sem_t* PROCESSES_full; // counts number of full buffer slots
sem_t PRM_mutex; // Controls access to critical section
sem_t PRM_empty; // counts number of empty buffer slots
sem_t PRM_full; // counts number of full buffer slots
//Queues declaration
Queue_t_p* ProcessQueues;
Queue_t_p MMUQueue;
Queue_t_p PRMQueue;
/*
* Responsible for initing the queues for all the threads - memory allocation and setting to null
*/
bool QUEUES_Init();
bool QUEUES_WriteToProcess(PID processID,QueueCommand_t_p command); //non blocking
bool QUEUES_WriteToMMU(QueueCommand_t_p command); //non blocking
bool QUEUES_WriteToPRM(QueueCommand_t_p command); //non blocking
QueueCommand_t_p QUEUES_ReadProcess(PID processID); //blocking if no messages
QueueCommand_t_p QUEUES_ReadMMU(); //blocking if no messages
QueueCommand_t_p QUEUES_ReadPRM(); //blocking if no messages
QueueItem_t_p QUEUES_GetLastItem(Queue_t_p queue);
void QUEUES_PrintCommand(QueueCommand_t_p command);
void QUEUES_DeInitPRM();
void QUEUES_DeInitProcess(PID processID);
void QUEUES_DeInitMMU();
void QUEUES_DeInit();
void QUEUES_FreeCommand(QueueCommand_t_p comm);
#endif /* _MESSAGEQUEUES_H */