Module: xenomai-gch
Branch: for-forge
Commit: b5c54bfaa5356b8d1d3fad83d01440e521f641c5
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=b5c54bfaa5356b8d1d3fad83d01440e521f641c5

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Nov 10 11:43:17 2011 +0100

copperplate, lib: move internal services to dedicated header

---

 include/copperplate/Makefile.am                    |    1 -
 include/copperplate/Makefile.in                    |    1 -
 include/copperplate/clockobj.h                     |    1 -
 include/copperplate/init.h                         |   28 +--------
 include/copperplate/threadobj.h                    |   28 ++++++---
 include/copperplate/traceobj.h                     |    1 -
 lib/copperplate/Makefile.am                        |    3 +-
 lib/copperplate/Makefile.in                        |   29 +++++-----
 lib/copperplate/cluster.c                          |    2 +-
 lib/copperplate/debug.c                            |    2 +-
 lib/copperplate/heapobj-malloc.c                   |    2 +-
 lib/copperplate/heapobj-pshared.c                  |    2 +-
 lib/copperplate/heapobj-tlsf.c                     |    2 +-
 lib/copperplate/init.c                             |   62 ++------------------
 lib/copperplate/{panic.c => internal.c}            |   58 ++++++++++++++++--
 .../panic.h => lib/copperplate/internal.h          |   44 +++++++++++---
 lib/copperplate/notifier.c                         |    3 +-
 lib/copperplate/reference.c                        |    2 +-
 lib/copperplate/threadobj.c                        |   12 +++-
 lib/copperplate/traceobj.c                         |    2 +-
 lib/psos/pt.c                                      |    2 +-
 lib/psos/queue.c                                   |    2 +-
 lib/psos/rn.c                                      |    2 +-
 lib/psos/sem.c                                     |    2 +-
 lib/psos/task.c                                    |    2 +-
 lib/vxworks/memPartLib.c                           |    2 +-
 lib/vxworks/semLib.c                               |    2 +-
 lib/vxworks/taskLib.c                              |    2 +-
 lib/vxworks/tickLib.c                              |    2 +-
 29 files changed, 156 insertions(+), 147 deletions(-)

diff --git a/include/copperplate/Makefile.am b/include/copperplate/Makefile.am
index ede7aea..bb74c86 100644
--- a/include/copperplate/Makefile.am
+++ b/include/copperplate/Makefile.am
@@ -14,7 +14,6 @@ includesub_HEADERS =  \
        shared-list.h   \
        private-list.h  \
        notifier.h      \
-       panic.h         \
        reference.h     \
        registry.h      \
        syncobj.h       \
diff --git a/include/copperplate/Makefile.in b/include/copperplate/Makefile.in
index 2821db1..cbb444c 100644
--- a/include/copperplate/Makefile.in
+++ b/include/copperplate/Makefile.in
@@ -253,7 +253,6 @@ includesub_HEADERS = \
        shared-list.h   \
        private-list.h  \
        notifier.h      \
-       panic.h         \
        reference.h     \
        registry.h      \
        syncobj.h       \
diff --git a/include/copperplate/clockobj.h b/include/copperplate/clockobj.h
index aacf018..85f3796 100644
--- a/include/copperplate/clockobj.h
+++ b/include/copperplate/clockobj.h
@@ -23,7 +23,6 @@
 #include <time.h>
 #include <xeno_config.h>
 #include <copperplate/list.h>
-#include <copperplate/panic.h>
 #include <copperplate/debug.h>
 #include <copperplate/lock.h>
 
diff --git a/include/copperplate/init.h b/include/copperplate/init.h
index 808330d..c2699b8 100644
--- a/include/copperplate/init.h
+++ b/include/copperplate/init.h
@@ -19,27 +19,9 @@
 #ifndef _COPPERPLATE_INIT_H
 #define _COPPERPLATE_INIT_H
 
