cs-3013-assignment-3/mailbox.h

36 lines
930 B
C
Raw Permalink Normal View History

2019-09-21 22:59:00 +00:00
#ifndef MAILBOX_H
#define MAILBOX_H
2019-09-21 23:31:21 +00:00
#include <semaphore.h>
2019-09-22 18:34:10 +00:00
extern struct mailbox *mailboxes;
2019-09-21 22:59:00 +00:00
struct msg {
// index of thread that sent the message
2019-09-21 23:31:21 +00:00
// if iFrom is -1, then the message is considered invalid.
2019-09-21 22:59:00 +00:00
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;
};
2019-09-21 23:31:21 +00:00
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;
};
2019-09-22 18:34:10 +00:00
int init_mailboxes(int n);
void free_mailboxes();
2019-09-22 18:48:11 +00:00
// God I hate the caps, but this is the required definition.
int SendMsg(int dest, struct msg *message);
2019-09-22 19:05:12 +00:00
int RecvMsg(int mailbox_index, struct msg *message);
2019-09-24 07:07:21 +00:00
int NBSendMsg(int dest, struct msg *message);
2019-09-22 18:34:10 +00:00
2019-09-21 22:59:00 +00:00
#endif