• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #ifndef ANDROID_AUDIO_CLOCK_NANOSLEEP_H
18 #define ANDROID_AUDIO_CLOCK_NANOSLEEP_H
19 
20 #include <time.h>
21 #include <unistd.h>
22 
23 #ifdef __linux__
24 
25 #include <sys/syscall.h>
26 #ifdef __ANDROID__
27 // bionic for Android provides clock_nanosleep
28 #define audio_utils_clock_nanosleep clock_nanosleep
29 #else
30 // bionic for desktop Linux omits clock_nanosleep
31 static inline
audio_utils_clock_nanosleep(clockid_t clock_id,int flags,const struct timespec * request,struct timespec * remain)32 int audio_utils_clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *request,
33         struct timespec *remain)
34 {
35     return syscall(SYS_clock_nanosleep, clock_id, flags, request, remain);
36 }
37 #endif  // __ANDROID__
38 
39 #else   // __linux__
40 
41 // macOS <10.12 doesn't have clockid_t / CLOCK_MONOTONIC
42 #ifndef CLOCK_MONOTONIC
43 typedef int clockid_t;
44 #define CLOCK_MONOTONIC 0
45 #endif
46 // macOS doesn't have clock_nanosleep
47 static inline
audio_utils_clock_nanosleep(clockid_t clock_id,int flags,const struct timespec * request,struct timespec * remain)48 int audio_utils_clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *request,
49         struct timespec *remain)
50 {
51     (void) clock_id;
52     (void) flags;
53     (void) request;
54     (void) remain;
55     errno = ENOSYS;
56     return -1;
57 }
58 
59 #endif  // __linux__
60 
61 #endif  // !ANDROID_AUDIO_CLOCK_NANOSLEEP_H
62