sqlite3_usleep_windows.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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://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
  16. /*
  17. #include <windows.h>
  18. void usleep(__int64 usec)
  19. {
  20. HANDLE timer;
  21. LARGE_INTEGER ft;
  22. // Convert to 100 nanosecond interval, negative value indicates relative time
  23. ft.QuadPart = -(10*usec);
  24. timer = CreateWaitableTimer(NULL, TRUE, NULL);
  25. SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
  26. WaitForSingleObject(timer, INFINITE);
  27. CloseHandle(timer);
  28. }
  29. */
  30. import "C"
  31. // EOF