36 lines
930 B
C
36 lines
930 B
C
#ifndef MAILBOX_H
|
|
#define MAILBOX_H
|
|
|
|
#include <semaphore.h>
|
|
|
|
extern struct mailbox *mailboxes;
|
|
|
|
struct msg {
|
|
// index of thread that sent the message
|
|
// if iFrom is -1, then the message is considered invalid.
|
|
int iFrom;
|
|
// value of message
|
|
int value;
|
|
// number of operations (optional; used to send a message back to the main thread)
|
|
int cnt;
|
|
// total time (optional; used to send a message back to the main thread)
|
|
int tot;
|
|
};
|
|
|
|
struct mailbox {
|
|
// the current message in the mailbox
|
|
struct msg stored_message;
|
|
// represents whether or not a message can be sent
|
|
sem_t send_sem;
|
|
// represents whether or not a message can be receieved
|
|
sem_t recv_sem;
|
|
};
|
|
|
|
int init_mailboxes(int n);
|
|
void free_mailboxes();
|
|
// God I hate the caps, but this is the required definition.
|
|
int SendMsg(int dest, struct msg *message);
|
|
int RecvMsg(int mailbox_index, struct msg *message);
|
|
int NBSendMsg(int dest, struct msg *message);
|
|
|
|
#endif |