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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Apr 20 17:08:14 2015 +0200

vxworks: add task hook services

Create and delete task event hooks are supported, switch hook is not
since we don't control scheduling.

---

 include/vxworks/Makefile.am   |    1 +
 include/vxworks/taskHookLib.h |   46 ++++++++++++++++++
 lib/vxworks/Makefile.am       |    2 +
 lib/vxworks/init.c            |    3 ++
 lib/vxworks/taskHookLib.c     |  107 +++++++++++++++++++++++++++++++++++++++++
 lib/vxworks/taskHookLib.h     |   37 ++++++++++++++
 lib/vxworks/taskLib.c         |    2 +
 7 files changed, 198 insertions(+)

diff --git a/include/vxworks/Makefile.am b/include/vxworks/Makefile.am
index f880426..849fbdf 100644
--- a/include/vxworks/Makefile.am
+++ b/include/vxworks/Makefile.am
@@ -10,6 +10,7 @@ includesub_HEADERS =  \
        rngLib.h        \
        semLib.h        \
        sysLib.h        \
+       taskHookLib.h   \
        taskInfo.h      \
        taskLib.h       \
        tickLib.h       \
diff --git a/include/vxworks/taskHookLib.h b/include/vxworks/taskHookLib.h
new file mode 100644
index 0000000..132786e
--- /dev/null
+++ b/include/vxworks/taskHookLib.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2015 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+ *
+ * This file satisfies the references within the emulator code
+ * mimicking a VxWorks-like API built upon the copperplate library.
+ *
+ * VxWorks is a registered trademark of Wind River Systems, Inc.
+ */
+
+#ifndef _XENOMAI_VXWORKS_TASKHOOKLIB_H
+#define _XENOMAI_VXWORKS_TASKHOOKLIB_H
+
+#include <vxworks/types.h>
+#include <vxworks/taskLib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+STATUS taskCreateHookAdd(FUNCPTR createHook);
+
+STATUS taskCreateHookDelete(FUNCPTR createHook);
+
+STATUS taskDeleteHookAdd(FUNCPTR deleteHook);
+
+STATUS taskDeleteHookDelete(FUNCPTR deleteHook);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_XENOMAI_VXWORKS_TASKHOOKLIB_H */
diff --git a/lib/vxworks/Makefile.am b/lib/vxworks/Makefile.am
index f012f3e..483d811 100644
--- a/lib/vxworks/Makefile.am
+++ b/lib/vxworks/Makefile.am
@@ -19,6 +19,8 @@ libvxworks_la_SOURCES = \
        semLib.h        \
        taskLib.c       \
        taskLib.h       \
+       taskHookLib.c   \
+       taskHookLib.h   \
        taskInfo.c      \
        tickLib.c       \
        tickLib.h       \
diff --git a/lib/vxworks/init.c b/lib/vxworks/init.c
index 54b7cf9..198a069 100644
--- a/lib/vxworks/init.c
+++ b/lib/vxworks/init.c
@@ -25,6 +25,7 @@
 #include "init.h"
 #include "tickLib.h"
 #include "taskLib.h"
