[syslinux:lwip] core: thread: merge mbox_post() and mbox_trypost()
syslinux-bot for H. Peter Anvin
hpa at zytor.com
Fri Apr 22 20:05:05 PDT 2011
Commit-ID: c565a5f27c2a4d341bf6f800230a282489d5c164
Gitweb: http://syslinux.zytor.com/commit/c565a5f27c2a4d341bf6f800230a282489d5c164
Author: H. Peter Anvin <hpa at zytor.com>
AuthorDate: Wed, 9 Sep 2009 16:29:15 -0700
Committer: Eric W. Biederman <ebiederm at xmission.com>
CommitDate: Fri, 8 Apr 2011 14:45:53 -0700
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 at zytor.com>
---
core/include/mbox.h | 4 ++++
core/thread/mbox.c | 17 +++--------------
2 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/core/include/mbox.h b/core/include/mbox.h
index ac139ff..9b927a0 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, mstime_t timeout);
+mstime_t mbox_fetch(struct mailbox *mbox, void **msg, mstime_t timeout);
+
#endif /* _MBOX_H */
diff --git a/core/thread/mbox.c b/core/thread/mbox.c
index bc0b010..c518eeb 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, mstime_t timeout)
{
+ if (sem_down(&mbox->prod_sem, timeout) == (mstime_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) == (mstime_t)-1)
- return ENOMEM;
- mbox_post_common(mbox, msg);
return 0;
}
More information about the Syslinux-commits
mailing list