summaryrefslogtreecommitdiff
path: root/usbredirparser
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2011-12-17 15:26:05 +0100
committerHans de Goede <hdegoede@redhat.com>2011-12-19 11:59:07 +0100
commitdb603a6909ce3523a620d4c85e6e335b5f0670d6 (patch)
tree5147c08b60480c5d272c8e48b7255dbf4310827a /usbredirparser
parente0c86c0c3b5ad0fa0e20c603360df0e458f0d622 (diff)
Allow specifying locking functions for multi-threading on open / create
Having separate set_locking_funcs functions causes the locking functions to be available potentially too late. And it just is not very pretty. This commit changes the API (in a way which is backward compat with 0.3.1), so that locking functions can be specified at creation time, just like all the other callbacks. This commit also bumps the reported version to 0.3.2, so that apps using libusbredirhost can check for this version to check the presence of the new usbredirhost_open_full function. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'usbredirparser')
-rw-r--r--usbredirparser/usbredirparser.c33
-rw-r--r--usbredirparser/usbredirparser.h12
2 files changed, 11 insertions, 34 deletions
diff --git a/usbredirparser/usbredirparser.c b/usbredirparser/usbredirparser.c
index ae731e0..7b2099f 100644
--- a/usbredirparser/usbredirparser.c
+++ b/usbredirparser/usbredirparser.c
@@ -30,13 +30,13 @@
#define LOCK(parser) \
do { \
if ((parser)->lock) \
- (parser)->lock_func((parser)->lock); \
+ (parser)->callb.lock_func((parser)->lock); \
} while (0)
#define UNLOCK(parser) \
do { \
if ((parser)->lock) \
- (parser)->unlock_func((parser)->lock); \
+ (parser)->callb.unlock_func((parser)->lock); \
} while (0)
struct usbredirparser_buf {
@@ -54,9 +54,6 @@ struct usbredirparser_priv {
uint32_t our_caps[USB_REDIR_CAPS_SIZE];
uint32_t peer_caps[USB_REDIR_CAPS_SIZE];
- usbredirparser_lock lock_func;
- usbredirparser_unlock unlock_func;
- usbredirparser_free_lock free_lock_func;
void *lock;
struct usb_redir_header header;
@@ -107,6 +104,9 @@ void usbredirparser_init(struct usbredirparser *parser_pub,
struct usb_redir_hello_header hello;
parser->flags = flags;
+ if (parser->callb.alloc_lock_func) {
+ parser->lock = parser->callb.alloc_lock_func();
+ }
snprintf(hello.version, sizeof(hello.version), "%s", version);
if (caps_len > USB_REDIR_CAPS_SIZE) {
@@ -133,32 +133,11 @@ void usbredirparser_destroy(struct usbredirparser *parser_pub)
}
if (parser->lock)
- parser->free_lock_func(parser->lock);
+ parser->callb.free_lock_func(parser->lock);
free(parser);
}
-int usbredirparser_set_locking_funcs(struct usbredirparser *parser_pub,
- usbredirparser_alloc_lock alloc_lock_func,
- usbredirparser_lock lock_func,
- usbredirparser_unlock unlock_func,
- usbredirparser_free_lock free_lock_func)
-{
- struct usbredirparser_priv *parser =
- (struct usbredirparser_priv *)parser_pub;
-
- parser->lock_func = lock_func;
- parser->unlock_func = unlock_func;
- parser->free_lock_func = free_lock_func;
-
- parser->lock = alloc_lock_func();
- if (!parser->lock) {
- ERROR("Out of memory allocating lock");
- return -1;
- }
- return 0;
-}
-
int usbredirparser_peer_has_cap(struct usbredirparser *parser_pub, int cap)
{
struct usbredirparser_priv *parser =
diff --git a/usbredirparser/usbredirparser.h b/usbredirparser/usbredirparser.h
index 6723edb..d1c47bb 100644
--- a/usbredirparser/usbredirparser.h
+++ b/usbredirparser/usbredirparser.h
@@ -156,6 +156,11 @@ struct usbredirparser {
usbredirparser_bulk_packet bulk_packet_func;
usbredirparser_iso_packet iso_packet_func;
usbredirparser_interrupt_packet interrupt_packet_func;
+ /* usbredir 0.3.2 new non packet callbacks (for multi-thread locking) */
+ usbredirparser_alloc_lock alloc_lock_func;
+ usbredirparser_lock lock_func;
+ usbredirparser_unlock unlock_func;
+ usbredirparser_free_lock free_lock_func;
};
/* Allocate a usbredirparser, after this the app should set the callback app
@@ -176,13 +181,6 @@ void usbredirparser_init(struct usbredirparser *parser,
void usbredirparser_destroy(struct usbredirparser *parser);
-/* See README.multi-thread */
-int usbredirparser_set_locking_funcs(struct usbredirparser *parser,
- usbredirparser_alloc_lock alloc_lock_func,
- usbredirparser_lock lock_func,
- usbredirparser_unlock unlock_func,
- usbredirparser_free_lock free_lock_func);
-
int usbredirparser_peer_has_cap(struct usbredirparser *parser, int cap);
/* Call this whenever there is data ready from the otherside to parse