Skip to content

Commit 7c89b38

Browse files
committed
Implementation for usleep
Implement `usleep` for Windows OS.
1 parent edb95b5 commit 7c89b38

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

sqlite3_opt_usleep.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

sqlite3_usleep_windows.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// +build cgo
2+
3+
// Copyright (C) 2018 G.J.R. Timmer <[email protected]>.
4+
//
5+
// Use of this source code is governed by an MIT-style
6+
// license that can be found in the LICENSE file.
7+
8+
package sqlite3
9+
10+
// usleep is a function available on *nix based systems.
11+
// This function is not present in Windows.
12+
// Windows has a sleep function but this works with seconds
13+
// and not with microseconds as usleep.
14+
//
15+
// This code should improve performance on windows because
16+
// without the presence of usleep SQLite waits 1 second.
17+
//
18+
// Source: https://stackoverflow.com/questions/5801813/c-usleep-is-obsolete-workarounds-for-windows-mingw?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
19+
20+
/*
21+
#include <windows.h>
22+
23+
void usleep(__int64 usec)
24+
{
25+
HANDLE timer;
26+
LARGE_INTEGER ft;
27+
28+
// Convert to 100 nanosecond interval, negative value indicates relative time
29+
ft.QuadPart = -(10*usec);
30+
31+
timer = CreateWaitableTimer(NULL, TRUE, NULL);
32+
SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
33+
WaitForSingleObject(timer, INFINITE);
34+
CloseHandle(timer);
35+
}
36+
*/
37+
import "C"
38+
39+
// EOF

0 commit comments

Comments
 (0)