Module: xenomai-gch
Branch: for-forge
Commit: c8c9c01f26bd464a78221eecd99d066b966cb84f
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=c8c9c01f26bd464a78221eecd99d066b966cb84f

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Fri Nov 11 18:13:01 2011 +0100

nucleus: allow xnhandle_t spare bits to be used by fast xnsynch objects

---

 include/cobalt/nucleus/synch.h |    7 +++----
 include/cobalt/nucleus/types.h |    9 +++++----
 kernel/cobalt/native/mutex.c   |    4 ++--
 kernel/cobalt/nucleus/synch.c  |   15 ++++++++++-----
 4 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/include/cobalt/nucleus/synch.h b/include/cobalt/nucleus/synch.h
index 7deae21..bcfb4d3 100644
--- a/include/cobalt/nucleus/synch.h
+++ b/include/cobalt/nucleus/synch.h
@@ -42,7 +42,7 @@
 static inline int xnsynch_fast_owner_check(xnarch_atomic_t *fastlock,
                                           xnhandle_t ownerh)
 {
-       return (xnhandle_mask_spare(xnarch_atomic_get(fastlock)) == ownerh) ?
+       return (xnhandle_mask_spares(xnarch_atomic_get(fastlock)) == ownerh) ?
                0 : -EPERM;
 }
 
@@ -55,7 +55,7 @@ static inline int xnsynch_fast_acquire(xnarch_atomic_t 
*fastlock,
        if (likely(lock_state == XN_NO_HANDLE))
                return 0;
 
-       if (xnhandle_mask_spare(lock_state) == new_ownerh)
+       if (xnhandle_mask_spares(lock_state) == new_ownerh)
                return -EBUSY;
 
        return -EAGAIN;
@@ -152,10 +152,9 @@ typedef struct xnsynch {
 #endif /* !CONFIG_XENO_FASTSYNCH */
 
 #define xnsynch_fast_is_claimed(fastlock) \
-       xnhandle_test_spare(fastlock, XNSYNCH_FLCLAIM)
+       xnhandle_test_spares(fastlock, XNSYNCH_FLCLAIM)
 #define xnsynch_fast_set_claimed(fastlock, enable) \
        (((fastlock) & ~XNSYNCH_FLCLAIM) | ((enable) ? XNSYNCH_FLCLAIM : 0))
-#define xnsynch_fast_mask_claimed(fastlock) ((fastlock) & ~XNSYNCH_FLCLAIM)
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/include/cobalt/nucleus/types.h b/include/cobalt/nucleus/types.h
index 0432005..57733e3 100644
--- a/include/cobalt/nucleus/types.h
+++ b/include/cobalt/nucleus/types.h
@@ -70,11 +70,12 @@ typedef unsigned long xnhandle_t;
 #define XN_HANDLE_SPARE3       ((xnhandle_t)0x80000000)
 #define XN_HANDLE_SPARE_MASK   ((xnhandle_t)0xf0000000)
 
-#define xnhandle_mask_spare(handle)  ((handle) & ~XN_HANDLE_SPARE_MASK)
-#define xnhandle_test_spare(handle, bits)  (!!((handle) & (bits)))
-#define xnhandle_set_spare(handle, bits) \
+#define xnhandle_mask_spares(handle)  ((handle) & ~XN_HANDLE_SPARE_MASK)
+#define xnhandle_get_spares(handle, bits)   ((handle) & (bits))
+#define xnhandle_test_spares(handle, bits)  
(!!xnhandle_get_spares(handle,bits))
+#define xnhandle_set_spares(handle, bits) \
        do { (handle) |= (bits); } while (0)
-#define xnhandle_clear_spare(handle, bits) \
+#define xnhandle_clear_spares(handle, bits) \
        do { (handle) &= ~(bits); } while (0)
 
 struct xnintr;
diff --git a/kernel/cobalt/native/mutex.c b/kernel/cobalt/native/mutex.c
index 4e13f4a..1de1068 100644
--- a/kernel/cobalt/native/mutex.c
+++ b/kernel/cobalt/native/mutex.c
@@ -77,7 +77,7 @@ static int vfile_rewind(struct xnvfile_snapshot_iterator *it)
 #ifdef CONFIG_XENO_FASTSYNCH
        lock_state = xnarch_atomic_get(mutex->synch_base.fastlock);
        owner = (lock_state == XN_NO_HANDLE) ? NULL :
-               xnthread_lookup(xnsynch_fast_mask_claimed(lock_state));
+               xnthread_lookup(xnhandle_mask_spares(lock_state));
 
        if (owner == NULL && lock_state != XN_NO_HANDLE)
                strncpy(priv->owner, "<DAMAGED HANDLE>",
@@ -660,7 +660,7 @@ int rt_mutex_inquire(RT_MUTEX *mutex, RT_MUTEX_INFO *info)
        lock_state = xnarch_atomic_get(mutex->synch_base.fastlock);
        info->locked = (lock_state != XN_NO_HANDLE);
        owner = (info->locked) ?
-               xnthread_lookup(xnsynch_fast_mask_claimed(lock_state)) : NULL;
+               xnthread_lookup(xnhandle_mask_spares(lock_state)) : NULL;
        if (!owner && info->locked)
                strcpy(info->owner, "<DAMAGED HANDLE!>");
        else
diff --git a/kernel/cobalt/nucleus/synch.c b/kernel/cobalt/nucleus/synch.c
index 25ae4f2..8dc1c52 100644
--- a/kernel/cobalt/nucleus/synch.c
+++ b/kernel/cobalt/nucleus/synch.c
@@ -453,7 +453,7 @@ xnflags_t xnsynch_acquire(struct xnsynch *synch, xnticks_t 
timeout,
                        fastlock = old;
                } while (!xnsynch_fast_is_claimed(fastlock));
 
-               owner = xnthread_lookup(xnsynch_fast_mask_claimed(fastlock));
+               owner = xnthread_lookup(xnhandle_mask_spares(fastlock));
 
                if (!owner) {
                        /* The handle is broken, therefore pretend that the 
synch
@@ -543,10 +543,13 @@ xnflags_t xnsynch_acquire(struct xnsynch *synch, 
xnticks_t timeout,
                        xnarch_atomic_t *lockp = xnsynch_fastlock(synch);
                        /* We are the new owner, update the fastlock
                           accordingly. */
-                       if (xnsynch_pended_p(synch))
-                               threadh =
-                                   xnsynch_fast_set_claimed(threadh, 1);
-                       xnarch_atomic_set(lockp, threadh);
+                       fastlock = threadh |
+                               xnhandle_get_spares(xnarch_atomic_get(lockp),
+                                                   XN_HANDLE_SPARE_MASK);
+                       fastlock =
+                               xnsynch_fast_set_claimed(fastlock,
+                                                        
xnsynch_pended_p(synch));
+                       xnarch_atomic_set(lockp, fastlock);
                }
        }
 
@@ -716,6 +719,8 @@ xnsynch_release_thread(struct xnsynch *synch, struct 
xnthread *lastowner)
        }
        if (use_fastlock) {
                xnarch_atomic_t *lockp = xnsynch_fastlock(synch);
+               newownerh |= xnhandle_get_spares(xnarch_atomic_get(lockp),
+                                                XN_HANDLE_SPARE_MASK & 
~XNSYNCH_FLCLAIM);
                xnarch_atomic_set(lockp, newownerh);
        }
 


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

Reply via email to