Skip to content

Commit

Permalink
Directly use pthread_mutex_* fucntions instead of using wrappers
Browse files Browse the repository at this point in the history
Remove thread_unix.c and thread_generic.h now useless


git-svn-id: svn:https://anonscm.debian.org/svn/pcsclite/trunk/PCSC@4885 0ce88b0d-b2fd-0310-8134-9614164e65ea
  • Loading branch information
LudovicRousseau committed Apr 18, 2010
1 parent 0f24230 commit 8e1f794
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 264 deletions.
3 changes: 0 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ libpcsclite_la_SOURCES = \
strlcat.c \
strlcpy.c \
sys_unix.c \
thread_unix.c \
utils.c \
winscard_msg.c
libpcsclite_la_LDFLAGS = -version-info 1:0:0
Expand Down Expand Up @@ -68,8 +67,6 @@ pcscd_SOURCES = \
strlcpycat.h \
sys_generic.h \
sys_unix.c \
thread_generic.h \
thread_unix.c \
tokenparser.l \
utils.c \
utils.h \
Expand Down
18 changes: 9 additions & 9 deletions src/eventhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>

#include "misc.h"
#include "pcscd.h"
#include "ifdhandler.h"
#include "debuglog.h"
#include "thread_generic.h"
#include "readerfactory.h"
#include "eventhandler.h"
#include "dyn_generic.h"
Expand All @@ -41,17 +41,17 @@

READER_STATE readerStates[PCSCLITE_MAX_READERS_CONTEXTS];
static list_t ClientsWaitingForEvent; /**< list of client file descriptors */
PCSCLITE_MUTEX ClientsWaitingForEvent_lock; /**< lock for the above list */
pthread_mutex_t ClientsWaitingForEvent_lock; /**< lock for the above list */

static void EHStatusHandlerThread(READER_CONTEXT *);

LONG EHRegisterClientForEvent(int32_t filedes)
{
(void)SYS_MutexLock(&ClientsWaitingForEvent_lock);
(void)pthread_mutex_lock(&ClientsWaitingForEvent_lock);

(void)list_append(&ClientsWaitingForEvent, &filedes);

(void)SYS_MutexUnLock(&ClientsWaitingForEvent_lock);
(void)pthread_mutex_unlock(&ClientsWaitingForEvent_lock);

return SCARD_S_SUCCESS;
} /* EHRegisterClientForEvent */
Expand All @@ -65,11 +65,11 @@ LONG EHTryToUnregisterClientForEvent(int32_t filedes)
LONG rv = SCARD_S_SUCCESS;
int ret;

(void)SYS_MutexLock(&ClientsWaitingForEvent_lock);
(void)pthread_mutex_lock(&ClientsWaitingForEvent_lock);

ret = list_delete(&ClientsWaitingForEvent, &filedes);

(void)SYS_MutexUnLock(&ClientsWaitingForEvent_lock);
(void)pthread_mutex_unlock(&ClientsWaitingForEvent_lock);

if (ret < 0)
rv = SCARD_F_INTERNAL_ERROR;
Expand Down Expand Up @@ -98,7 +98,7 @@ LONG EHSignalEventToClients(void)
LONG rv = SCARD_S_SUCCESS;
int32_t filedes;

(void)SYS_MutexLock(&ClientsWaitingForEvent_lock);
(void)pthread_mutex_lock(&ClientsWaitingForEvent_lock);

(void)list_iterator_start(&ClientsWaitingForEvent);
while (list_iterator_hasnext(&ClientsWaitingForEvent))
Expand All @@ -110,7 +110,7 @@ LONG EHSignalEventToClients(void)

(void)list_clear(&ClientsWaitingForEvent);

(void)SYS_MutexUnLock(&ClientsWaitingForEvent_lock);
(void)pthread_mutex_unlock(&ClientsWaitingForEvent_lock);

return rv;
} /* EHSignalEventToClients */
Expand Down Expand Up @@ -139,7 +139,7 @@ LONG EHInitializeEventStructures(void)
/* setting the comparator, so the list can sort, find the min, max etc */
(void)list_attributes_comparator(&ClientsWaitingForEvent, list_comparator_int32_t);

