[PATCH] longjmp implementation

From: Darren Vincent Hart
Date: Thu Oct 29 2009 - 21:11:32 EST


---
mutexint.c | 27 +++++++++++++++++++--------
1 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/mutexint.c b/mutexint.c
index 003717f..82a608b 100644
--- a/mutexint.c
+++ b/mutexint.c
@@ -37,6 +37,7 @@
#include <sys/types.h>
#include <linux/futex.h>
#include <errno.h>
+#include <setjmp.h>

/*
* The futex() call has been removed from the include/futex.h header, implement
@@ -44,7 +45,8 @@
*/
//#define SYS_futex 202
#define FUTEX_PRIVATE 128
-#define FUTEX_INTERRUPTIBLE 512
+//#define FUTEX_INTERRUPTIBLE 512
+#define FUTEX_INTERRUPTIBLE 0
#define futex(uaddr, op, val, timeout, uaddr2, val3) \
syscall(SYS_futex, uaddr, op, val, timeout, uaddr2, val3)

@@ -59,6 +61,9 @@

#define SIGMUTEXINT SIGRTMIN

+/* Need some kind of per-thread variable here */
+jmp_buf env;
+
/*
* Implement cmpxchg using gcc atomic builtins.
* http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html
@@ -80,6 +85,7 @@ struct mutexint_attr {
void sigmutexint_handler(int signo)
{
printf("handled cancel signal: %d\n", signo);
+ longjmp(env, 1);
}

int mutexint_init(struct mutexint *mutex, struct mutexint_attr *attr)
@@ -102,13 +108,18 @@ int mutexint_lock(struct mutexint *mutex)
if ((val & FUTEX_WAITERS) ||
(val = cmpxchg(&mutex->lock_val, val, val | FUTEX_WAITERS))) {
printf("\tinner cmpxchg old_val: 0x%x lock_val: 0x%x\n", val, mutex->lock_val);
- printf("\tcalling futex_lock_pi:\n");
- printf("\top: 0x%x\n", FUTEX_LOCK_PI | FUTEX_PRIVATE | FUTEX_INTERRUPTIBLE);
- printf("\t&lock_val: %p\n", &mutex->lock_val);
- ret = futex_lock_pi(&mutex->lock_val, val, NULL);
- if (ret == -1) {
- ret = -errno;
- printf("futex_lock_pi returned -1, errno is %d\n", ret);
+ if (setjmp(env)) {
+ printf("mutexint_lock canceled, aborting\n");
+ ret = -EINTR;
+ } else {
+ printf("\tcalling futex_lock_pi:\n");
+ printf("\top: 0x%x\n", FUTEX_LOCK_PI | FUTEX_PRIVATE | FUTEX_INTERRUPTIBLE);
+ printf("\t&lock_val: %p\n", &mutex->lock_val);
+ ret = futex_lock_pi(&mutex->lock_val, val, NULL);
+ if (ret == -1) {
+ ret = -errno;
+ printf("futex_lock_pi returned -1, errno is %d\n", ret);
+ }
}
/*
* If -EINTR is returned, the lock may no longer
--
1.6.0.4


--
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/