From: Orin E. <ori...@gm...> - 2010-01-27 02:18:52
|
On Tue, Jan 26, 2010 at 5:29 PM, Michael Plante <mic...@gm...>wrote: > Yes, it presently uses a mutex. Like I said, that is not a difficult > problem. The only issue with the default context is making sure that mutex > only gets overwritten once, and this can be done with an > InterlockedCompareExchange() (are HANDLE's 32 or 64-bits in 64-bit > Windows? If 64, it might need to be > InterlockedCompareExchangePointer().). Or, if it's done via static > initialization, that it get torn down, and that we check for errors during > init. > > HANDLES are "void *"s in theory in both 32 and 64 bit, but since Windows supports both 32 and 64 bit apps, I believe that 64bit handles are sign extended 32bit values. InterlockedCompareExchangePointer() would be one way to go for init... though you do have to make sure the operands are 64bit aligned. How would you handle the libusb_exit code as the last instance should free the mutex? Static initialization is problematic as you might not know what order such initializations are done in. I could have a static C++ object that uses libusb - when will its constructor be called relative to any other static initialization? So the code I gave Pete punted the problem to the OS with a named semaphore (could have been a named mutex, but six of one...). > The condition variable is difficult. I was merely trying to be complete > by listing the others. > > I haven't looked at that yet... Orin. |