Add memtest support.
[syslinux-debian/hramrach.git] / core / include / mbox.h
blob6fec267cd8479ab1e0c8dc49b048bcd1f72d0016
1 /*
2 * mbox.h
4 * Simple thread mailbox interface
5 */
7 #ifndef _MBOX_H
8 #define _MBOX_H
10 #include "thread.h"
13 * If a mailbox is allocated statically (as a struct mailbox), this
14 * is the number of slots it gets.
16 #define MAILBOX_STATIC_SIZE 512
18 struct mailbox {
19 struct semaphore prod_sem; /* Producer semaphore (empty slots) */
20 struct semaphore cons_sem; /* Consumer semaphore (data slots) */
21 struct semaphore head_sem; /* Head pointer semaphore */
22 struct semaphore tail_sem; /* Tail pointer semaphore */
23 void **wrap; /* Where pointers wrap */
24 void **head; /* Head pointer */
25 void **tail; /* Tail pointer */
27 void *data[MAILBOX_STATIC_SIZE]; /* Data array */
30 /* The number of bytes for an mailbox of size s */
31 #define MBOX_BYTES(s) (sizeof(struct mailbox) + \
32 ((s)-MAILBOX_STATIC_SIZE)*sizeof(void *))
34 void mbox_init(struct mailbox *mbox, size_t size);
35 int mbox_post(struct mailbox *mbox, void *msg, mstime_t timeout);
36 mstime_t mbox_fetch(struct mailbox *mbox, void **msg, mstime_t timeout);
39 * This marks a mailbox object as unusable; it will remain unusable
40 * until sem_init() is called on it again. This DOES NOT clear the
41 * list of blocked processes on this mailbox!
43 * It is also possible to mark the mailbox invalid by zeroing its
44 * memory structure.
46 static inline void mbox_set_invalid(struct mailbox *mbox)
48 if (!!mbox)
49 sem_set_invalid(&mbox->prod_sem);
53 * Ask if a mailbox object has been initialized.
55 static inline bool mbox_is_valid(struct mailbox *mbox)
57 return ((!!mbox) && sem_is_valid(&mbox->prod_sem));
60 #endif /* _MBOX_H */