examples: make dpfp_threaded work on OS X
OS X does not support unnamed semaphores so the example has been updated to use a named semaphore instead. Signed-off-by: Nathan Hjelm <hjelmn@me.com>
This commit is contained in:
parent
bcac08d60f
commit
7dff2d35ca
2 changed files with 11 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* libusb example program to manipulate U.are.U 4000B fingerprint scanner.
|
* libusb example program to manipulate U.are.U 4000B fingerprint scanner.
|
||||||
* Copyright © 2007 Daniel Drake <dsd@gentoo.org>
|
* Copyright © 2007 Daniel Drake <dsd@gentoo.org>
|
||||||
|
* Copyright © 2016 Nathan Hjelm <hjelmn@mac.com>
|
||||||
*
|
*
|
||||||
* Basic image capture program only, does not consider the powerup quirks or
|
* Basic image capture program only, does not consider the powerup quirks or
|
||||||
* the fact that image encryption may be enabled. Not expected to work
|
* the fact that image encryption may be enabled. Not expected to work
|
||||||
|
@ -37,6 +38,7 @@
|
||||||
#define CTRL_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT)
|
#define CTRL_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT)
|
||||||
#define USB_RQ 0x04
|
#define USB_RQ 0x04
|
||||||
#define INTR_LENGTH 64
|
#define INTR_LENGTH 64
|
||||||
|
#define SEM_NAME "/org.libusb.example.dpfp_threaded"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MODE_INIT = 0x00,
|
MODE_INIT = 0x00,
|
||||||
|
@ -68,12 +70,12 @@ static int img_idx = 0;
|
||||||
static volatile sig_atomic_t do_exit = 0;
|
static volatile sig_atomic_t do_exit = 0;
|
||||||
|
|
||||||
static pthread_t poll_thread;
|
static pthread_t poll_thread;
|
||||||
static sem_t exit_sem;
|
static sem_t *exit_sem;
|
||||||
|
|
||||||
static void request_exit(sig_atomic_t code)
|
static void request_exit(sig_atomic_t code)
|
||||||
{
|
{
|
||||||
do_exit = code;
|
do_exit = code;
|
||||||
sem_post(&exit_sem);
|
sem_post(exit_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *poll_thread_main(void *arg)
|
static void *poll_thread_main(void *arg)
|
||||||
|
@ -446,16 +448,18 @@ int main(void)
|
||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
int r = 1;
|
int r = 1;
|
||||||
|
|
||||||
r = sem_init(&exit_sem, 0, 0);
|
exit_sem = sem_open (SEM_NAME, O_CREAT, 0);
|
||||||
if (r) {
|
if (!exit_sem) {
|
||||||
fprintf(stderr, "failed to initialise semaphore error %d", errno);
|
fprintf(stderr, "failed to initialise semaphore error %d", errno);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* only using this semaphore in this process so go ahead and unlink it now */
|
||||||
|
sem_unlink (SEM_NAME);
|
||||||
|
|
||||||
r = libusb_init(NULL);
|
r = libusb_init(NULL);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
fprintf(stderr, "failed to initialise libusb\n");
|
fprintf(stderr, "failed to initialise libusb\n");
|
||||||
sem_destroy(&exit_sem);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,7 +512,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!do_exit)
|
while (!do_exit)
|
||||||
sem_wait(&exit_sem);
|
sem_wait(exit_sem);
|
||||||
|
|
||||||
printf("shutting down...\n");
|
printf("shutting down...\n");
|
||||||
pthread_join(poll_thread, NULL);
|
pthread_join(poll_thread, NULL);
|
||||||
|
@ -544,6 +548,5 @@ out_release:
|
||||||
out:
|
out:
|
||||||
libusb_close(devh);
|
libusb_close(devh);
|
||||||
libusb_exit(NULL);
|
libusb_exit(NULL);
|
||||||
sem_destroy(&exit_sem);
|
|
||||||
return r >= 0 ? r : -r;
|
return r >= 0 ? r : -r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
#define LIBUSB_NANO 11117
|
#define LIBUSB_NANO 11116
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue