2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 * Work around the lack of <sys/eventfd.h> on glibc 2.5.1 which we still
21 * need to support, sigh.
28 // <sys/eventfd.h> doesn't exist on older glibc versions
29 #if (defined(__GLIBC__) && __GLIBC_PREREQ(2, 9))
30 #include <sys/eventfd.h>
31 #else /* !(defined(__GLIBC__) && __GLIBC_PREREQ(2, 9)) */
33 #include <sys/syscall.h>
37 // Use existing __NR_eventfd2 if already defined
38 // Values from the Linux kernel source:
39 // arch/x86/include/asm/unistd_{32,64}.h
41 #if defined(__x86_64__)
42 #define __NR_eventfd2 290
43 #elif defined(__i386__)
44 #define __NR_eventfd2 328
46 #error "Can't define __NR_eventfd2 for your architecture."
53 #define EFD_SEMAPHORE EFD_SEMAPHORE
54 EFD_CLOEXEC = 02000000,
55 #define EFD_CLOEXEC EFD_CLOEXEC
57 #define EFD_NONBLOCK EFD_NONBLOCK
60 // http://www.kernel.org/doc/man-pages/online/pages/man2/eventfd.2.html
61 // Use the eventfd2 system call, as in glibc 2.9+
62 // (requires kernel 2.6.30+)
63 #define eventfd(initval, flags) syscall(__NR_eventfd2,(initval),(flags))
65 #endif /* !(defined(__GLIBC__) && __GLIBC_PREREQ(2, 9)) */