2 * Copyright 2014 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Work around the lack of <sys/eventfd.h> on glibc 2.5.1 which we still
19 * need to support, sigh.
26 // <sys/eventfd.h> doesn't exist on older glibc versions
27 #if (defined(__GLIBC__) && __GLIBC_PREREQ(2, 9))
28 #include <sys/eventfd.h>
29 #else /* !(defined(__GLIBC__) && __GLIBC_PREREQ(2, 9)) */
31 #include <sys/syscall.h>
35 // Use existing __NR_eventfd2 if already defined
36 // Values from the Linux kernel source:
37 // arch/x86/include/asm/unistd_{32,64}.h
40 #define __NR_eventfd2 290
41 #elif defined(__i386__)
42 #define __NR_eventfd2 328
44 #error "Can't define __NR_eventfd2 for your architecture."
51 #define EFD_SEMAPHORE EFD_SEMAPHORE
52 EFD_CLOEXEC = 02000000,
53 #define EFD_CLOEXEC EFD_CLOEXEC
55 #define EFD_NONBLOCK EFD_NONBLOCK
58 // http://www.kernel.org/doc/man-pages/online/pages/man2/eventfd.2.html
59 // Use the eventfd2 system call, as in glibc 2.9+
60 // (requires kernel 2.6.30+)
61 #define eventfd(initval, flags) syscall(__NR_eventfd2,(initval),(flags))
63 #endif /* !(defined(__GLIBC__) && __GLIBC_PREREQ(2, 9)) */