[Pcsclite-cvs-commit] r410 - in trunk/PKCS11: include src
Ludovic Rousseau
rousseau at costa.debian.org
Thu Mar 16 10:10:34 CET 2006
Author: rousseau
Date: 2006-03-16 09:10:34 +0000 (Thu, 16 Mar 2006)
New Revision: 410
Added:
trunk/PKCS11/include/misc.h
trunk/PKCS11/include/thread_generic.h
trunk/PKCS11/src/thread_unix.c
Modified:
trunk/PKCS11/src/Makefile.am
Log:
copy thread_unix.c from pcsc-lite 1.3.0 since the SYS_Thread* symbols
are no more exported by libpcsclite or libmusclecard
Added: trunk/PKCS11/include/misc.h
===================================================================
--- trunk/PKCS11/include/misc.h 2006-02-07 10:26:28 UTC (rev 409)
+++ trunk/PKCS11/include/misc.h 2006-03-16 09:10:34 UTC (rev 410)
@@ -0,0 +1,58 @@
+/*
+ * This handles GCC attributes
+ *
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 2005
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: misc.h 1935 2006-03-16 08:17:58Z rousseau $
+ */
+
+#ifndef __local_h__
+#define __local_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/*
+ * Declare the function as internal to the library: the function name is
+ * not exported and can't be used by a program linked to the library
+ *
+ * see http://gcc.gnu.org/onlinedocs/gcc-3.3.5/gcc/Function-Attributes.html#Function-Attributes
+ * see http://www.nedprod.com/programs/gccvisibility.html
+ */
+#if defined __GNUC__
+#define INTERNAL __attribute__ ((visibility("hidden")))
+#define PCSC_API __attribute__ ((visibility("default")))
+#else
+#define INTERNAL
+#define PCSC_API
+#endif
+
+#if defined __GNUC__
+
+/* GNU Compiler Collection (GCC) */
+#define CONSTRUCTOR __attribute__ ((constructor))
+#define DESTRUCTOR __attribute__ ((destructor))
+
+#else
+
+/* SUN C compiler does not use __attribute__ but #pragma init (function)
+ * We can't use a # inside a #define so it is not possible to use
+ * #define CONSTRUCTOR_DECLARATION(x) #pragma init (x)
+ * The #pragma is used directly where needed */
+
+/* any other */
+#define CONSTRUCTOR
+#define DESTRUCTOR
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __lcoal_h__ */
Added: trunk/PKCS11/include/thread_generic.h
===================================================================
--- trunk/PKCS11/include/thread_generic.h 2006-02-07 10:26:28 UTC (rev 409)
+++ trunk/PKCS11/include/thread_generic.h 2006-03-16 09:10:34 UTC (rev 410)
@@ -0,0 +1,64 @@
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 2000-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Damien Sauveron <damien.sauveron at labri.fr>
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: thread_generic.h 1827 2006-01-24 14:49:52Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This provides system specific thread calls.
+ */
+
+#ifndef __thread_generic_h__
+#define __thread_generic_h__
+
+#ifdef WIN32
+#include <windows.h>
+#include "PCSC.h"
+#else
+#include <pthread.h>
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef WIN32
+#define PCSCLITE_THREAD_T HANDLE
+#define PCSCLITE_MUTEX CRITICAL_SECTION
+#define PCSCLITE_MUTEX_T CRITICAL_SECTION*
+#define PCSCLITE_THREAD_FUNCTION(f) void *(*f)(void *)
+#else
+#define PCSCLITE_THREAD_T pthread_t
+#define PCSCLITE_MUTEX pthread_mutex_t
+#define PCSCLITE_MUTEX_T pthread_mutex_t*
+#define PCSCLITE_THREAD_FUNCTION(f) void *(*f)(void *)
+#endif
+
+/* thread attributes */
+#define THREAD_ATTR_DEFAULT 0
+#define THREAD_ATTR_DETACHED 1
+
+ int SYS_MutexInit(PCSCLITE_MUTEX_T);
+ int SYS_MutexDestroy(PCSCLITE_MUTEX_T);
+ int SYS_MutexLock(PCSCLITE_MUTEX_T);
+ int SYS_MutexUnLock(PCSCLITE_MUTEX_T);
+ int SYS_ThreadCreate(PCSCLITE_THREAD_T *, int, PCSCLITE_THREAD_FUNCTION( ), LPVOID);
+ int SYS_ThreadCancel(PCSCLITE_THREAD_T *);
+ int SYS_ThreadDetach(PCSCLITE_THREAD_T);
+ int SYS_ThreadJoin(PCSCLITE_THREAD_T *, LPVOID*);
+ int SYS_ThreadExit(LPVOID);
+ PCSCLITE_THREAD_T SYS_ThreadSelf(void);
+ int SYS_ThreadEqual(PCSCLITE_THREAD_T *, PCSCLITE_THREAD_T *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __thread_generic_h__ */
Modified: trunk/PKCS11/src/Makefile.am
===================================================================
--- trunk/PKCS11/src/Makefile.am 2006-02-07 10:26:28 UTC (rev 409)
+++ trunk/PKCS11/src/Makefile.am 2006-03-16 09:10:34 UTC (rev 410)
@@ -32,7 +32,8 @@
p11x_thread.c \
p11x_unixdll.c \
p11x_util.c \
- p11x_win32dll.c
+ p11x_win32dll.c \
+ thread_unix.c
include_HEADERS = \
../include/crackcert.h \
@@ -43,7 +44,8 @@
../include/pkcs11f.h \
../include/pkcs11t.h \
../include/p11x_msc.h \
- ../include/thread_generic.h
+ ../include/thread_generic.h \
+ ../include/misc.h
EXTRA_DIST = $(include_HEADERS)
Added: trunk/PKCS11/src/thread_unix.c
===================================================================
--- trunk/PKCS11/src/thread_unix.c 2006-02-07 10:26:28 UTC (rev 409)
+++ trunk/PKCS11/src/thread_unix.c 2006-03-16 09:10:34 UTC (rev 410)
@@ -0,0 +1,103 @@
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 2000-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Damien Sauveron <damien.sauveron at labri.fr>
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: thread_unix.c 1421 2005-04-12 12:09:21Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles thread function abstraction.
+ */
+
+#include "wintypes.h"
+#include "thread_generic.h"
+#include "misc.h"
+
+#ifndef TRUE
+#define TRUE 1
+#define FALSE 0
+#endif
+
+INTERNAL int SYS_MutexInit(PCSCLITE_MUTEX_T mMutex)
+{
+ return pthread_mutex_init(mMutex, NULL);
+}
+
+INTERNAL int SYS_MutexDestroy(PCSCLITE_MUTEX_T mMutex)
+{
+ return pthread_mutex_destroy(mMutex);
+}
+
+INTERNAL int SYS_MutexLock(PCSCLITE_MUTEX_T mMutex)
+{
+ return pthread_mutex_lock(mMutex);
+}
+
+INTERNAL int SYS_MutexUnLock(PCSCLITE_MUTEX_T mMutex)
+{
+ return pthread_mutex_unlock(mMutex);
+}
+
+INTERNAL int SYS_ThreadCreate(PCSCLITE_THREAD_T * pthThread, int attributes,
+ PCSCLITE_THREAD_FUNCTION(pvFunction), LPVOID pvArg)
+{
+ pthread_attr_t attr;
+
+ if (0 != pthread_attr_init(&attr))
+ return FALSE;
+
+ if (0 != pthread_attr_setdetachstate(&attr,
+ attributes & THREAD_ATTR_DETACHED ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE))
+ return FALSE;
+
+ if (0 == pthread_create(pthThread, &attr, pvFunction, pvArg))
+ return TRUE;
+ else
+ return FALSE;
+}
+
+INTERNAL int SYS_ThreadCancel(PCSCLITE_THREAD_T * pthThread)
+{
+ if (0 == pthread_cancel(*pthThread))
+ return TRUE;
+ else
+ return FALSE;
+}
+
+INTERNAL int SYS_ThreadDetach(PCSCLITE_THREAD_T pthThread)
+{
+ if (0 == pthread_detach(pthThread))
+ return TRUE;
+ else
+ return FALSE;
+}
+
+INTERNAL int SYS_ThreadJoin(PCSCLITE_THREAD_T *pthThread, LPVOID* pvRetVal)
+{
+ if (0 == pthread_join(*pthThread, pvRetVal))
+ return TRUE;
+ else
+ return FALSE;
+}
+
+INTERNAL int SYS_ThreadExit(LPVOID pvRetVal)
+{
+ pthread_exit(pvRetVal);
+ return 1;
+}
+
+INTERNAL PCSCLITE_THREAD_T SYS_ThreadSelf(void)
+{
+ return pthread_self();
+}
+
+INTERNAL int SYS_ThreadEqual(PCSCLITE_THREAD_T *pthThread1, PCSCLITE_THREAD_T *pthThread2)
+{
+ return pthread_equal(*pthThread1, *pthThread2);
+}
+
More information about the Pcsclite-cvs-commit
mailing list