Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / libfreerdp-utils / sleep.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * Sleep Utils
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <freerdp/utils/sleep.h>
21
22 #include <time.h>
23
24 #ifndef _WIN32
25 #define _XOPEN_SOURCE 500
26 #include <unistd.h>
27 #else
28 #include <windows.h>
29 #endif
30
31 void freerdp_sleep(uint32 seconds)
32 {
33 #ifndef _WIN32
34         sleep(seconds);
35 #else
36         Sleep(seconds * 1000);
37 #endif
38 }
39
40 void freerdp_usleep(uint32 useconds)
41 {
42 #ifndef _WIN32
43         usleep(useconds);
44 #else
45         uint64 t1;
46         uint64 t2;
47         uint64 freq;
48
49         QueryPerformanceCounter((LARGE_INTEGER*) &t1);
50         QueryPerformanceCounter((LARGE_INTEGER*) &freq);
51
52         do
53         {
54                 QueryPerformanceCounter((LARGE_INTEGER*) &t2);
55         }
56         while ((t2 - t1) < useconds);
57 #endif
58 }