+#include "taskHookLib.h"
 
 /**
  * @defgroup vxworks VxWorks&reg; emulator
@@ -98,6 +99,8 @@ static int vxworks_init(void)
        }
 
        __RT(pthread_mutex_init(&wind_task_lock, NULL));
+       list_init(&wind_create_hooks);
+       list_init(&wind_delete_hooks);
 
        return 0;
 }
diff --git a/lib/vxworks/taskHookLib.c b/lib/vxworks/taskHookLib.c
new file mode 100644
index 0000000..80d412f
--- /dev/null
+++ b/lib/vxworks/taskHookLib.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2015 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * 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 <copperplate/heapobj.h>
+#include <vxworks/taskHookLib.h>
+#include <vxworks/errnoLib.h>
+#include "taskLib.h"
+#include "taskHookLib.h"
+
+struct list wind_create_hooks;
+
+struct list wind_delete_hooks;
+
+static STATUS add_hook(struct list *list, FUNCPTR hook, int prepend)
+{
+       struct wind_task_hook *p;
+
+       p = xnmalloc(sizeof(*p));
+       if (p == NULL)
+               return ERROR;
+
+       p->handler = (void (*)(TASK_ID))hook;
+       write_lock_nocancel(&wind_task_lock);
+
+       if (prepend)
+               list_prepend(&p->next, list);
+       else
+               list_append(&p->next, list);
+
+       write_unlock(&wind_task_lock);
+
+       return OK;
+}
+
+static STATUS remove_hook(struct list *list, FUNCPTR hook)
+{
+       struct wind_task_hook *p = NULL;
+
+       write_lock_nocancel(&wind_task_lock);
+
+       list_for_each_entry(p, list, next) {
+               if (p->handler == (void (*)(TASK_ID))hook) {
+                       list_remove(&p->next);
+                       goto found;
+               }
+       }
+
+       p = NULL;
+found:
+       write_unlock(&wind_task_lock);
+
+       if (p) {
+               xnfree(p);
+               return OK;
+       }
+
+       return ERROR;
+}
+
+void wind_run_hooks(struct list *list, struct wind_task *task)
+{
+       struct wind_task_hook *p;
+       TASK_ID tid;
+
+       write_lock_nocancel(&wind_task_lock);
+
+       tid = mainheap_ref(&task->priv_tcb, TASK_ID);
+
+       list_for_each_entry(p, list, next)
+               p->handler(tid);
+
+       write_unlock(&wind_task_lock);
+}
+
+STATUS taskCreateHookAdd(FUNCPTR createHook)
+{
+       return add_hook(&wind_create_hooks, createHook, 0);
+}
+
+STATUS taskCreateHookDelete(FUNCPTR createHook)
+{
+       return remove_hook(&wind_create_hooks, createHook);
+}
+
+STATUS taskDeleteHookAdd(FUNCPTR deleteHook)
+{
+       return add_hook(&wind_create_hooks, deleteHook, 1);
+}
+
+STATUS taskDeleteHookDelete(FUNCPTR deleteHook)
+{
+       return remove_hook(&wind_create_hooks, deleteHook);
+}
diff --git a/lib/vxworks/taskHookLib.h b/lib/vxworks/taskHookLib.h
new file mode 100644
index 0000000..3de1125
--- /dev/null
+++ b/lib/vxworks/taskHookLib.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2015 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+ */
+#ifndef _VXWORKS_TASKHOOKLIB_H
+#define _VXWORKS_TASKHOOKLIB_H
+
+#include <vxworks/taskLib.h>
+
+struct wind_task;
+
+struct wind_task_hook {
+       void (*handler)(TASK_ID tid);
+       struct holder next;
+};
+
+extern struct list wind_create_hooks;
+
+extern struct list wind_delete_hooks;
+
+void wind_run_hooks(struct list *list,
+                   struct wind_task *task);
+
+#endif /* _VXWORKS_TASKHOOKLIB_H */
diff --git a/lib/vxworks/taskLib.c b/lib/vxworks/taskLib.c
index ddb7df6..6cbcbf3 100644
--- a/lib/vxworks/taskLib.c
+++ b/lib/vxworks/taskLib.c
@@ -28,6 +28,7 @@
 #include "taskLib.h"
 #include "tickLib.h"
 #include "msgQLib.h"
+#include "taskHookLib.h"
 #include "copperplate/init.h"
 #include "copperplate/heapobj.h"
 #include "copperplate/threadobj.h"
@@ -157,6 +158,7 @@ static void task_finalizer(struct threadobj *thobj)
                write_lock_nocancel(&wind_task_lock);
                pvlist_remove(&task->next);
                write_unlock(&wind_task_lock);
+               wind_run_hooks(&wind_delete_hooks, task);
        }
 
        task->tcb->status |= WIND_DEAD;


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

Reply via email to