(void)SYS_MutexInit(&ClientsWaitingForEvent_lock);
(void)pthread_mutex_init(&ClientsWaitingForEvent_lock, NULL);

return SCARD_S_SUCCESS;
}
Expand Down
16 changes: 8 additions & 8 deletions src/hotplug_libhal.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <dirent.h>
#include <stdlib.h>
#include <libhal.h>
#include <pthread.h>

#include "misc.h"
#include "wintypes.h"
Expand All @@ -29,7 +30,6 @@
#include "readerfactory.h"
#include "sys_generic.h"
#include "hotplug.h"
#include "thread_generic.h"
#include "utils.h"
#include "strlcpycat.h"

Expand All @@ -42,7 +42,7 @@

#define UDI_BASE "/org/freedesktop/Hal/devices/"

PCSCLITE_MUTEX usbNotifierMutex;
pthread_mutex_t usbNotifierMutex;

static pthread_t usbNotifyThread;
static int driverSize = -1;
Expand Down Expand Up @@ -374,7 +374,7 @@ static void HPAddDevice(LibHalContext *ctx, const char *udi)
/* wait until the device is visible by libusb/etc. */
(void)SYS_Sleep(1);

(void)SYS_MutexLock(&usbNotifierMutex);
(void)pthread_mutex_lock(&usbNotifierMutex);

/* find a free entry */
for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++)
Expand All @@ -387,7 +387,7 @@ static void HPAddDevice(LibHalContext *ctx, const char *udi)
{
Log2(PCSC_LOG_ERROR,
"Not enough reader entries. Already found %d readers", i);
(void)SYS_MutexUnLock(&usbNotifierMutex);
(void)pthread_mutex_unlock(&usbNotifierMutex);
return;
}

Expand Down Expand Up @@ -479,7 +479,7 @@ static void HPAddDevice(LibHalContext *ctx, const char *udi)
}
}

(void)SYS_MutexUnLock(&usbNotifierMutex);
(void)pthread_mutex_unlock(&usbNotifierMutex);
} /* HPAddDevice */


Expand All @@ -503,15 +503,15 @@ static void HPRemoveDevice(/*@unused@*/ LibHalContext *ctx, const char *udi)
Log3(PCSC_LOG_INFO, "Removing USB device[%d]: %s", i,
short_name(readerTracker[i].udi));

(void)SYS_MutexLock(&usbNotifierMutex);
(void)pthread_mutex_lock(&usbNotifierMutex);

(void)RFRemoveReader(readerTracker[i].fullName, PCSCLITE_HP_BASE_PORT + i);
free(readerTracker[i].fullName);
readerTracker[i].fullName = NULL;
free(readerTracker[i].udi);
readerTracker[i].udi = NULL;

(void)SYS_MutexUnLock(&usbNotifierMutex);
(void)pthread_mutex_unlock(&usbNotifierMutex);

return;
} /* HPRemoveDevice */
Expand All @@ -526,7 +526,7 @@ ULONG HPRegisterForHotplugEvents(void)
int i, num_devices;
DBusError error;

(void)SYS_MutexInit(&usbNotifierMutex);
(void)pthread_mutex_init(&usbNotifierMutex, NULL);

