summaryrefslogtreecommitdiff
path: root/libusb/libusbi.h
diff options
context:
space:
mode:
authorDaniel Drake <dsd@gentoo.org>2009-10-28 15:13:22 +0545
committerDaniel Drake <dsd@gentoo.org>2009-11-06 21:45:37 +0000
commit69830057547396f893f0d7b3125a05d016313b10 (patch)
treed82ac7414926f4439a3216c1f060156cb9a62c38 /libusb/libusbi.h
parent98f1b30d24359cb3185051b8df9ebb663cc10369 (diff)
downloadlibusb-69830057547396f893f0d7b3125a05d016313b10.tar.gz
Transfer locking
At least on Linux, there were some possible races that could occur if a transfer is cancelled from one thread while another thread is handling an event for that transfer, or for if a transfer completes while it is still being submitted from another thread, etc. On the global level, transfers could be submitted and cancelled at the same time. Fix those issues with transfer-level locks.
Diffstat (limited to 'libusb/libusbi.h')
-rw-r--r--libusb/libusbi.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 9813c4d..6e9e2e0 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -242,6 +242,15 @@ struct usbi_transfer {
struct timeval timeout;
int transferred;
uint8_t flags;
+
+ /* this lock is held during libusb_submit_transfer() and
+ * libusb_cancel_transfer() (allowing the OS backend to prevent duplicate
+ * cancellation, submission-during-cancellation, etc). the OS backend
+ * should also take this lock in the handle_events path, to prevent the user
+ * cancelling the transfer from another thread while you are processing
+ * its completion (presumably there would be races within your OS backend
+ * if this were possible). */
+ pthread_mutex_t lock;
};
#define __USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer) \
@@ -733,6 +742,10 @@ struct usbi_os_backend {
* This function should also be able to detect disconnection of the
* device, reporting that situation with usbi_handle_disconnect().
*
+ * When processing an event related to a transfer, you probably want to
+ * take usbi_transfer.lock to prevent races. See the documentation for
+ * the usbi_transfer structure.
+ *
* Return 0 on success, or a LIBUSB_ERROR code on failure.
*/
int (*handle_events)(struct libusb_context *ctx,