[Xenomai-git] Philippe Gerum : copperplate/heapobj: check sanity of ref-types at build time (C only)

2014-05-05 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 28221054cfb21b0c1a988b0fa972432ab85d848d
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=28221054cfb21b0c1a988b0fa972432ab85d848d

Author: Philippe Gerum 
Date:   Mon May  5 09:28:54 2014 +0200

copperplate/heapobj: check sanity of ref-types at build time (C only)

---

 include/copperplate/heapobj.h |   21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index 38deb89..6b5617c 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -324,21 +324,30 @@ static inline int pshared_check(void *heap, void *addr)
return 0;
 }
 
+#ifdef __cplusplus
+#define __check_ref_width(__dst, __src)\
+   ({  \
+   assert(sizeof(__dst) >= sizeof(__src)); \
+   (typeof(__dst))__src;   \
+   })
+#else
+#define __check_ref_width(__dst, __src)
\
+   __builtin_choose_expr(  \
+   sizeof(__dst) >= sizeof(__src), (typeof(__dst))__src,   \
+   ((void)0))
+#endif
+
 #define mainheap_ref(ptr, type)
\
({  \
type handle;\
-   assert(__builtin_types_compatible_p(typeof(type), unsigned 
long) || \
-  __builtin_types_compatible_p(typeof(type), uintptr_t)); \
+   handle = __check_ref_width(handle, ptr);\
assert(ptr == NULL || __memchk(__main_heap, ptr));  \
-   handle = (type)ptr; \
handle; \
})
 #define mainheap_deref(handle, type)   \
({  \
type *ptr;  \
-   assert(__builtin_types_compatible_p(typeof(handle), unsigned 
long) || \
-  __builtin_types_compatible_p(typeof(handle), 
uintptr_t)); \
-   ptr = (type *)handle;   \
+   ptr = __check_ref_width(ptr, handle);   \
ptr;\
})
 


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


[Xenomai-git] Philippe Gerum : cobalt/posix: drop open coded thread hash lookups

2014-05-05 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 5442b222c4fcb5f1d683a0907141a65a2048d1e1
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=5442b222c4fcb5f1d683a0907141a65a2048d1e1

Author: Philippe Gerum 
Date:   Sat May  3 10:37:26 2014 +0200

cobalt/posix: drop open coded thread hash lookups

---

 kernel/cobalt/posix/thread.c |   14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index e11e777..18939c1 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -1083,22 +1083,16 @@ int cobalt_thread_set_name_np(unsigned long pth, const 
char __user *u_name)
 
 int cobalt_thread_probe_np(pid_t pid)
 {
-   struct global_thread_hash *gslot;
-   u32 hash;
-   int ret;
+   struct cobalt_thread *thread;
+   int ret = 0;
spl_t s;
 
-   hash = jhash2((u32 *)&pid, sizeof(pid) / sizeof(u32), 0);
-
trace_cobalt_pthread_probe(pid);
 
xnlock_get_irqsave(&nklock, s);
 
-   gslot = global_index[hash & (PTHREAD_HSLOTS - 1)];
-   while (gslot && gslot->pid != pid)
-   gslot = gslot->next;
-
-   ret = gslot ? 0 : -ESRCH;
+   if (cobalt_thread_find(pid) == NULL)
+   ret = -ESRCH;
 
xnlock_put_irqrestore(&nklock, s);
 


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