Skip to contentSkip to conversation

fix rt_task_delete for cancellable rt-threads

PATCH In review Jan Kiszka 1 participant 3 messages Dec 8, 2005 – Dec 10, 2005

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 fix rt_task_delete for cancellable rt-threads

Hi,

no, this is not the fix for the issue I described earlier. This just improves the behaviour of rt_task_delete in case the target is blocking at a cancellation point (tested with standard sem_wait). With the current version, rt_task_deletes the rt-shadow and just wakes up the linux pthread even if the target is cancellable at that moment. With the reordering, this is fixed and the target is actually terminated. No major issue, though.

Jan

skins/native/task.c +11 -5
Index: src/skins/native/task.c
===================================================================
@@ -203,12 +203,18 @@
 int rt_task_delete (RT_TASK *task)
 
 {
-    int err = XENOMAI_SKINCALL1(__native_muxid,
-				__native_task_delete,
-				task);
-    if (!err)
-	pthread_cancel((pthread_t)task->opaque2);
+    int err;
 
+    err = pthread_cancel((pthread_t)task->opaque2)
+    if (err)
+        return -err;
+
+    err = XENOMAI_SKINCALL1(__native_muxid,
+			    __native_task_delete,
+			    task);
+    if (err == -ESRCH)
+	return 0;
+
     return err;
 }
 
author
#1 lore raw
Quoted 33 lines · Jan Kiszka

Hi,

no, this is not the fix for the issue I described earlier. This just improves the behaviour of rt_task_delete in case the target is blocking at a cancellation point (tested with standard sem_wait). With the current version, rt_task_deletes the rt-shadow and just wakes up the linux pthread even if the target is cancellable at that moment. With the reordering, this is fixed and the target is actually terminated. No major issue, though.

Jan

------------------------------------------------------------------------

Index: src/skins/native/task.c
===================================================================

skins/native/task.c +4 -5
@@ -203,12 +203,18 @@
 int rt_task_delete (RT_TASK *task)
 
 {
-    int err = XENOMAI_SKINCALL1(__native_muxid,
-				__native_task_delete,
-				task);
-    if (!err)
-	pthread_cancel((pthread_t)task->opaque2);
+    int err;
 
+    err = pthread_cancel((pthread_t)task->opaque2)
+    if (err)
+        return -err;

skins/native/task.c line 220

Quoted 10 lines
skins/native/task.c +7 -0
+
+    err = XENOMAI_SKINCALL1(__native_muxid,
+			    __native_task_delete,
+			    task);
+    if (err == -ESRCH)
+	return 0;
+
     return err;
 }
 

Oops, fix for my patch:

src/skins/native/task.c (Arbeitskopie) renamed from src/skins/native/task.c (Revision 251) +1 -1
@@ -206,7 +206,7 @@
 {
     int err;
 
-    err = pthread_cancel((pthread_t)task->opaque2)
+    err = pthread_cancel((pthread_t)task->opaque2);
     if (err)
         return -err;
 

I reorganised the code without a compiler run before posting.

Jan

author
#2 lore raw

Hi Philippe,

really hope we can close this issue soon, but I managed to add another regression with my fix (rt_task_delete(NULL) caused seg-faults, e.g. in latency). Please apply the attached path against current SVN.

Jan

skins/native/task.c +5 -3
Index: src/skins/native/task.c
===================================================================
@@ -206,9 +206,11 @@
 {
     int err;
 
-    err = pthread_cancel((pthread_t)task->opaque2)
-    if (err)
-        return -err;
+    if (task) {
+	err = pthread_cancel((pthread_t)task->opaque2);
+	if (err)
+	    return -err;
+    }
 
     err = XENOMAI_SKINCALL1(__native_muxid,
 			    __native_task_delete,