Subject:
update client.c nano-X.h ecos_app.c from nano-X cvs for eCos
From:
"Lecordier, Guy" ####@####.####
Date:
3 Nov 2008 14:50:30 -0000
Message-Id: <427FC27C2ABCC042A7FB4E17D3F893B7FB168E@lauescmx01.ROPERIND.NET>
Hi all,
Modification done to compile client.c from nano-X cvs for ecos
nxErrorStrings[] was in a #ifndef __ECOS branch, so it was undefined for
the __ECOS compilation,I move it outside the #ifndef branch.
The definition of ecos_nanox_client_data_index is specific to eCos. I
move it in the specific file ecos_app.c, where it is initialized.
Add ACCESS_PER_THREAD_DATA() before evlist in GrGetNextEventTimeout()
Modification done in nano-x.h
ecos_nanox_client_data_index initialization is removed from
INIT_PER_THREAD_DATA() avoiding to reinit it each time a new thread
starts.
#if defined(__ECOS) && !defined(NONETWORK) to enable the data per thread
in client server mode and to disable them in the NONETWORK mode.
Modification done in ecos_app.c
ecos_nanox_client_data_index = cyg_thread_new_data_index();
To initialize ecos_nanox_client_data_index once.
[patch]
Index: src/ecos/ecos_app.c
===================================================================
RCS file: /usr/cvs/microwin/src/ecos/ecos_app.c,v
retrieving revision 1.2
diff -u -r1.2 ecos_app.c
--- src/ecos/ecos_app.c 21 Aug 2002 16:36:19 -0000 1.2
+++ src/ecos/ecos_app.c 3 Nov 2008 13:39:40 -0000
@@ -73,6 +73,12 @@
char stack[STACKSIZE];
};
+/*
+ * eCos uses a thread data pointer to store all statics in...
+ */
+int ecos_nanox_client_data_index = CYGNUM_KERNEL_THREADS_DATA_MAX;
+
+
struct nx_thread _threads[] = {
{ "System startup", startup_thread, 11 },
{ "Nano-X server", nanox_thread, 12 },
@@ -94,13 +100,14 @@
#define NUM(x) (sizeof(x)/sizeof(x[0]))
// Functions not provided in eCos by standard...
+/*
char *
strdup(char *string) {
char *newbit = malloc(strlen(string)+1);
strcpy(newbit,string);
return newbit;
}
-
+*/
int
gettimeofday(struct timeval *tv,
struct timezone *tz)
@@ -124,7 +131,6 @@
static void
startup_thread(CYG_ADDRESS data)
{
- cyg_ucount32 nanox_data_index;
int i;
struct nx_thread *nx;
@@ -164,15 +170,15 @@
// Allocate a free thread data slot
// Note: all MicroWindows/NanoX threads use this slot for
NanoX-private
// data. That's why there is only one call here.
- nanox_data_index = cyg_thread_new_data_index();
- printf("data index = %d\n", nanox_data_index);
+ ecos_nanox_client_data_index = cyg_thread_new_data_index();
+ printf("data index = %d\n", ecos_nanox_client_data_index);
printf("Creating system threads\n");
nx = &_threads[1];
for (i = 1; i < NUM(_threads); i++, nx++) {
cyg_thread_create(nx->prio,
nx->entry,
- (cyg_addrword_t) nanox_data_index,
+ (cyg_addrword_t) 0,
nx->name,
(void *)nx->stack, STACKSIZE,
&nx->t,
@@ -187,7 +193,7 @@
// Special case - run additional code, specific to this
environment
// only after the server has had a chance to startup
if (i == 2) {
- ecos_nx_init(nanox_data_index);
+ ecos_nx_init(ecos_nanox_client_data_index);
}
}
Index: src/nanox/client.c
===================================================================
RCS file: /usr/cvs/microwin/src/nanox/client.c,v
retrieving revision 1.52
diff -u -r1.52 client.c
--- src/nanox/client.c 7 Jan 2008 00:01:31 -0000 1.52
+++ src/nanox/client.c 3 Nov 2008 13:39:42 -0000
@@ -40,6 +40,7 @@
#define ADDR_FAM AF_NANO
#elif __ECOS
#include <netinet/in.h>
+#include <netdb.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <cyg/kernel/kapi.h>
@@ -91,13 +92,6 @@
static int regfdmax = -1; /* GrRegisterInput globals*/
static fd_set regfdset;
-/**
- * Human-readable error strings.
- */
-const char *nxErrorStrings[] = {
- GR_ERROR_STRINGS
-};
-
static EVENT_LIST * evlist;
/*
@@ -107,14 +101,15 @@
* will only be called when the client asks for events.
*/
static GR_FNCALLBACKEVENT ErrorFunc = GrDefaultErrorHandler;
+#endif
-#else /* __ECOS*/
-/*
- * eCos uses a thread data pointer to store all statics in...
+/**
+ * Human-readable error strings.
*/
-int ecos_nanox_client_data_index = CYGNUM_KERNEL_THREADS_DATA_MAX;
+const char *nxErrorStrings[] = {
+ GR_ERROR_STRINGS
+};
-#endif
static void QueueEvent(GR_EVENT *ep);
static void GetNextQueuedEvent(GR_EVENT *ep);
@@ -931,6 +926,7 @@
void
GrGetNextEventTimeout(GR_EVENT * ep, GR_TIMEOUT timeout)
{
+ ACCESS_PER_THREAD_DATA()
LOCK(&nxGlobalLock);
if (evlist) {
/*DPRINTF("nxclient %d: Returning queued
event\n",getpid());*/
Index: src/include/nano-X.h
===================================================================
RCS file: /usr/cvs/microwin/src/include/nano-X.h,v
retrieving revision 1.40
diff -u -r1.40 nano-X.h
--- src/include/nano-X.h 7 Jan 2008 00:01:31 -0000 1.40
+++ src/include/nano-X.h 3 Nov 2008 13:39:41 -0000
@@ -1009,9 +1009,11 @@
unsigned char *buffer; /* request buffer*/
} REQBUF;
-#ifdef __ECOS
+#if defined(__ECOS) && !defined(NONETWORK)
#include <sys/select.h>
#include <cyg/kernel/kapi.h>
+#include "lock.h" // needed by MWMUTEX
+
/*
* In a single process, multi-threaded environment, we need to keep
* all static data of shared code in a structure, with a pointer to
@@ -1038,9 +1040,8 @@
#define INIT_PER_THREAD_DATA()
\
{
\
ecos_nanox_client_data *dptr =
malloc(sizeof(ecos_nanox_client_data)); \
- ecos_nanox_client_data_index = data;
\
dptr->_nxSocket = -1;
\
- dptr->nxGlobalLock = 0;
+ dptr->_nxGlobalLock = 0;
\
dptr->_storedevent = 0;
\
dptr->_regfdmax = -1;
\
FD_ZERO(&dptr->_regfdset);
\
@@ -1062,7 +1063,9 @@
#define reqbuf (data->_reqbuf)
#define evlist (data->_evlist)
+
#else
+#define INIT_PER_THREAD_DATA()
#define ACCESS_PER_THREAD_DATA()
#endif
Any comments
Regards
Guy