sqlite3_usleep_windows.go 1.2 KB

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