1 // Copyright 2018 The Amber Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "src/sleep.h" 16 17 #include "src/platform.h" 18 19 #if AMBER_PLATFORM_WINDOWS 20 #include <windows.h> 21 #elif AMBER_PLATFORM_POSIX 22 #include <unistd.h> 23 #else 24 #error "Unknown platform" 25 #endif 26 27 namespace amber { 28 USleep(uint32_t microseconds)29void USleep(uint32_t microseconds) { 30 #if AMBER_PLATFORM_WINDOWS 31 // The Windows call uses milliseconds. 32 Sleep(static_cast<DWORD>((microseconds + 999) / 1000)); 33 #elif AMBER_PLATFORM_POSIX 34 usleep(microseconds); 35 #else 36 #error "Implement amber::USleep" 37 #endif 38 } 39 40 } // namespace amber 41