summaryrefslogtreecommitdiff
path: root/libusb/os/events_windows.c
Commit message (Collapse)AuthorAgeFilesLines
* core: Split usbi_clock_gettime() into two separate functionsChris Dickens2020-09-131-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Most of the library only uses the monotonic clock. In fact, the only use of the realtime clock is to implement the POSIX version of usbi_cond_timedwait(). Now that Windows can no longer use the POSIX thread abstraction, there is no need for Windows to implement a means of reading the realtime clock. This change replaces usbi_clock_gettime() with usbi_get_monotonic_time() and usbi_get_real_time(). When clock_gettime() is available, both functions are implemented as simple inline calls, otherwise the backend must provide a definition for usbi_get_monotonic_time() *AND* usbi_get_real_time() iff the platform is POSIX. Reading the clocks is also never expected to fail. In practice, if it ever did there would be much more than libusb that would not function correctly. The new functions therefore have no return value, thus allowing the callers to assume success and remove a bunch of error handling code. The clock_gettime() wrappers have a simple error check that is only enforced in debug builds. This change also makes it unnecessary to check for and use clock_gettime() on Windows, so remove it and always provide usbi_get_monotonic_time(). Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* core: Introduce platform events abstractionChris Dickens2020-08-121-0/+219
The way in which system handles or resources are represented differs greatly between Unix-like operating systems and Windows. Ever since Windows support was added to libusb, Windows been emulating principles of Unix-like operating systems such as file descriptors and poll(). This commit introduces an abstraction layer that completely removes the need to perform any emulation. Fundamentally there are three things that each platform provides to libusb: 1) A signallable event 2) A timer (not required, but useful) 3) A means to wait for event sources such as the above to be triggered The POSIX abstraction for Unix-like operating systems uses file descriptors as the "handles" to the underlying system resources. The signallable event is implemented using a pipe, the timer as a timerfd (where supported) and the poll() system call is used to wait for events. The Windows abstraction uses native HANDLEs as the "handles" to the underlying system resources. The signallable event is implemented using a manual-reset event, the timer as a manual-reset waitable timer, and the WaitForMultipleObjects() system call is used to wait for events. Closes #252 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>