bionic_futex.h revision d5ed63a6a8290de88802172ce178656fbafe70c6
16304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner/* 26304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * Copyright (C) 2008 The Android Open Source Project 36304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * All rights reserved. 46304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * 56304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * Redistribution and use in source and binary forms, with or without 66304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * modification, are permitted provided that the following conditions 76304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * are met: 86304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * * Redistributions of source code must retain the above copyright 96304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * notice, this list of conditions and the following disclaimer. 106304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * * Redistributions in binary form must reproduce the above copyright 116304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * notice, this list of conditions and the following disclaimer in 126304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * the documentation and/or other materials provided with the 136304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * distribution. 146304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * 156304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 166304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 176304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 186304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 196304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 206304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 216304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 226304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 236304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 246304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 256304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 266304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner * SUCH DAMAGE. 276304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner */ 286304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner#ifndef _BIONIC_FUTEX_H 296304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner#define _BIONIC_FUTEX_H 306304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner 316304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner#include <linux/futex.h> 3236fa67bcdd90f18a3c68f8637ae836762407fa51Elliott Hughes#include <sys/cdefs.h> 33d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes#include <stdbool.h> 34d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes#include <stddef.h> 356304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner 363e898476c7230b60a0f76968e64ff25f475b48c0Elliott Hughes__BEGIN_DECLS 373e898476c7230b60a0f76968e64ff25f475b48c0Elliott Hughes 38d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughesstruct timespec; 396304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner 40d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughesextern int __futex_syscall4(volatile void* ftx, int op, int value, const struct timespec* timeout); 416304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner 42d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughesstatic inline int __futex_wake(volatile void* ftx, int count) { 43d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes return __futex_syscall4(ftx, FUTEX_WAKE, count, NULL); 44d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes} 45d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes 46d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughesstatic inline int __futex_wake_ex(volatile void* ftx, bool shared, int count) { 47d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes return __futex_syscall4(ftx, shared ? FUTEX_WAKE : FUTEX_WAKE_PRIVATE, count, NULL); 48d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes} 49d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes 50d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughesstatic inline int __futex_wait(volatile void* ftx, int value, const struct timespec* timeout) { 51d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes return __futex_syscall4(ftx, FUTEX_WAIT, value, timeout); 52d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes} 53d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes 54d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughesstatic inline int __futex_wait_ex(volatile void* ftx, bool shared, int value, const struct timespec* timeout) { 55d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes return __futex_syscall4(ftx, shared ? FUTEX_WAIT : FUTEX_WAIT_PRIVATE, value, timeout); 56d5ed63a6a8290de88802172ce178656fbafe70c6Elliott Hughes} 576304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner 583e898476c7230b60a0f76968e64ff25f475b48c0Elliott Hughes__END_DECLS 593e898476c7230b60a0f76968e64ff25f475b48c0Elliott Hughes 606304d8b21891fd0cb7b5a4c25159a3d3b1709d62David 'Digit' Turner#endif /* _BIONIC_FUTEX_H */ 61