Module: xenomai-head
Branch: master
Commit: d2430095358f64c486ccf906176e7ab170659859
URL:    
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=d2430095358f64c486ccf906176e7ab170659859

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Sep 18 17:17:28 2011 +0200

vxworks: fix taskDelete(), taskDeleteForce()

---

 ksrc/skins/vxworks/defs.h    |    6 ++--
 ksrc/skins/vxworks/syscall.c |   23 ++++++++++++-
 src/skins/vxworks/taskLib.c  |   70 +++++++++++++++++++++++++++++++++++++----
 3 files changed, 87 insertions(+), 12 deletions(-)

diff --git a/ksrc/skins/vxworks/defs.h b/ksrc/skins/vxworks/defs.h
index b6e33b9..0acf0d4 100644
--- a/ksrc/skins/vxworks/defs.h
+++ b/ksrc/skins/vxworks/defs.h
@@ -221,10 +221,10 @@ static inline int wind_errnoget(void)
 
 
 /* Must be called with nklock locked, interrupts off. */
-static inline void taskSafeInner (xnthread_t *cur)
+static inline void taskSafeInner (xnthread_t *thread)
 {
-       if (xnthread_get_magic(cur) == VXWORKS_SKIN_MAGIC) {
-               wind_task_t *task = thread2wind_task(cur);
+       if (xnthread_get_magic(thread) == VXWORKS_SKIN_MAGIC) {
+               wind_task_t *task = thread2wind_task(thread);
                task->safecnt++;
        }
 }
diff --git a/ksrc/skins/vxworks/syscall.c b/ksrc/skins/vxworks/syscall.c
index 26a48d2..3b26bdd 100644
--- a/ksrc/skins/vxworks/syscall.c
+++ b/ksrc/skins/vxworks/syscall.c
@@ -341,12 +341,31 @@ static int __wind_task_unlock(struct pt_regs *regs)
 }
 
 /*
- * int __wind_task_safe(void)
+ * int __wind_task_safe(TASK_ID task_id)
  */
 
 static int __wind_task_safe(struct pt_regs *regs)
 {
-       taskSafe();
+       xnhandle_t handle = __xn_reg_arg1(regs);
+       xnthread_t *thread;
+       WIND_TCB *pTcb;
+       spl_t s;
+
+       xnlock_get_irqsave(&nklock, s);
+
+       if (handle) {
+               pTcb = __wind_lookup_task(handle);
+               if (pTcb == NULL) {
+                       xnlock_put_irqrestore(&nklock, s);
+                       return S_objLib_OBJ_ID_ERROR;
+               }
+               thread = &pTcb->threadbase;
+       } else
+               thread = xnpod_current_thread();
+
+       taskSafeInner(thread);
+       xnlock_put_irqrestore(&nklock, s);
+
        return 0;
 }
 
diff --git a/src/skins/vxworks/taskLib.c b/src/skins/vxworks/taskLib.c
index 7d318ae..819e35f 100644
--- a/src/skins/vxworks/taskLib.c
+++ b/src/skins/vxworks/taskLib.c
@@ -252,12 +252,43 @@ TASK_ID taskSpawn(const char *name,
        return taskActivate(tcb.handle) == ERROR ? ERROR : tcb.handle;
 }
 
-STATUS taskDeleteForce(TASK_ID task_id)
+STATUS taskDelete(TASK_ID task_id)
 {
+       TASK_DESC desc;
+       pthread_t tid;
        int err;
 
-       err = XENOMAI_SKINCALL1(__vxworks_muxid,
-                               __vxworks_task_deleteforce, task_id);
+       err = XENOMAI_SKINCALL2(__vxworks_muxid,
+                               __vxworks_taskinfo_get, task_id, &desc);
+       if (err) {
+               errno = abs(err);
+               return ERROR;
+       }
+
+       tid = (pthread_t)desc.td_opaque;
+       if (tid == pthread_self()) {
+               /* Silently migrate to avoid raising SIGXCPU. */
+               XENOMAI_SYSCALL1(__xn_sys_migrate, XENOMAI_LINUX_DOMAIN);
+               pthread_exit(NULL);
+       }
+
+       /*
+        * Serialize and lock out anyone from safe sections. We won't
+        * release this lock, which is untracked (no PIP) and lives
+        * within the target thread TCB, so that is ok.
+        */
+       XENOMAI_SKINCALL1(__vxworks_muxid, __vxworks_task_safe, task_id);
+
+       if (tid) {
+               err = pthread_cancel(tid);
+               if (err)
+                       return -err;
+       }
+
+       err = XENOMAI_SKINCALL1(__vxworks_muxid, __vxworks_task_delete, 
task_id);
+       if (err == S_objLib_OBJ_ID_ERROR)
+               return OK; /* Used to be valid, but has exited. */
+
        if (err) {
                errno = abs(err);
                return ERROR;
@@ -266,12 +297,37 @@ STATUS taskDeleteForce(TASK_ID task_id)
        return OK;
 }
 
-STATUS taskDelete(TASK_ID task_id)
+STATUS taskDeleteForce(TASK_ID task_id)
 {
+       TASK_DESC desc;
+       pthread_t tid;
        int err;
 
-       err =
-           XENOMAI_SKINCALL1(__vxworks_muxid, __vxworks_task_delete, task_id);
+       err = XENOMAI_SKINCALL2(__vxworks_muxid,
+                               __vxworks_taskinfo_get, task_id, &desc);
+       if (err) {
+               errno = abs(err);
+               return ERROR;
+       }
+
+       tid = (pthread_t)desc.td_opaque;
+       if (tid == pthread_self()) {
+               /* Silently migrate to avoid raising SIGXCPU. */
+               XENOMAI_SYSCALL1(__xn_sys_migrate, XENOMAI_LINUX_DOMAIN);
+               pthread_exit(NULL);
+       }
+
+       if (tid) {
+               err = pthread_cancel(tid);
+               if (err)
+                       return -err;
+       }
+
+       err = XENOMAI_SKINCALL1(__vxworks_muxid,
+                               __vxworks_task_deleteforce, task_id);
+       if (err == S_objLib_OBJ_ID_ERROR)
+               return OK; /* Used to be valid, but has exited. */
+
        if (err) {
                errno = abs(err);
                return ERROR;
@@ -384,7 +440,7 @@ STATUS taskUnlock(void)
 
 STATUS taskSafe(void)
 {
-       XENOMAI_SKINCALL0(__vxworks_muxid, __vxworks_task_safe);
+       XENOMAI_SKINCALL1(__vxworks_muxid, __vxworks_task_safe, 0);
        return OK;
 }
 


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

Reply via email to