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

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.

Hooks are process-local.

---

 include/vxworks/Makefile.am   |    1 +
 include/vxworks/taskHookLib.h |   46 ++++++++++++++++++
 lib/vxworks/Makefile.am       |    2 +
 lib/vxworks/taskHookLib.c     |  107 +++++++++++++++++++++++++++++++++++++++++
 lib/vxworks/taskHookLib.h     |   37 ++++++++++++++
 lib/vxworks/taskLib.c         |    4 ++
 6 files changed, 197 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/taskHookLib.c b/lib/vxworks/taskHookLib.c
new file mode 100644
index 0000000..bf61b79
--- /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"
+
+DEFINE_PRIVATE_LIST(wind_create_hooks);
+
+DEFINE_PRIVATE_LIST(wind_delete_hooks);
+
+static STATUS add_hook(struct pvlist *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)
+               pvlist_prepend(&p->next, list);
+       else
+               pvlist_append(&p->next, list);
+
+       write_unlock(&wind_task_lock);
+
+       return OK;
+}
+
+static STATUS remove_hook(struct pvlist *list, FUNCPTR hook)
+{
+       struct wind_task_hook *p = NULL;
+
+       write_lock_nocancel(&wind_task_lock);
+
+       pvlist_for_each_entry(p, list, next) {
+               if (p->handler == (void (*)(TASK_ID))hook) {
+                       pvlist_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 pvlist *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);
+
+       pvlist_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..d30af0c
--- /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 pvholder next;
+};
+
+extern struct pvlist wind_create_hooks;
+
+extern struct pvlist wind_delete_hooks;
+
+void wind_run_hooks(struct pvlist *list,
+                   struct wind_task *task);
+
+#endif /* _VXWORKS_TASKHOOKLIB_H */
diff --git a/lib/vxworks/taskLib.c b/lib/vxworks/taskLib.c
index ddb7df6..81540c4 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;
@@ -256,6 +258,8 @@ static void *task_trampoline(void *arg)
                warning("failed to export task %s to registry, %s",
                        task->name, symerror(ret));
 
+       wind_run_hooks(&wind_create_hooks, task);
+       
        /* Wait for someone to run taskActivate() upon us. */
        threadobj_wait_start();
 


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

Reply via email to