5

I need functionality of do_futex() call in user space outside of lock/unlock context. I.e., I do not need a mutex, but the exact semantics of the kernel call do_futex.

It would seem it should be available in user space, since the intent was to minimize the number of system calls, but I can't link with it.

Or is there a syscall?

Update:

I'm currently using syscall(__NR_futex, ...) to run do_futex(). But

  1. I have to include to get __NR_futex, which is ugly
  2. I have to include to get FUTEX_WAIT and FUTEX_WAKE, but I still don't get EWOULDBLOCK, or the maximum number of threads for WAKE

Is there a coherent wrapper?

n-alexander
  • 14,663
  • 12
  • 42
  • 43
  • 1
    What exactly do you think the semantics are? When you refer to `do_futex` are you referring to the actual `do_futex` routine in the kernel that is indirectly called by the `futex` system call? `man futex` – Noah Watkins Aug 31 '10 at 13:45
  • 1
    how do I get the futex system call? I'm doing a syscall(__NR_futex, ...), but this is ugly, and I don't get the futext defines to pass in or compare against. And I have to include to get __NR_futex. I can include as man suggests, but that defines the kernel call rather than user space call. And it still does not define some of the constants. Is there a consistent wrapper/header? – n-alexander Aug 31 '10 at 15:42
  • `sys/syscall.h`, not `asm/unistd.h`, is the proper header for accessing system calls from userspace. `linux/*` and `asm/*` includes do not belong in userspace apps. – R.. GitHub STOP HELPING ICE Feb 16 '12 at 02:36

2 Answers2

2

As it's said on http://locklessinc.com/articles/obscure_synch/:

Finally, in order to block on a kernel wait-list, we need to use the Futex system call, which unfortunately isn't exposed by linux/futex.h.

And they define their own simple wrapper:

#include <linux/futex.h>
#include <sys/syscall.h>

static long sys_futex(void *addr1, int op, int val1, struct timespec *timeout,
                      void *addr2, int val3) {
    return syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
}
abyss.7
  • 13,882
  • 11
  • 56
  • 100
1

futex(2) system call is probably what you are looking for.

man 2 futex

Also, on side note, man syscalls gives list of all system calls.

Rumple Stiltskin
  • 9,597
  • 1
  • 20
  • 25