-#include <xeno_config.h>
-#include <sched.h>
-#include <time.h>
-#include <copperplate/list.h>
+#include <stdarg.h>
 #include <copperplate/core.h>
-
-struct coppernode {
-       pid_t id;
-       unsigned int mem_pool;
-       char *registry_mountpt;
-       const char *session_label;
-       cpu_set_t cpu_affinity;
-       /* No bitfield below, we have to take address of thoses. */
-       int no_mlock;
-       int no_registry;
-       int reset_session;
-};
-
-struct timespec __init_date;
-
-extern struct coppernode __this_node;
+#include <copperplate/list.h>
 
 struct copperskin {
        const char *name;
@@ -53,16 +35,14 @@ extern "C" {
 
 void copperplate_init(int argc, char *const argv[]);
 
-pid_t copperplate_get_tid(void);
-
-int copperplate_probe_node(unsigned int id);
-
 void copperplate_register_skin(struct copperskin *p);
 
 void panic(const char *fmt, ...);
 
 void warning(const char *fmt, ...);
 
+const char *symerror(int errnum);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 220467e..286df4d 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -22,7 +22,6 @@
 #include <time.h>
 #include <sched.h>
 #include <pthread.h>
-#include <copperplate/init.h>
 #include <copperplate/list.h>
 #include <copperplate/lock.h>
 #include <copperplate/clockobj.h>
@@ -222,6 +221,24 @@ void threadobj_spin(ticks_t ns);
 int threadobj_stat(struct threadobj *thobj,
                   struct threadobj_stat *stat);
 
+#ifdef CONFIG_XENO_PSHARED
+
+int __threadobj_local_p(struct threadobj *thobj);
+
+static inline int threadobj_local_p(struct threadobj *thobj)
+{
+       return __threadobj_local_p(thobj);
+}
+
+#else
+
+static inline int threadobj_local_p(struct threadobj *thobj)
+{
+       return 1;
+}
+
+#endif /* !CONFIG_XENO_PSHARED */
+
 void threadobj_pkg_init(void);
 
 #ifdef __cplusplus
@@ -320,15 +337,6 @@ static inline int threadobj_get_errno(struct threadobj 
*thobj)
        return *thobj->errno_pointer;
 }
 
-static inline int threadobj_local_p(struct threadobj *thobj)
-{
-#ifdef CONFIG_XENO_PSHARED
-       return thobj->cnode == __this_node.id;
-#else
-       return 1;
-#endif
-}
-
 #define threadobj_prepare_wait(T)                                      \
        ({                                                              \
                struct threadobj *__thobj = threadobj_current();        \
diff --git a/include/copperplate/traceobj.h b/include/copperplate/traceobj.h
index f61d2f9..71901b5 100644
--- a/include/copperplate/traceobj.h
+++ b/include/copperplate/traceobj.h
@@ -20,7 +20,6 @@
 #define _COPPERPLATE_TRACEOBJ_H
 
 #include <pthread.h>
-#include <copperplate/panic.h>
 
 struct threadobj;
 
diff --git a/lib/copperplate/Makefile.am b/lib/copperplate/Makefile.am
index d504a4f..a66ea79 100644
--- a/lib/copperplate/Makefile.am
+++ b/lib/copperplate/Makefile.am
@@ -8,7 +8,8 @@ libcopperplate_la_SOURCES =     \
        cluster.c       \
        hash.c          \
        init.c          \
-       panic.c         \
+       internal.c      \
+       internal.h      \
        syncobj.c       \
        semobj.c        \
        threadobj.c     \
diff --git a/lib/copperplate/Makefile.in b/lib/copperplate/Makefile.in
index 1228ba1..404b86f 100644
--- a/lib/copperplate/Makefile.in
+++ b/lib/copperplate/Makefile.in
@@ -96,9 +96,10 @@ am__installdirs = "$(DESTDIR)$(libdir)"
 LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES)
 libcopperplate_la_DEPENDENCIES = $(am__append_4) $(am__append_7)
 am__libcopperplate_la_SOURCES_DIST = clockobj.c cluster.c hash.c \
-       init.c panic.c syncobj.c semobj.c threadobj.c traceobj.c \
-       timerobj-cobalt.c timerobj-mercury.c notifier.c debug.c \
-       heapobj-pshared.c reference.c heapobj-tlsf.c heapobj-malloc.c
+       init.c internal.c internal.h syncobj.c semobj.c threadobj.c \
+       traceobj.c timerobj-cobalt.c timerobj-mercury.c notifier.c \
+       debug.c heapobj-pshared.c reference.c heapobj-tlsf.c \
+       heapobj-malloc.c
 @XENO_COBALT_TRUE@am__objects_1 =  \
 @XENO_COBALT_TRUE@     libcopperplate_la-timerobj-cobalt.lo
 @XENO_COBALT_FALSE@am__objects_2 =  \
@@ -112,7 +113,7 @@ am__libcopperplate_la_SOURCES_DIST = clockobj.c cluster.c 
hash.c \
 @XENO_TLSF_FALSE@am__objects_6 = libcopperplate_la-heapobj-malloc.lo
 am_libcopperplate_la_OBJECTS = libcopperplate_la-clockobj.lo \
        libcopperplate_la-cluster.lo libcopperplate_la-hash.lo \
-       libcopperplate_la-init.lo libcopperplate_la-panic.lo \
+       libcopperplate_la-init.lo libcopperplate_la-internal.lo \
        libcopperplate_la-syncobj.lo libcopperplate_la-semobj.lo \
        libcopperplate_la-threadobj.lo libcopperplate_la-traceobj.lo \
        $(am__objects_1) $(am__objects_2) $(am__objects_3) \
@@ -310,10 +311,10 @@ top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 lib_LTLIBRARIES = libcopperplate.la
 libcopperplate_la_LDFLAGS = @XENO_DLOPEN_CONSTRAINT@ -version-info 0:0:0 
-lpthread
-libcopperplate_la_SOURCES = clockobj.c cluster.c hash.c init.c panic.c \
-       syncobj.c semobj.c threadobj.c traceobj.c $(am__append_1) \
-       $(am__append_3) $(am__append_5) $(am__append_6) \
-       $(am__append_8) $(am__append_9)
+libcopperplate_la_SOURCES = clockobj.c cluster.c hash.c init.c \
+       internal.c internal.h syncobj.c semobj.c threadobj.c \
+       traceobj.c $(am__append_1) $(am__append_3) $(am__append_5) \
+       $(am__append_6) $(am__append_8) $(am__append_9)
 libcopperplate_la_CPPFLAGS = @XENO_USER_CFLAGS@ \
        -I$(top_srcdir)/include $(am__append_2)
 libcopperplate_la_LIBADD = $(am__append_4) $(am__append_7)
@@ -431,8 +432,8 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcopperplate_la-heapobj-pshared.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcopperplate_la-heapobj-tlsf.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcopperplate_la-init.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcopperplate_la-internal.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcopperplate_la-notifier.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcopperplate_la-panic.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcopperplate_la-reference.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcopperplate_la-semobj.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcopperplate_la-syncobj.Plo@am__quote@
@@ -492,12 +493,12 @@ libcopperplate_la-init.lo: init.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) 
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(libcopperplate_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o 
libcopperplate_la-init.lo `test -f 'init.c' || echo '$(srcdir)/'`init.c
 
-libcopperplate_la-panic.lo: panic.c
-@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) 
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(libcopperplate_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT 
libcopperplate_la-panic.lo -MD -MP -MF $(DEPDIR)/libcopperplate_la-panic.Tpo -c 
-o libcopperplate_la-panic.lo `test -f 'panic.c' || echo '$(srcdir)/'`panic.c
-@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libcopperplate_la-panic.Tpo 
$(DEPDIR)/libcopperplate_la-panic.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='panic.c' 
object='libcopperplate_la-panic.lo' libtool=yes @AMDEPBACKSLASH@
+libcopperplate_la-internal.lo: internal.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) 
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(libcopperplate_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT 
libcopperplate_la-internal.lo -MD -MP -MF 
$(DEPDIR)/libcopperplate_la-internal.Tpo -c -o libcopperplate_la-internal.lo 
`test -f 'internal.c' || echo '$(srcdir)/'`internal.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libcopperplate_la-internal.Tpo 
$(DEPDIR)/libcopperplate_la-internal.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='internal.c' 
object='libcopperplate_la-internal.lo' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) 
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(libcopperplate_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o 
libcopperplate_la-panic.lo `test -f 'panic.c' || echo '$(srcdir)/'`panic.c
+@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) 
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(libcopperplate_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o 
libcopperplate_la-internal.lo `test -f 'internal.c' || echo 
'$(srcdir)/'`internal.c
 
 libcopperplate_la-syncobj.lo: syncobj.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) 
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(libcopperplate_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT 
libcopperplate_la-syncobj.lo -MD -MP -MF 
$(DEPDIR)/libcopperplate_la-syncobj.Tpo -c -o libcopperplate_la-syncobj.lo 
`test -f 'syncobj.c' || echo '$(srcdir)/'`syncobj.c
diff --git a/lib/copperplate/cluster.c b/lib/copperplate/cluster.c
index ee29206..b8608b8 100644
--- a/lib/copperplate/cluster.c
+++ b/lib/copperplate/cluster.c
@@ -90,12 +90,12 @@
 
 #include <errno.h>
 #include <string.h>
-#include "copperplate/init.h"
 #include "copperplate/heapobj.h"
 #include "copperplate/cluster.h"
 #include "copperplate/syncobj.h"
 #include "copperplate/threadobj.h"
 #include "copperplate/debug.h"
+#include "internal.h"
 
 #ifdef CONFIG_XENO_PSHARED
 
diff --git a/lib/copperplate/debug.c b/lib/copperplate/debug.c
index eb80296..6bcd1a7 100644
--- a/lib/copperplate/debug.c
+++ b/lib/copperplate/debug.c
@@ -23,11 +23,11 @@
 #include <assert.h>
 #include <pthread.h>
 #include <errno.h>
-#include "copperplate/panic.h"
 #include "copperplate/lock.h"
 #include "copperplate/debug.h"
 #include "copperplate/threadobj.h"
 #include "copperplate/heapobj.h"
+#include "internal.h"
 
 static pthread_key_t btkey;
 
diff --git a/lib/copperplate/heapobj-malloc.c b/lib/copperplate/heapobj-malloc.c
index 13386d0..70a0a88 100644
--- a/lib/copperplate/heapobj-malloc.c
+++ b/lib/copperplate/heapobj-malloc.c
@@ -22,9 +22,9 @@
 #include <string.h>
 #include <malloc.h>
 #include "copperplate/wrappers.h"
-#include "copperplate/init.h"
 #include "copperplate/heapobj.h"
 #include "copperplate/debug.h"
+#include "internal.h"
 
 #define MALLOC_BLOCK_OVERHEAD  8
 
diff --git a/lib/copperplate/heapobj-pshared.c 
b/lib/copperplate/heapobj-pshared.c
index 102e68e..8feae81 100644
--- a/lib/copperplate/heapobj-pshared.c
+++ b/lib/copperplate/heapobj-pshared.c
@@ -34,12 +34,12 @@
 #include <signal.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include "copperplate/init.h"
 #include "copperplate/lock.h"
 #include "copperplate/list.h"
 #include "copperplate/hash.h"
 #include "copperplate/heapobj.h"
 #include "copperplate/debug.h"
+#include "internal.h"
 
 #define HOBJ_PAGE_SHIFT        9       /* 2^9 => 512 bytes */
 #define HOBJ_PAGE_SIZE         (1U << HOBJ_PAGE_SHIFT)
diff --git a/lib/copperplate/heapobj-tlsf.c b/lib/copperplate/heapobj-tlsf.c
index 395d9d7..87d52d3 100644
--- a/lib/copperplate/heapobj-tlsf.c
+++ b/lib/copperplate/heapobj-tlsf.c
@@ -22,10 +22,10 @@
 #include <string.h>
 #include <memory.h>
 #include "copperplate/wrappers.h"
-#include "copperplate/init.h"
 #include "copperplate/heapobj.h"
 #include "copperplate/debug.h"
 #include "tlsf/tlsf.h"
+#include "internal.h"
 
 /* XXX: depends on the implementation included from tlsf/, YMMV. */
 #define TLSF_BLOCK_OVERHEAD  8
diff --git a/lib/copperplate/init.c b/lib/copperplate/init.c
index 26cce9f..e477d38 100644
--- a/lib/copperplate/init.c
+++ b/lib/copperplate/init.c
@@ -29,25 +29,16 @@
 #include <errno.h>
 #include <getopt.h>
 #include <sched.h>
-#include <linux/unistd.h>
-#include "copperplate/init.h"
 #include "copperplate/threadobj.h"
 #include "copperplate/heapobj.h"
 #include "copperplate/clockobj.h"
 #include "copperplate/registry.h"
 #include "copperplate/timerobj.h"
 #include "copperplate/debug.h"
+#include "internal.h"
 
 struct timespec __init_date;
 
-struct coppernode __this_node = {
-       .mem_pool = 128 * 1024, /* Default, 128 Kb. */
-       .session_label = "anon",
-       .no_mlock = 0,
-       .no_registry = 0,
-       .reset_session = 0,
-};
-
 static DEFINE_PRIVATE_LIST(skins);
 
 static int mkdir_mountpt = 1;
@@ -173,50 +164,6 @@ static int collect_cpu_affinity(const char *cpu_list)
        return 0;
 }
 
-pid_t copperplate_get_tid(void)
-{
-       return syscall(__NR_gettid);
-}
-
-#ifdef CONFIG_XENO_COBALT
-
-static inline unsigned long get_node_id(void)
-{
-       /*
-        * XXX: The nucleus maintains a hash table indexed on
-        * task_pid_vnr() values for mapped shadows. This is what
-        * __NR_gettid retrieves as well.
-        */
-       return copperplate_get_tid();
-}
-
-int copperplate_probe_node(unsigned int id)
-{
-       /*
-        * XXX: this call does NOT migrate to secondary mode therefore
-        * may be used in time-critical contexts. However, since the
-        * nucleus has to know about a probed thread to find out
-        * whether it exists, copperplate_init() must always be
-        * invoked from a real-time shadow, so that __this_node.id can
-        * be matched.
-        */
-       return pthread_probe_np((pid_t)id) == 0;
-}
-
-#else /* CONFIG_XENO_MERCURY */
-
-static inline unsigned long get_node_id(void)
-{
-       return getpid();
-}
-
-int copperplate_probe_node(unsigned int id)
-{
-       return kill((pid_t)id, 0) == 0;
-}
-
-#endif  /* CONFIG_XENO_MERCURY */
-
 void copperplate_init(int argc, char *const argv[])
 {
        struct copperskin *skin;
@@ -224,10 +171,11 @@ void copperplate_init(int argc, char *const argv[])
 
        __RT(clock_gettime(CLOCK_COPPERPLATE, &__init_date));
 
-       /* No ifs, no buts: we must be called over the main thread. */
-       assert(getpid() == copperplate_get_tid());
+       /* Our node id. is the tid of the main thread. */
+       __this_node.id = copperplate_get_tid();
 
-       __this_node.id = get_node_id();
+       /* No ifs, no buts: we must be called over the main thread. */
+       assert(getpid() == __this_node.id);
 
        /* Set a reasonable default value for the registry mount point. */
        ret = asprintf(&__this_node.registry_mountpt,
diff --git a/lib/copperplate/panic.c b/lib/copperplate/internal.c
similarity index 72%
rename from lib/copperplate/panic.c
rename to lib/copperplate/internal.c
index 626d716..4d4cf45 100644
--- a/lib/copperplate/panic.c
+++ b/lib/copperplate/internal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Philippe Gerum <r...@xenomai.org>.
+ * Copyright (C) 2011 Philippe Gerum <r...@xenomai.org>.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -16,19 +16,63 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
+#include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <signal.h>
 #include <errno.h>
-#include "copperplate/init.h"
-#include "copperplate/lock.h"
-#include "copperplate/debug.h"
-#include "copperplate/clockobj.h"
-#include "copperplate/threadobj.h"
-#include "copperplate/panic.h"
+#include <linux/unistd.h>
+#include <copperplate/clockobj.h>
+#include <copperplate/threadobj.h>
+#include "internal.h"
+
+struct coppernode __this_node = {
+       .mem_pool = 128 * 1024, /* Default, 128 Kb. */
+       .session_label = "anon",
+       .no_mlock = 0,
+       .no_registry = 0,
+       .reset_session = 0,
+};
 
 pthread_mutex_t __printlock;
 
+pid_t copperplate_get_tid(void)
+{
+       /*
+        * XXX: The nucleus maintains a hash table indexed on
+        * task_pid_vnr() values for mapped shadows. This is what
+        * __NR_gettid retrieves as well in Cobalt mode.
+        */
+       return syscall(__NR_gettid);
+}
+
+#ifdef CONFIG_XENO_COBALT
+
+int copperplate_probe_node(unsigned int id)
+{
+       /*
+        * XXX: this call does NOT migrate to secondary mode therefore
+        * may be used in time-critical contexts. However, since the
+        * nucleus has to know about a probed thread to find out
+        * whether it exists, copperplate_init() must always be
+        * invoked from a real-time shadow, so that __this_node.id can
+        * be matched.
+        */
+       return pthread_probe_np((pid_t)id) == 0;
+}
+
+#else /* CONFIG_XENO_MERCURY */
+
+int copperplate_probe_node(unsigned int id)
+{
+       return kill((pid_t)id, 0) == 0;
+}
+
+#endif  /* CONFIG_XENO_MERCURY */
+
 void __printout(struct threadobj *thobj,
                const char *header, const char *fmt, va_list ap)
 {
diff --git a/include/copperplate/panic.h b/lib/copperplate/internal.h
similarity index 64%
rename from include/copperplate/panic.h
rename to lib/copperplate/internal.h
index 380aac1..1954d5f 100644
--- a/include/copperplate/panic.h
+++ b/lib/copperplate/internal.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Philippe Gerum <r...@xenomai.org>.
+ * Copyright (C) 2011 Philippe Gerum <r...@xenomai.org>.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -16,11 +16,35 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
-#ifndef _COPPERPLATE_PANIC_H
-#define _COPPERPLATE_PANIC_H
+#ifndef _COPPERPLATE_INTERNAL_H
+#define _COPPERPLATE_INTERNAL_H
 
+#include <sys/types.h>
 #include <stdarg.h>
 #include <pthread.h>
+#include <sched.h>
+#include <xeno_config.h>
+#include <copperplate/list.h>
+
+struct coppernode {
+       pid_t id;
+       unsigned int mem_pool;
+       char *registry_mountpt;
+       const char *session_label;
+       cpu_set_t cpu_affinity;
+       /* No bitfield below, we have to take address of thoses. */
+       int no_mlock;
+       int no_registry;
+       int reset_session;
+};
+
+extern struct coppernode __this_node;
+
+extern struct timespec __init_date;
+
+extern const char *dashes;
+
+extern pthread_mutex_t __printlock;
 
 struct threadobj;
 struct error_frame;
@@ -29,24 +53,24 @@ struct error_frame;
 extern "C" {
 #endif
 
-void error_hook(struct error_frame *ef);
-
 void __printout(struct threadobj *thobj,
                const char *header,
                const char *fmt, va_list ap);
 
+void error_hook(struct error_frame *ef);
+
+const char *symerror(int errnum);
+
 void panic(const char *fmt, ...);
 
 void warning(const char *fmt, ...);
 
-const char *symerror(int errnum);
-
-extern const char *dashes;
+pid_t copperplate_get_tid(void);
 
-extern pthread_mutex_t __printlock;
+int copperplate_probe_node(unsigned int id);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* _COPPERPLATE_PANIC_H */
+#endif /* _COPPERPLATE_INTERNAL_H */
diff --git a/lib/copperplate/notifier.c b/lib/copperplate/notifier.c
index 41b644e..df95c2d 100644
--- a/lib/copperplate/notifier.c
+++ b/lib/copperplate/notifier.c
@@ -22,11 +22,10 @@
 #include <fcntl.h>
 #include <assert.h>
 #include <errno.h>
-#include "copperplate/init.h"
-#include "copperplate/panic.h"
 #include "copperplate/notifier.h"
 #include "copperplate/lock.h"
 #include "copperplate/debug.h"
+#include "internal.h"
 
 /* Private signal used for notification. */
 #define NOTIFYSIG      (SIGRTMIN + 8)
diff --git a/lib/copperplate/reference.c b/lib/copperplate/reference.c
index b9cc35c..2cb38b9 100644
--- a/lib/copperplate/reference.c
+++ b/lib/copperplate/reference.c
@@ -21,7 +21,7 @@
 #include <string.h>
 #include "copperplate/reference.h"
 #include "copperplate/hash.h"
-#include "copperplate/panic.h"
+#include "internal.h"
 
 static int nrefs[MAX_FNLIBS];
 
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index 8025786..6508812 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -29,8 +29,6 @@
 #include <assert.h>
 #include <limits.h>
 #include <sched.h>
-#include "copperplate/init.h"
-#include "copperplate/panic.h"
 #include "copperplate/lock.h"
 #include "copperplate/traceobj.h"
 #include "copperplate/threadobj.h"
@@ -38,6 +36,7 @@
 #include "copperplate/cluster.h"
 #include "copperplate/clockobj.h"
 #include "copperplate/debug.h"
+#include "internal.h"
 
 union copperplate_wait_union {
        struct syncluster_wait_struct syncluster_wait;
@@ -1007,6 +1006,15 @@ void threadobj_spin(ticks_t ns)
                cpu_relax();
 }
 
+#ifdef CONFIG_XENO_PSHARED
+
+int __threadobj_local_p(struct threadobj *thobj)
+{
+       return thobj->cnode == __this_node.id;
+}
+
+#endif /* CONFIG_XENO_PSHARED */
+
 #ifdef __XENO_DEBUG__
 
 int __check_cancel_type(const char *locktype)
diff --git a/lib/copperplate/traceobj.c b/lib/copperplate/traceobj.c
index 6e1187a..1d52bee 100644
--- a/lib/copperplate/traceobj.c
+++ b/lib/copperplate/traceobj.c
@@ -1,10 +1,10 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include "copperplate/init.h"
 #include "copperplate/lock.h"
 #include "copperplate/traceobj.h"
 #include "copperplate/threadobj.h"
 #include "copperplate/heapobj.h"
+#include "internal.h"
 
 struct tracemark {
        const char *file;
diff --git a/lib/psos/pt.c b/lib/psos/pt.c
index e16e4d0..c3d8c98 100644
--- a/lib/psos/pt.c
+++ b/lib/psos/pt.c
@@ -22,7 +22,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <memory.h>
-#include <copperplate/panic.h>
+#include <copperplate/init.h>
 #include <copperplate/cluster.h>
 #include <copperplate/lock.h>
 #include <psos/psos.h>
diff --git a/lib/psos/queue.c b/lib/psos/queue.c
index 8aefa1e..6ad22f4 100644
--- a/lib/psos/queue.c
+++ b/lib/psos/queue.c
@@ -25,7 +25,7 @@
 #include <copperplate/threadobj.h>
 #include <copperplate/heapobj.h>
 #include <copperplate/clockobj.h>
-#include <copperplate/panic.h>
+#include <copperplate/init.h>
 #include <copperplate/cluster.h>
 #include <psos/psos.h>
 #include "internal.h"
diff --git a/lib/psos/rn.c b/lib/psos/rn.c
index 02b5bd8..09c3962 100644
--- a/lib/psos/rn.c
+++ b/lib/psos/rn.c
@@ -22,7 +22,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <memory.h>
-#include <copperplate/panic.h>
+#include <copperplate/init.h>
 #include <copperplate/threadobj.h>
 #include <copperplate/clockobj.h>
 #include <psos/psos.h>
diff --git a/lib/psos/sem.c b/lib/psos/sem.c
index 27ecbb4..ab13672 100644
--- a/lib/psos/sem.c
+++ b/lib/psos/sem.c
@@ -22,7 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <copperplate/heapobj.h>
-#include <copperplate/panic.h>
+#include <copperplate/init.h>
 #include <copperplate/cluster.h>
 #include <copperplate/clockobj.h>
 #include "reference.h"
diff --git a/lib/psos/task.c b/lib/psos/task.c
index 48f4fa3..88b87be 100644
--- a/lib/psos/task.c
+++ b/lib/psos/task.c
@@ -26,7 +26,7 @@
 #include <assert.h>
 #include <sched.h>
 #include <limits.h>
-#include <copperplate/panic.h>
+#include <copperplate/init.h>
 #include <copperplate/heapobj.h>
 #include <copperplate/threadobj.h>
 #include <copperplate/syncobj.h>
diff --git a/lib/vxworks/memPartLib.c b/lib/vxworks/memPartLib.c
index 128e764..3d97094 100644
--- a/lib/vxworks/memPartLib.c
+++ b/lib/vxworks/memPartLib.c
@@ -21,7 +21,7 @@
 #include <stdlib.h>
 #include <copperplate/lock.h>
 #include <copperplate/heapobj.h>
-#include <copperplate/panic.h>
+#include <copperplate/init.h>
 #include <vxworks/errnoLib.h>
 #include <vxworks/memPartLib.h>
 #include "memPartLib.h"
diff --git a/lib/vxworks/semLib.c b/lib/vxworks/semLib.c
index ebdfc87..d1a8b07 100644
--- a/lib/vxworks/semLib.c
+++ b/lib/vxworks/semLib.c
@@ -21,7 +21,7 @@
 #include <stdlib.h>
 #include <limits.h>
 #include <copperplate/heapobj.h>
-#include <copperplate/panic.h>
+#include <copperplate/init.h>
 #include <vxworks/errnoLib.h>
 #include "reference.h"
 #include "taskLib.h"
diff --git a/lib/vxworks/taskLib.c b/lib/vxworks/taskLib.c
index e84ee81..f7ab858 100644
--- a/lib/vxworks/taskLib.c
+++ b/lib/vxworks/taskLib.c
@@ -29,7 +29,7 @@
 #include <limits.h>
 #include "taskLib.h"
 #include "tickLib.h"
-#include <copperplate/panic.h>
+#include <copperplate/init.h>
 #include <copperplate/heapobj.h>
 #include <copperplate/threadobj.h>
 #include <copperplate/syncobj.h>
diff --git a/lib/vxworks/tickLib.c b/lib/vxworks/tickLib.c
index b95e062..9fe5730 100644
--- a/lib/vxworks/tickLib.c
+++ b/lib/vxworks/tickLib.c
@@ -21,7 +21,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <copperplate/panic.h>
+#include <copperplate/init.h>
 #include <copperplate/lock.h>
 #include <vxworks/tickLib.h>
 #include "tickLib.h"


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to