2 * Copyright 2017 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.
24 #ifndef FOLLY_NO_CONFIG
25 #include <folly/folly-config.h>
28 #ifdef FOLLY_HAVE_FEATURES_H
29 # include <features.h>
32 #if defined(__GLIBC__) && !defined(__APPLE__)
33 #if __GLIBC_PREREQ(2, 9)
34 # define FOLLY_GLIBC_2_9
38 // <sys/eventfd.h> doesn't exist on older glibc versions
39 #ifdef FOLLY_GLIBC_2_9
40 #include <sys/eventfd.h>
41 #else /* !def FOLLY_GLIBC_2_9 */
43 #include <sys/syscall.h>
47 // Use existing __NR_eventfd2 if already defined
48 // Values from the Linux kernel source:
49 // arch/x86/include/asm/unistd_{32,64}.h
53 #define __NR_eventfd2 290
54 #elif defined(__i386__)
56 #define __NR_eventfd2 328
58 #error "Can't define __NR_eventfd2 for your architecture."
65 #define EFD_SEMAPHORE EFD_SEMAPHORE
66 EFD_CLOEXEC = 02000000,
67 #define EFD_CLOEXEC EFD_CLOEXEC
69 #define EFD_NONBLOCK EFD_NONBLOCK
72 // http://www.kernel.org/doc/man-pages/online/pages/man2/eventfd.2.html
73 // Use the eventfd2 system call, as in glibc 2.9+
74 // (requires kernel 2.6.30+)
75 #define eventfd(initval, flags) syscall(__NR_eventfd2,(initval),(flags))
77 #endif /* !(defined(__GLIBC__) && __GLIBC_PREREQ(2, 9)) */