core: Introduce atomic type and operations
authorChris Dickens <christopher.a.dickens@gmail.com>
Wed, 16 Dec 2020 18:35:45 +0000 (10:35 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Wed, 16 Dec 2020 18:35:45 +0000 (10:35 -0800)
commit1a08aa84d96397a3840a75abe66051f5360c2c84
treeb079a8f43ad2d61c36b7af8d7ae3d86ffee8fe74
parentf6d2cb561402c3b6d3627c0eb89e009b503d9067
core: Introduce atomic type and operations

An atomic variable is useful for reference counting and is much less
overhead than accessing such a variable while holding a lock. To that
end, replace the libusb_device 'refcnt' variable with an atomic and use
the atomic operations to manipulate it. This removes the need for the
mutex in the libusb_device.

Also convert the 'attached' variable to an atomic as well. This variable
was previously accessed both while holding the libusb_device mutex and
not.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/core.c
libusb/libusbi.h
libusb/os/linux_usbfs.c
libusb/version_nano.h