aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-09-09 16:29:15 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-09-09 16:29:15 -0700
commit7c15367c10a7f086ef9523065299a982032f1a66 (patch)
tree5cf5678c870948e69ccb2ee3955d440aa2acaad9
parentfb1da6f2505664e3c5284f33f395755922ff5983 (diff)
downloadlwip-7c15367c10a7f086ef9523065299a982032f1a66.tar.gz
lwip-7c15367c10a7f086ef9523065299a982032f1a66.tar.xz
lwip-7c15367c10a7f086ef9523065299a982032f1a66.zip
core: thread: merge mbox_post() and mbox_trypost()
Merge mbox_post() and mbox_trypost() into a single function with a timeout parameter. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--core/include/mbox.h4
-rw-r--r--core/thread/mbox.c17
2 files changed, 7 insertions, 14 deletions
diff --git a/core/include/mbox.h b/core/include/mbox.h
index ac139ff5..0f38cb46 100644
--- a/core/include/mbox.h
+++ b/core/include/mbox.h
@@ -21,4 +21,8 @@ struct mailbox {
void *data[]; /* Data array */
};
+void mbox_init(struct mailbox *mbox, size_t size);
+int mbox_post(struct mailbox *mbox, void *msg, jiffies_t timeout);
+jiffies_t mbox_fetch(struct mailbox *mbox, void **msg, jiffies_t timeout);
+
#endif /* _MBOX_H */
diff --git a/core/thread/mbox.c b/core/thread/mbox.c
index 107b51bf..f880b47b 100644
--- a/core/thread/mbox.c
+++ b/core/thread/mbox.c
@@ -20,8 +20,10 @@ void mbox_init(struct mailbox *mbox, size_t size)
mbox->tail = &mbox->data[0];
};
-static void mbox_post_common(struct mailbox *mbox, void *msg)
+int mbox_post(struct mailbox *mbox, void *msg, jiffies_t timeout)
{
+ if (sem_down(&mbox->prod_sem, timeout) == (jiffies_t)-1)
+ return ENOMEM;
sem_down(&mbox->head_sem, 0);
*mbox->head = msg;
@@ -31,19 +33,6 @@ static void mbox_post_common(struct mailbox *mbox, void *msg)
sem_up(&mbox->head_sem);
sem_up(&mbox->cons_sem);
-}
-
-void mbox_post(struct mailbox *mbox, void *msg)
-{
- sem_down(&mbox->prod_sem, 0);
- mbox_post_common(mbox, msg);
-}
-
-int mbox_trypost(struct mailbox *mbox, void *msg)
-{
- if (sem_down(&mbox->prod_sem, -1) == (jiffies_t)-1)
- return ENOMEM;
- mbox_post_common(mbox, msg);
return 0;
}