snapscan-mutex.c: Use hash instead of parsing the device string.

merge-requests/1/head
Oliver Schwartz 2010-01-28 21:52:20 +01:00
rodzic 8177af4168
commit 13cded1269
2 zmienionych plików z 24 dodań i 20 usunięć

Wyświetl plik

@ -1,3 +1,8 @@
2010-01-28 Oliver Schwartz <oliverschwartz at users.sourceforge.net>
* backend/snapscan-usb.c: Use hash of device string instead of parsing
it to create a semaphore id. The new code is less platform dependent
and should also work on FreeBSD 8.0.
2010-01-27 Stéphane Voltz <stef.dev at free.fr>
* backend/genesys.c backend/genesys.h backend/genesys_conv.c
backend/genesys_low.h backend/genesys_gl841.c: add dynamic lineart

Wyświetl plik

@ -97,6 +97,8 @@ static void snapscani_mutex_unlock(snapscan_mutex_t* sem_id)
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/types.h>
#include <unistd.h>
#define snapscan_mutex_t int
@ -116,32 +118,29 @@ union semun {
static struct sembuf sem_wait = { 0, -1, 0 };
static struct sembuf sem_signal = { 0, 1, 0 };
static unsigned int snapscani_bernstein(const unsigned char* str)
{
unsigned int hash = 5381; /* some arbitrary number */
int c;
while (*str)
{
c = *str++;
hash = ((hash << 5) + hash) + c;
}
return hash;
}
static int snapscani_mutex_open(snapscan_mutex_t* sem_id, const char* dev)
{
static const char *me = "snapscani_mutex_open";
key_t ipc_key;
int pid, devnum, busnum;
key_t ipc_key = -1;
if (strstr(dev, "libusb:") == dev)
{
if (sanei_usb_get_vendor_product_byname(dev, NULL, &pid) != SANE_STATUS_GOOD)
{
DBG (DL_MAJOR_ERROR, "%s: could not obtain USB product ID for device %s\n", me, dev);
return 0;
}
if (sscanf(dev, "libusb:%d:%d", &busnum, &devnum) != 2)
{
DBG (DL_MAJOR_ERROR, "%s: could not parse device string: %s\n", me, strerror(errno));
return 0;
}
ipc_key = pid << 16;
ipc_key |= (busnum & 0xff) << 8;
ipc_key |= (devnum & 0xff);
DBG (DL_INFO, "%s: using IPC key 0x%08x for device %s (pid 0x%04x, bus 0x%02x, dev 0x%02x)\n",
me, ipc_key, dev, pid, busnum, devnum);
key_t ipc_key = (key_t) snapscani_bernstein((const unsigned char*) dev+7);
DBG (DL_INFO, "%s: using IPC key 0x%08x for device %s\n",
me, ipc_key, dev);
}
else
{