[Cbe-oss-dev] [PATCH 1/3] libspe2: (take2) Change representation of fd's attribute table

Kazunori Asayama asayama at sm.sony.co.jp
Mon Apr 16 17:57:44 EST 2007


Here is a patch to change representation of tables of file
descriptors' attributes. This patch replaces multiple arrays of
attributes with just one array of structures, in order to make it easy
to maintain, debug, and/or modify the code.

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
@@ -33,8 +33,24 @@
 #include "create.h"
 #include "spebase.h"
 
-static char *spe_fd_name[] = { (char *)"mbox",(char *)"mbox_stat",(char *)"ibox",(char *)"ibox_stat",(char *)"wbox",(char *)"wbox_stat",(char *)"signal1",(char *)"signal2",(char *)"mfc",(char *)"mss"};
-static int   spe_fd_mode[] = { 	        O_RDONLY,      O_RDONLY,           O_RDONLY,      O_RDONLY,           O_WRONLY,      O_RDONLY,           O_RDWR,           O_RDWR,           O_RDWR,       O_RDWR};
+struct fd_attr
+{
+	const char *name;
+	int mode;
+};
+
+static const struct fd_attr spe_fd_attr[NUM_MBOX_FDS] = {
+	[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_STAT]	= { .name = "ibox_stat", .mode = O_RDONLY, },
+	[FD_WBOX]	= { .name = "wbox",      .mode = O_WRONLY, },
+	[FD_WBOX_STAT]	= { .name = "wbox_stat", .mode = O_RDONLY, },
+	[FD_SIG1]	= { .name = "signal1",   .mode = O_RDWR, },
+	[FD_SIG2]	= { .name = "signal2",   .mode = O_RDWR, },
+	[FD_MFC]	= { .name = "mfc",       .mode = O_RDWR, },
+	[FD_MSS]	= { .name = "mss",       .mode = O_RDWR, },
+};
 
 void *mapfileat( int dir, const char* filename, int size)
 {   
@@ -85,7 +101,8 @@ int open_if_closed(struct spe_context *s
 		spe->base_private->spe_fds_refcount[(int)fdesc]++;
 	}
 	else {
-		spe->base_private->spe_fds_array[(int)fdesc] = openat(spe->base_private->fd_spe_dir, spe_fd_name[(int)fdesc], spe_fd_mode[(int)fdesc]);
+		spe->base_private->spe_fds_array[(int)fdesc] =
+			openat(spe->base_private->fd_spe_dir, spe_fd_attr[fdesc].name, spe_fd_attr[fdesc].mode);
 		if (spe->base_private->spe_fds_array[(int)fdesc] > 0)
 			spe->base_private->spe_fds_refcount[(int)fdesc]++;
 	}



More information about the cbe-oss-dev mailing list