[Cbe-oss-dev] [PATCH 3/3] libspe2: (take2) Add behavior flag implementation to spe_out_intr_mbox_read
Kazunori Asayama
asayama at sm.sony.co.jp
Mon Apr 16 17:59:34 EST 2007
The patch below adds missing "behavior flag" implementation to
spe_out_intr_mbox_read API in libspe2.
Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
Index: libspe2-public/spebase/create.c
===================================================================
--- libspe2-public.orig/spebase/create.c
+++ libspe2-public/spebase/create.c
@@ -43,6 +43,7 @@ static const struct fd_attr spe_fd_attr[
[FD_MBOX] = { .name = "mbox", .mode = O_RDONLY, },
[FD_MBOX_STAT] = { .name = "mbox_stat", .mode = O_RDONLY, },
[FD_IBOX] = { .name = "ibox", .mode = O_RDONLY, },
+ [FD_IBOX_NB] = { .name = "ibox", .mode = O_RDONLY | O_NONBLOCK, },
[FD_IBOX_STAT] = { .name = "ibox_stat", .mode = O_RDONLY, },
[FD_WBOX] = { .name = "wbox", .mode = O_WRONLY, },
[FD_WBOX_NB] = { .name = "wbox", .mode = O_WRONLY | O_NONBLOCK, },
Index: libspe2-public/spebase/mbox.c
===================================================================
--- libspe2-public.orig/spebase/mbox.c
+++ libspe2-public/spebase/mbox.c
@@ -149,17 +149,50 @@ int _base_spe_out_intr_mbox_read(spe_con
int behavior_flag)
{
int rc;
+ int total;
if (mbox_data == NULL || count < 1){
errno = EINVAL;
return -1;
}
- rc = read(open_if_closed(spectx,FD_IBOX, 0), mbox_data, count*4);
- if (rc != -1)
- rc /= 4;
+ switch (behavior_flag) {
+ case SPE_MBOX_ALL_BLOCKING: // read all, even if blocking
+ total = rc = 0;
+ while (total < 4*count) {
+ rc = read(open_if_closed(spectx,FD_IBOX, 0),
+ (char *)mbox_data + total, 4*count - total);
+ if (rc == -1) {
+ break;
+ }
+ total += rc;
+ }
+ break;
+
+ case SPE_MBOX_ANY_BLOCKING: // read at least one, even if blocking
+ total = rc = read(open_if_closed(spectx,FD_IBOX, 0), mbox_data, 4*count);
+ break;
+
+ case SPE_MBOX_ANY_NONBLOCKING: // only reaad, if non blocking
+ rc = read(open_if_closed(spectx,FD_IBOX_NB, 0), mbox_data, 4*count);
+ if (rc == -1 && errno == EAGAIN) {
+ rc = 0;
+ errno = 0;
+ }
+ total = rc;
+ break;
- return rc;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (rc == -1) {
+ errno = EIO;
+ return -1;
+ }
+
+ return rc / 4;
}
int _base_spe_signal_write(spe_context_ptr_t spectx,
Index: libspe2-public/spebase/spebase.h
===================================================================
--- libspe2-public.orig/spebase/spebase.h
+++ libspe2-public/spebase/spebase.h
@@ -43,6 +43,7 @@ enum fd_name {
FD_MBOX,
FD_MBOX_STAT,
FD_IBOX,
+ FD_IBOX_NB,
FD_IBOX_STAT,
FD_WBOX,
FD_WBOX_NB,
More information about the cbe-oss-dev
mailing list