sqlite3_usleep_windows.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. //go:build cgo
  6. // +build cgo
  7. package sqlite3
  8. // usleep is a function available on *nix based systems.
  9. // This function is not present in Windows.
  10. // Windows has a sleep function but this works with seconds
  11. // and not with microseconds as usleep.
  12. //
  13. // This code should improve performance on windows because
  14. // without the presence of usleep SQLite waits 1 second.
  15. //
  16. // Source: https://github.com/php/php-src/blob/PHP-5.0/win32/time.c
  17. // License: https://github.com/php/php-src/blob/PHP-5.0/LICENSE
  18. // 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
  19. /*
  20. #include <windows.h>
  21. void usleep(__int64 usec)
  22. {
  23. HANDLE timer;
  24. LARGE_INTEGER ft;
  25. // Convert to 100 nanosecond interval, negative value indicates relative time
  26. ft.QuadPart = -(10*usec);
  27. timer = CreateWaitableTimer(NULL, TRUE, NULL);
  28. SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
  29. WaitForSingleObject(timer, INFINITE);
  30. CloseHandle(timer);
  31. }
  32. */
  33. import "C"
  34. // EOF