Module: xenomai-forge
Branch: next
Commit: 67c9b31d8cea51969632d58714730c04bd956bdc
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=67c9b31d8cea51969632d58714730c04bd956bdc

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Aug  3 11:52:30 2014 +0200

copperplate/threadobj: factor out SET_NAME operation for threads

---

 include/copperplate/threadobj.h |    2 ++
 lib/copperplate/internal.c      |   12 +++++++++++-
 lib/copperplate/internal.h      |    2 ++
 lib/copperplate/threadobj.c     |   24 ++----------------------
 lib/copperplate/timerobj.c      |   14 ++++----------
 5 files changed, 21 insertions(+), 33 deletions(-)

diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index e7b610d..73eb791 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -342,6 +342,8 @@ int threadobj_stat(struct threadobj *thobj,
 
 int threadobj_sleep(const struct timespec *ts);
 
+void threadobj_set_current_name(const char *name);
+
 #ifdef CONFIG_XENO_PSHARED
 
 static inline int threadobj_local_p(struct threadobj *thobj)
diff --git a/lib/copperplate/internal.c b/lib/copperplate/internal.c
index ce1902e..d5e7b67 100644
--- a/lib/copperplate/internal.c
+++ b/lib/copperplate/internal.c
@@ -15,8 +15,8 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
-
 #include <sys/types.h>
+#include <sys/prctl.h>
 #include <sys/syscall.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -92,6 +92,11 @@ int copperplate_kill_tid(pid_t tid, int sig)
        return __RT(kill(tid, sig)) ? -errno : 0;
 }
 
+void copperplate_set_current_name(const char *name)
+{
+       __RT(pthread_setname_np(pthread_self(), name));
+}
+
 #else /* CONFIG_XENO_MERCURY */
 
 int copperplate_kill_tid(pid_t tid, int sig)
@@ -99,6 +104,11 @@ int copperplate_kill_tid(pid_t tid, int sig)
        return syscall(__NR_tkill, tid, sig) ? -errno : 0;
 }
 
+void copperplate_set_current_name(const char *name)
+{
+       prctl(PR_SET_NAME, (unsigned long)name, 0, 0, 0);
+}
+
 int copperplate_create_thread(struct corethread_attributes *cta,
                              pthread_t *ptid_r)
 {
diff --git a/lib/copperplate/internal.h b/lib/copperplate/internal.h
index b4a49e2..9ac9848 100644
--- a/lib/copperplate/internal.h
+++ b/lib/copperplate/internal.h
@@ -94,6 +94,8 @@ static inline void copperplate_set_silent(void)
 extern "C" {
 #endif
 
+void copperplate_set_current_name(const char *name);
+
 int copperplate_kill_tid(pid_t tid, int sig);
 
 int copperplate_create_thread(struct corethread_attributes *cta,
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index e43a8e1..870e81e 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -17,8 +17,6 @@
  *
  * Thread object abstraction.
  */
-
-#include <sys/prctl.h>
 #include <signal.h>
 #include <memory.h>
 #include <errno.h>
@@ -106,26 +104,10 @@ struct remote_request {
        } u;
 };
 
-#ifdef CONFIG_XENO_COBALT
-
-static inline void agent_init_corespec(const char *name)
-{
-       __RT(pthread_setname_np(pthread_self(), name));
-}
-
-#else /* CONFIG_XENO_MERCURY */
-
-static inline void agent_init_corespec(const char *name)
-{
-       prctl(PR_SET_NAME, (unsigned long)name, 0, 0, 0);
-}
-
-#endif /* CONFIG_XENO_MERCURY */
-
 static int agent_prologue(void *arg)
 {
        agent_pid = get_thread_pid();
-       agent_init_corespec("remote-agent");
+       copperplate_set_current_name("remote-agent");
        threadobj_set_current(THREADOBJ_IRQCONTEXT);
 
        return 0;
@@ -257,7 +239,6 @@ static inline void threadobj_uninit_corespec(struct 
threadobj *thobj)
 
 static inline int threadobj_setup_corespec(struct threadobj *thobj)
 {
-       __RT(pthread_setname_np(pthread_self(), thobj->name));
        thobj->core.handle = cobalt_get_current();
        thobj->core.u_window = cobalt_get_current_window();
 
@@ -593,8 +574,6 @@ static inline int threadobj_setup_corespec(struct threadobj 
*thobj)
        sigset_t set;
        int ret;
 
-       prctl(PR_SET_NAME, (unsigned long)thobj->name, 0, 0, 0);
-
        /*
         * Do the per-thread setup for supporting the suspend/resume
         * actions over Mercury. We have two basic requirements for
@@ -1188,6 +1167,7 @@ int threadobj_prologue(struct threadobj *thobj, const 
char *name)
        thobj->errno_pointer = &errno;
        threadobj_set_agent(thobj);
        backtrace_init_context(&thobj->btd, name);
+       copperplate_set_current_name(thobj->name);
        ret = threadobj_setup_corespec(thobj);
        if (ret) {
                warning("prologue failed for thread %s, %s",
diff --git a/lib/copperplate/timerobj.c b/lib/copperplate/timerobj.c
index fffd1cb..fbe5b0a 100644
--- a/lib/copperplate/timerobj.c
+++ b/lib/copperplate/timerobj.c
@@ -45,24 +45,17 @@ static DEFINE_PRIVATE_LIST(svtimers);
 
 #ifdef CONFIG_XENO_COBALT
 
-static inline void timersv_init_corespec(const char *name)
-{
-       __RT(pthread_setname_np(pthread_self(), name));
-}
+static inline void timersv_init_corespec(void) { }
 
 #else /* CONFIG_XENO_MERCURY */
 
-#include <sys/prctl.h>
-
-static inline void timersv_init_corespec(const char *name)
+static inline void timersv_init_corespec(void)
 {
        sigset_t set;
 
        sigemptyset(&set);
        sigaddset(&set, SIGALRM);
        pthread_sigmask(SIG_BLOCK, &set, NULL);
-
-       prctl(PR_SET_NAME, (unsigned long)name, 0, 0, 0);
 }
 
 #endif /* CONFIG_XENO_MERCURY */
@@ -96,7 +89,8 @@ static void timerobj_enqueue(struct timerobj *tmobj)
 static int server_prologue(void *arg)
 {
        svpid = get_thread_pid();
-       timersv_init_corespec("timer-internal");
+       copperplate_set_current_name("timer-internal");
+       timersv_init_corespec();
        threadobj_set_current(THREADOBJ_IRQCONTEXT);
 
        return 0;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to