if (driverSize <= 0)
{
Expand Down
15 changes: 8 additions & 7 deletions src/hotplug_libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <unistd.h>
#include <errno.h>
#include <usb.h>
#include <pthread.h>

#include "misc.h"
#include "wintypes.h"
Expand All @@ -55,7 +56,7 @@
#define FALSE 0
#define TRUE 1

PCSCLITE_MUTEX usbNotifierMutex;
pthread_mutex_t usbNotifierMutex;

static pthread_t usbNotifyThread;
static int driverSize = -1;
Expand Down Expand Up @@ -483,7 +484,7 @@ static LONG HPAddHotPluggable(struct usb_device *dev, const char bus_device[],
dev->descriptor.idVendor, dev->descriptor.idProduct, bus_device);
deviceName[sizeof(deviceName) -1] = '\0';

SYS_MutexLock(&usbNotifierMutex);
pthread_mutex_lock(&usbNotifierMutex);

/* find a free entry */
for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++)
Expand All @@ -496,7 +497,7 @@ static LONG HPAddHotPluggable(struct usb_device *dev, const char bus_device[],
{
Log2(PCSC_LOG_ERROR,
"Not enough reader entries. Already found %d readers", i);
SYS_MutexUnLock(&usbNotifierMutex);
pthread_mutex_unlock(&usbNotifierMutex);
return 0;
}

Expand Down Expand Up @@ -544,14 +545,14 @@ static LONG HPAddHotPluggable(struct usb_device *dev, const char bus_device[],
(void)CheckForOpenCT();
}

SYS_MutexUnLock(&usbNotifierMutex);
pthread_mutex_unlock(&usbNotifierMutex);

return 1;
} /* End of function */

static LONG HPRemoveHotPluggable(int reader_index)
{
SYS_MutexLock(&usbNotifierMutex);
pthread_mutex_lock(&usbNotifierMutex);

Log3(PCSC_LOG_INFO, "Removing USB device[%d]: %s", reader_index,
readerTracker[reader_index].bus_device);
Expand All @@ -563,7 +564,7 @@ static LONG HPRemoveHotPluggable(int reader_index)
readerTracker[reader_index].bus_device[0] = '\0';
readerTracker[reader_index].fullName = NULL;

SYS_MutexUnLock(&usbNotifierMutex);
pthread_mutex_unlock(&usbNotifierMutex);

return 1;
} /* End of function */
Expand All @@ -573,7 +574,7 @@ static LONG HPRemoveHotPluggable(int reader_index)
*/
ULONG HPRegisterForHotplugEvents(void)
{
(void)SYS_MutexInit(&usbNotifierMutex);
(void)pthread_mutex_init(&usbNotifierMutex, NULL);
return 0;
}

Expand Down
12 changes: 6 additions & 6 deletions src/hotplug_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#define FALSE 0
#define TRUE 1

PCSCLITE_MUTEX usbNotifierMutex;
pthread_mutex_t usbNotifierMutex;

struct usb_device_descriptor
{
Expand Down Expand Up @@ -314,7 +314,7 @@ static void HPEstablishUSBNotifications(void)

if (usbDeviceStatus == 1)
{
SYS_MutexLock(&usbNotifierMutex);
pthread_mutex_lock(&usbNotifierMutex);

for (j=0; j < PCSCLITE_MAX_READERS_CONTEXTS; j++)
{
Expand All @@ -331,7 +331,7 @@ static void HPEstablishUSBNotifications(void)
bundleTracker[i].deviceNumber[j].id = suspectDeviceNumber;
}

SYS_MutexUnLock(&usbNotifierMutex);
pthread_mutex_unlock(&usbNotifierMutex);
}
else
if (usbDeviceStatus == 0)
Expand All @@ -342,10 +342,10 @@ static void HPEstablishUSBNotifications(void)
if (bundleTracker[i].deviceNumber[j].id != 0 &&
bundleTracker[i].deviceNumber[j].status == 0)
{
SYS_MutexLock(&usbNotifierMutex);
pthread_mutex_lock(&usbNotifierMutex);
HPRemoveHotPluggable(i, j+1);
bundleTracker[i].deviceNumber[j].id = 0;
SYS_MutexUnLock(&usbNotifierMutex);
pthread_mutex_unlock(&usbNotifierMutex);
}
}
}
Expand Down Expand Up @@ -423,7 +423,7 @@ static LONG HPRemoveHotPluggable(int i, unsigned long usbAddr)
*/
ULONG HPRegisterForHotplugEvents(void)
{
(void)SYS_MutexInit(&usbNotifierMutex);
(void)pthread_mutex_init(&usbNotifierMutex, NULL);
return 0;
}

Expand Down
Loading

0 comments on commit 8e1f794

Please sign in to comment.