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