summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2010-09-06 16:52:14 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2010-09-06 16:52:14 +0200
commit49f57a8d0dcf990169e2f591a937672f74ffa4a9 (patch)
treee8f872af3dd4f0c7d02ef47e214f016747396c23 /src
parentfbe102bada583f308450c27e256053b51643a532 (diff)
downloadlibssh-49f57a8d0dcf990169e2f591a937672f74ffa4a9.tar.gz
libssh-49f57a8d0dcf990169e2f591a937672f74ffa4a9.tar.xz
libssh-49f57a8d0dcf990169e2f591a937672f74ffa4a9.zip
Implemented the noop and native pointers
Diffstat (limited to 'src')
-rw-r--r--src/threads.c21
-rw-r--r--src/threads/CMakeLists.txt1
-rw-r--r--src/threads/native.c4
-rw-r--r--src/threads/pthread.c88
4 files changed, 72 insertions, 42 deletions
diff --git a/src/threads.c b/src/threads.c
index 51a4ccf..022ca2c 100644
--- a/src/threads.c
+++ b/src/threads.c
@@ -30,6 +30,25 @@
#include "libssh/priv.h"
#include "libssh/threads.h"
+static int threads_noop (void **lock){
+ (void)lock;
+ return 0;
+}
+
+static unsigned long threads_id_noop (void){
+ return 1;
+}
+
+struct ssh_threads_callbacks_struct ssh_threads_noop =
+{
+ .type=ssh_threads_type_noop,
+ .mutex_init=threads_noop,
+ .mutex_destroy=threads_noop,
+ .mutex_lock=threads_noop,
+ .mutex_unlock=threads_noop,
+ .thread_id=threads_id_noop
+};
+
static struct ssh_threads_callbacks_struct *user_callbacks;
#ifdef HAVE_LIBGCRYPT
@@ -107,7 +126,7 @@ int ssh_threads_init(void){
* already the case
*/
if(user_callbacks == NULL){
- return SSH_ERROR; // Can't do anything to initialize threading
+ user_callbacks=&ssh_threads_noop;
}
/* Then initialize the crypto libraries threading callbacks */
diff --git a/src/threads/CMakeLists.txt b/src/threads/CMakeLists.txt
index 1cf3d7b..2cebb41 100644
--- a/src/threads/CMakeLists.txt
+++ b/src/threads/CMakeLists.txt
@@ -33,7 +33,6 @@ set(LIBSSH_THREADS_LINK_LIBRARIES
)
set(libssh_threads_SRCS
- native.c
)
# build and link pthread
diff --git a/src/threads/native.c b/src/threads/native.c
deleted file mode 100644
index c65c18e..0000000
--- a/src/threads/native.c
+++ /dev/null
@@ -1,4 +0,0 @@
-#include "config.h"
-#include <libssh/callbacks.h>
-
-struct ssh_threads_callbacks_struct ssh_pthread_callbacks;
diff --git a/src/threads/pthread.c b/src/threads/pthread.c
index 35589cc..0fc0b11 100644
--- a/src/threads/pthread.c
+++ b/src/threads/pthread.c
@@ -45,43 +45,59 @@
* callbacks for threading
*
*/
-#define SSH_THREADS_PTHREAD(name) \
-static int ssh_pthread_mutex_init (void **priv){ \
- int err = 0; \
- *priv = malloc (sizeof (pthread_mutex_t)); \
- if (*priv==NULL) \
- return ENOMEM; \
- err = pthread_mutex_init (*priv, NULL); \
- if (err != 0){ \
- free (*priv); \
- *priv=NULL; \
- } \
- return err; \
-} \
-static int ssh_pthread_mutex_destroy (void **lock) { \
- int err = pthread_mutex_destroy (*lock); \
- free (*lock); \
- *lock=NULL; \
- return err; \
-} \
-static int ssh_pthread_mutex_lock (void **lock) { \
- return pthread_mutex_lock (*lock); \
-} \
-static int ssh_pthread_mutex_unlock (void **lock){ \
- return pthread_mutex_unlock (*lock); \
-} \
-static unsigned long ssh_pthread_thread_id (void){ \
- return (unsigned long) pthread_self(); \
-} \
-static struct ssh_threads_callbacks_struct name= \
-{ \
- .mutex_init=ssh_pthread_mutex_init, \
- .mutex_destroy=ssh_pthread_mutex_destroy, \
- .mutex_lock=ssh_pthread_mutex_lock, \
- .mutex_unlock=ssh_pthread_mutex_unlock, \
- .thread_id=ssh_pthread_thread_id \
+
+static int ssh_pthread_mutex_init (void **priv){
+ int err = 0;
+ *priv = malloc (sizeof (pthread_mutex_t));
+ if (*priv==NULL)
+ return ENOMEM;
+ err = pthread_mutex_init (*priv, NULL);
+ if (err != 0){
+ free (*priv);
+ *priv=NULL;
+ }
+ return err;
+}
+
+static int ssh_pthread_mutex_destroy (void **lock) {
+ int err = pthread_mutex_destroy (*lock);
+ free (*lock);
+ *lock=NULL;
+ return err;
+}
+
+static int ssh_pthread_mutex_lock (void **lock) {
+ return pthread_mutex_lock (*lock);
}
-SSH_THREADS_PTHREAD(ssh_pthread_user_callbacks);
+static int ssh_pthread_mutex_unlock (void **lock){
+ return pthread_mutex_unlock (*lock);
+}
+
+static unsigned long ssh_pthread_thread_id (void){
+ return (unsigned long) pthread_self();
+}
+
+struct ssh_threads_callbacks_struct ssh_threads_pthread =
+{
+ .type=ssh_threads_type_pthread,
+ .mutex_init=ssh_pthread_mutex_init,
+ .mutex_destroy=ssh_pthread_mutex_destroy,
+ .mutex_lock=ssh_pthread_mutex_lock,
+ .mutex_unlock=ssh_pthread_mutex_unlock,
+ .thread_id=ssh_pthread_thread_id
+};
+
+#ifdef THREAD_NATIVE_PTHREAD
+struct ssh_threads_callbacks_struct ssh_threads_native =
+{
+ .type=ssh_threads_type_pthread,
+ .mutex_init=ssh_pthread_mutex_init,
+ .mutex_destroy=ssh_pthread_mutex_destroy,
+ .mutex_lock=ssh_pthread_mutex_lock,
+ .mutex_unlock=ssh_pthread_mutex_unlock,
+ .thread_id=ssh_pthread_thread_id
+};
+#endif
#endif /* HAVE_PTHREAD */