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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Jun 17 10:32:19 2013 +0200

kernel/cobalt/posix: remove dead cancel support

---

 kernel/cobalt/posix/cancel.c |  409 ------------------------------------------
 kernel/cobalt/posix/cancel.h |   26 ---
 kernel/cobalt/posix/cond.c   |    6 +-
 kernel/cobalt/posix/thread.c |    1 -
 4 files changed, 1 insertions(+), 441 deletions(-)

diff --git a/kernel/cobalt/posix/cancel.c b/kernel/cobalt/posix/cancel.c
deleted file mode 100644
index c83c63e..0000000
--- a/kernel/cobalt/posix/cancel.c
+++ /dev/null
@@ -1,409 +0,0 @@
-/*
- * Written by Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-/**
- * @ingroup cobalt_thread
- * @defgroup cobalt_cancel Thread cancellation.
- *
- * Thread cancellation.
- *
- * Cancellation is the mechanism by which a thread can terminate the execution
- * of a Cobalt thread (created with pthread_create()). More
- * precisely, a thread can send a cancellation request to a Cobalt
- * thread and depending on its cancelability type (see pthread_setcanceltype())
- * and state (see pthread_setcancelstate()), the target thread can then either
- * ignore the request, honor it immediately, or defer it till it reaches a
- * cancellation point. When threads are first created by pthread_create(), they
- * always defer cancellation requests.
- *
- * When a thread eventually honors a cancellation request, it behaves as if
- * @a pthread_exit(PTHREAD_CANCELED) was called.  All cleanup handlers are
- * executed in reverse order, finalization functions for thread-specific data
- * are called, and finally the thread stops executing. If the canceled thread
- * was joinable, the return value PTHREAD_CANCELED is provided to whichever
- * thread calls pthread_join() on it. See pthread_exit() for more information.
- *
- * Cancellation points are the points where the thread checks for pending
- * cancellation requests and performs them.  The POSIX threads functions
- * pthread_join(), pthread_cond_wait(), pthread_cond_timedwait(),
- * pthread_testcancel(), sem_wait(), sem_timedwait(), sigwait(), sigwaitinfo()
- * and sigtimedwait() are cancellation points.
- *
- * @see
- * <a 
href="http://www.opengroup.org/onlinepubs/000095399/functions/xsh_chap02_09.html#tag_02_09_05";>
- * Specification.</a>
- *
- *@{*/
-
-#include "thread.h"
-#include "cancel.h"
-
-typedef void cleanup_routine_t(void *);
-
-typedef struct {
-       cleanup_routine_t *routine;
-       void *arg;
-       xnholder_t link;
-
-#define link2cleanup_handler(laddr) container_of(laddr, cleanup_handler_t, 
link)
-
-} cleanup_handler_t;
-
-/**
- * Cancel a thread.
- *
- * This service sends a cancellation request to the thread @a thread and 
returns
- * immediately. Depending on the target thread cancelability state (see
- * pthread_setcancelstate()) and type (see pthread_setcanceltype()), its
- * termination is either immediate, deferred or ignored.
- *
- * When the cancellation request is handled and before the thread is 
terminated,
- * the cancellation cleanup handlers (registered with the 
pthread_cleanup_push()
- * service) are called, then the thread-specific data destructor functions
- * (registered with pthread_key_create()).
- *
- * @return 0 on success;
- * @return an error number if:
- * - ESRCH, the thread @a thread was not found.
- *
- * @see
- * <a 
href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_cancel.html";>
- * Specification.</a>
- *
- */
-int pthread_cancel(pthread_t thread)
-{
-       int cancel_enabled;
-       spl_t s;
-
-       xnlock_get_irqsave(&nklock, s);
-
-       if (!cobalt_obj_active(thread, COBALT_THREAD_MAGIC, struct 
cobalt_thread)) {
-               xnlock_put_irqrestore(&nklock, s);
-               return ESRCH;
-       }
-
-       cancel_enabled = thread_getcancelstate(thread) == PTHREAD_CANCEL_ENABLE;
-
-       if (cancel_enabled
-           && thread_getcanceltype(thread) == PTHREAD_CANCEL_ASYNCHRONOUS)
-               cobalt_thread_abort(thread, PTHREAD_CANCELED);
-       else {
-               /* pthread_cancel is not a cancellation point, so
-                  thread == pthread_self() is not a special case. */
-
-               thread_setcancel(thread);
-
-               if (cancel_enabled) {
-                       /* Unblock thread, so that it can honor the 
cancellation request. */
-                       xnpod_unblock_thread(&thread->threadbase);
-                       xnpod_schedule();
-               }
-       }
-
-       xnlock_put_irqrestore(&nklock, s);
-
-       return 0;
-}
-
-/**
- * Register a cleanup handler to be executed at the time of cancellation.
- *
- * This service registers the given @a routine to be executed a the time of
- * cancellation of the calling thread, if this thread is a Cobalt
- * thread (i.e. created with the pthread_create() service). If the caller
- * context is invalid (not a Cobalt thread), this service has no
- * effect.
- *
- * If allocation from the system heap fails (because the system heap size is to
- * small), this service fails silently.
- *
- * The routines registered with this service get called in LIFO order when the
- * calling thread calls pthread_exit() or is canceled, or when it calls the
- * pthread_cleanup_pop() service with a non null argument.
- *
- * @param routine the cleanup routine to be registered;
- *
- * @param arg the argument associated with this routine.
- *
- * @par Valid contexts:
- * - Cobalt kernel-space thread,
- * - Cobalt user-space thread (switches to primary mode).
- *
- * @see
- * <a 
href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_cleanup_push.html";>
- * Specification.</a>
- *
- */
-void pthread_cleanup_push(cleanup_routine_t * routine, void *arg)
-{
-       pthread_t cur = cobalt_current_thread();
-       cleanup_handler_t *handler;
-       spl_t s;
-
-       if (!routine || !cur || xnpod_asynch_p())
-               return;
-
-       /* The allocation is inside the critical section in order to make the
-          function async-signal safe, that is in order to avoid leaks if an
-          asynchronous cancellation request could occur between the call to
-          xnmalloc and xnlock_get_irqsave. */
-
-       xnlock_get_irqsave(&nklock, s);
-
-       handler = xnmalloc(sizeof(*handler));
-
-       if (!handler) {
-               xnlock_put_irqrestore(&nklock, s);
-               return;
-       }
-
-       handler->routine = routine;
-       handler->arg = arg;
-       inith(&handler->link);
-
-       prependq(thread_cleanups(cur), &handler->link);
-
-       xnlock_put_irqrestore(&nklock, s);
-}
-
-/**
- * Unregister the last registered cleanup handler.
- *
- * If the calling thread is a Cobalt thread (i.e. created with
- * pthread_create()), this service unregisters the last routine which was
- * registered with pthread_cleanup_push() and call it if @a execute is not 
null.
- *
- * If the caller context is invalid (not a Cobalt thread), this
- * service has no effect.
- *
- * This service may be called at any place, but for maximal portability, should
- * only called in the same lexical scope as the matching call to
- * pthread_cleanup_push().
- *
- * @param execute if non zero, the last registered cleanup handler should be
- * executed before it is unregistered.
- *
- * @par Valid contexts:
- * - Cobalt kernel-space thread,
- * - Cobalt user-space thread (switches to primary mode).
- *
- * @see
- * <a 
href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_cleanup_pop.html";>
- * Specification.</a>
- *
- */
-void pthread_cleanup_pop(int execute)
-{
-       pthread_t cur = cobalt_current_thread();
-       cleanup_handler_t *handler;
-       cleanup_routine_t *routine;
-       xnholder_t *holder;
-       void *arg;
-       spl_t s;
-
-       if (!cur || xnpod_asynch_p())
-               return;
-
-       xnlock_get_irqsave(&nklock, s);
-
-       holder = getq(thread_cleanups(cur));
-
-       if (!holder) {
-               xnlock_put_irqrestore(&nklock, s);
-               return;
-       }
-
-       handler = link2cleanup_handler(holder);
-
-       routine = handler->routine;
-       arg = handler->arg;
-
-       /* Same remark as xnmalloc in pthread_cleanup_push */
-       xnfree(handler);
-
-       xnlock_put_irqrestore(&nklock, s);
-
-       if (execute)
-               routine(arg);
-}
-
-/**
- * Set cancelability type of the current thread.
- *
- * This service atomically sets the cancelability type of the calling thread,
- * and return its previous value at the address @a oldtype_ptr, if this thread
- * is a Cobalt thread (i.e. was created with the pthread_create()
- * service).
- *
- * The cancelability type of a POSIX thread may be:
- * - PTHREAD_CANCEL_DEFERRED, meaning that cancellation requests are only
- *   handled in services which are cancellation points;
- * - PTHREAD_CANCEL_ASYNCHRONOUS, meaning that cancellation requests are 
handled
- *   as soon as they are sent.
- *
- * @param type new cancelability type of the calling thread;
- *
- * @param oldtype_ptr address where the old cancelability type will be stored 
on
- * success.
- *
- * @return 0 on success;
- * @return an error number if:
- * - EINVAL, @a type is not a valid cancelability type;
- * - EPERM, the caller context is invalid.
- *
- * @par Valid contexts:
- * - Cobalt kernel-space thread,
- * - Cobalt user-space thread (switches to primary mode).
- *
- * @see
- * <a 
href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_setcanceltype.html";>
- * Specification.</a>
- *
- */
-int pthread_setcanceltype(int type, int *oldtype_ptr)
-{
-       pthread_t cur;
-       int oldtype;
-       spl_t s;
-
-       switch (type) {
-       default:
-
-               return EINVAL;
-
-       case PTHREAD_CANCEL_DEFERRED:
-       case PTHREAD_CANCEL_ASYNCHRONOUS:
-
-               break;
-       }
-
-       cur = cobalt_current_thread();
-
-       if (!cur || xnpod_interrupt_p())
-               return EPERM;
-
-       xnlock_get_irqsave(&nklock, s);
-
-       oldtype = thread_getcanceltype(cur);
-
-       thread_setcanceltype(cur, type);
-
-       if (oldtype_ptr)
-               *oldtype_ptr = oldtype;
-
-       xnlock_put_irqrestore(&nklock, s);
-
-       return 0;
-}
-
-/**
- * Set cancelability state of the current thread.
- *
- * This service atomically set the cancelability state of the calling thread 
and
- * returns its previous value at the address @a oldstate_ptr, if the calling
- * thread is a Cobalt thread (i.e. created with the pthread_create
- * service).
- *
- * The cancelability state of a POSIX thread may be:
- * - PTHREAD_CANCEL_ENABLE, meaning that cancellation requests will be handled
- *   if received;
- * - PTHREAD_CANCEL_DISABLE, meaning that cancellation requests will not be
- *   handled if received.
- *
- * @param state new cancelability state of the calling thread;
- *
- * @param oldstate_ptr address where the old cancelability state will be stored
- * on success.
- *
- * @return 0 on success;
- * @return an error number if:
- * - EINVAL, @a state is not a valid cancelability state;
- * - EPERM, the caller context is invalid.
- *
- * @par Valid contexts:
- * - Cobalt kernel-space thread,
- * - Cobalt user-space thread (switches to primary mode).
- *
- * @see
- * <a 
href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_setcancelstate.html";>
- * Specification.</a>
- *
- */
-int pthread_setcancelstate(int state, int *oldstate_ptr)
-{
-       pthread_t cur;
-       int oldstate;
-       spl_t s;
-
-       switch (state) {
-       default:
-
-               return EINVAL;
-
-       case PTHREAD_CANCEL_ENABLE:
-       case PTHREAD_CANCEL_DISABLE:
-
-               break;
-       }
-
-       cur = cobalt_current_thread();
-
-       if (!cur || xnpod_interrupt_p())
-               return EPERM;
-
-       xnlock_get_irqsave(&nklock, s);
-
-       oldstate = thread_getcancelstate(cur);
-       thread_setcancelstate(cur, state);
-
-       if (oldstate_ptr)
-               *oldstate_ptr = oldstate;
-
-       xnlock_put_irqrestore(&nklock, s);
-
-       return 0;
-}
-
-void cobalt_cancel_init_thread(pthread_t thread)
-{
-       thread_setcancelstate(thread, PTHREAD_CANCEL_ENABLE);
-       thread_setcanceltype(thread, PTHREAD_CANCEL_DEFERRED);
-       thread_clrcancel(thread);
-       initq(thread_cleanups(thread));
-}
-
-void cobalt_cancel_cleanup_thread(pthread_t thread)
-{
-       xnholder_t *holder;
-
-       while ((holder = getq(thread_cleanups(thread)))) {
-               cleanup_handler_t *handler = link2cleanup_handler(holder);
-               handler->routine(handler->arg);
-               xnfree(handler);
-       }
-}
-
-/*@}*/
-
-EXPORT_SYMBOL_GPL(pthread_cancel);
-EXPORT_SYMBOL_GPL(pthread_cleanup_push);
-EXPORT_SYMBOL_GPL(pthread_cleanup_pop);
-EXPORT_SYMBOL_GPL(pthread_setcancelstate);
-EXPORT_SYMBOL_GPL(pthread_setcanceltype);
-EXPORT_SYMBOL_GPL(pthread_testcancel);
diff --git a/kernel/cobalt/posix/cancel.h b/kernel/cobalt/posix/cancel.h
deleted file mode 100644
index 8c97af4..0000000
--- a/kernel/cobalt/posix/cancel.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Written by Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef _COBALT_CANCEL_H
-#define _COBALT_CANCEL_H
-
-void cobalt_cancel_init_thread(pthread_t thread);
-
-void cobalt_cancel_cleanup_thread(pthread_t thread);
-
-#endif /* !_COBALT_CANCEL_H */
diff --git a/kernel/cobalt/posix/cond.c b/kernel/cobalt/posix/cond.c
index d0b876e..3578476 100644
--- a/kernel/cobalt/posix/cond.c
+++ b/kernel/cobalt/posix/cond.c
@@ -290,7 +290,7 @@ static inline int cobalt_cond_timedwait_prologue(xnthread_t 
*cur,
        else
                xnsynch_sleep_on(&cond->synchbase, XN_INFINITE, XN_RELATIVE);
 
-       /* There are four possible wakeup conditions :
+       /* There are three possible wakeup conditions :
           - cond_signal / cond_broadcast, no status bit is set, and the 
function
             should return 0 ;
           - timeout, the status XNTIMEO is set, and the function should return
@@ -300,10 +300,6 @@ static inline int 
cobalt_cond_timedwait_prologue(xnthread_t *cur,
             interface, replaced by 0 anywhere else), causing a wakeup, spurious
             or not whether pthread_cond_signal was called between pthread_kill
             and the moment when xnsynch_sleep_on returned ;
-          - pthread_cancel, no status bit is set, but cancellation specific
-            bits are set, and tested only once the mutex is reacquired in
-            cobalt_cond_timedwait_epilogue, so that the cancellation handler 
can
-            be called with the mutex locked, as required by the specification.
         */
 
        err = 0;
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index b344302..11f75da 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -31,7 +31,6 @@
 #include <linux/types.h>
 #include <linux/jhash.h>
 #include "thread.h"
-#include "cancel.h"
 #include "timer.h"
 
 xnticks_t cobalt_time_slice;


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

Reply via email to