sqlite3_usleep_windows.go (1253B)
1 // Copyright (C) 2018 G.J.R. Timmer <gjr.timmer@gmail.com>. 2 // 3 // Use of this source code is governed by an MIT-style 4 // license that can be found in the LICENSE file. 5 6 //go:build cgo 7 // +build cgo 8 9 package sqlite3 10 11 // usleep is a function available on *nix based systems. 12 // This function is not present in Windows. 13 // Windows has a sleep function but this works with seconds 14 // and not with microseconds as usleep. 15 // 16 // This code should improve performance on windows because 17 // without the presence of usleep SQLite waits 1 second. 18 // 19 // Source: https://github.com/php/php-src/blob/PHP-5.0/win32/time.c 20 // License: https://github.com/php/php-src/blob/PHP-5.0/LICENSE 21 // Details: 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 22 23 /* 24 #include <windows.h> 25 26 void usleep(__int64 usec) 27 { 28 HANDLE timer; 29 LARGE_INTEGER ft; 30 31 // Convert to 100 nanosecond interval, negative value indicates relative time 32 ft.QuadPart = -(10*usec); 33 34 timer = CreateWaitableTimer(NULL, TRUE, NULL); 35 SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); 36 WaitForSingleObject(timer, INFINITE); 37 CloseHandle(timer); 38 } 39 */ 40 import "C" 41 42 // EOF