summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Plante <michael.plante@gmail.com>2010-01-22 19:58:40 -0600
committerPete Batard <pbatard@gmail.com>2010-01-23 22:16:35 +0000
commit6b34ff4ed72e3c52b4c927946b4fb0a233c24044 (patch)
tree8b2d750c11ae7c816c0c6522cc80599f9b572d75
parentc7fa44ff83cba5d58c058510fced820fab906332 (diff)
downloadlibusb-6b34ff4ed72e3c52b4c927946b4fb0a233c24044.tar.gz
r104: thread safety change for pipe_number global
Signed-off-by: Michael Plante <michael.plante@gmail.com>
-rw-r--r--libusb/os/windows_compat.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/libusb/os/windows_compat.c b/libusb/os/windows_compat.c
index a7f68d2..677d2ba 100644
--- a/libusb/os/windows_compat.c
+++ b/libusb/os/windows_compat.c
@@ -132,7 +132,7 @@ struct {
// globals
BOOLEAN is_polling_set = FALSE;
-unsigned short pipe_number = 0;
+LONG pipe_number = 0;
// Init
void init_polling(void)
@@ -270,6 +270,7 @@ int pipe_for_poll(int filedes[2])
HANDLE handle[2];
OVERLAPPED *overlapped0, *overlapped1;
char pipe_name[] = "\\\\.\\pipe\\libusb000000000000";
+ LONG our_pipe_number;
CHECK_INIT_POLLING;
@@ -284,7 +285,9 @@ int pipe_for_poll(int filedes[2])
return -1;
}
- _snprintf(pipe_name, sizeof(pipe_name), "\\\\.\\pipe\\libusb%08x%04x", (unsigned)GetCurrentProcessId(), pipe_number++);
+ our_pipe_number = InterlockedIncrement(&pipe_number) - 1; // - 1 to mirror postfix operation inside _snprintf
+ our_pipe_number &= 0xFFFF; // Could warn if this was necessary (ToDo)
+ _snprintf(pipe_name, sizeof(pipe_name), "\\\\.\\pipe\\libusb%08x%04x", (unsigned)GetCurrentProcessId(), our_pipe_number);
// Read end of the pipe
handle[0] = CreateNamedPipeA(pipe_name, PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED,