summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/libssh/callbacks.h17
-rw-r--r--src/threads.c6
-rw-r--r--src/threads/pthread.c6
-rw-r--r--tests/unittests/torture_rand.c2
4 files changed, 26 insertions, 5 deletions
diff --git a/include/libssh/callbacks.h b/include/libssh/callbacks.h
index a2ea6a69..d2526694 100644
--- a/include/libssh/callbacks.h
+++ b/include/libssh/callbacks.h
@@ -279,8 +279,21 @@ struct ssh_threads_callbacks_struct {
LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
*cb);
-extern struct ssh_threads_callbacks_struct ssh_threads_pthread;
-extern struct ssh_threads_callbacks_struct ssh_threads_noop;
+/**
+ * @brief returns a pointer on the pthread threads callbacks, to be used with
+ * ssh_threads_set_callbacks.
+ * @warning you have to link with the library ssh_threads.
+ * @see ssh_threads_set_callbacks
+ */
+LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void);
+
+/**
+ * @brief returns a pointer on the noop threads callbacks, to be used with
+ * ssh_threads_set_callbacks. These callbacks do nothing and are being used by
+ * default.
+ * @see ssh_threads_set_callbacks
+ */
+LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void);
/** @} */
#ifdef __cplusplus
diff --git a/src/threads.c b/src/threads.c
index 60d5dee5..db7c216c 100644
--- a/src/threads.c
+++ b/src/threads.c
@@ -39,7 +39,7 @@ static unsigned long threads_id_noop (void){
return 1;
}
-struct ssh_threads_callbacks_struct ssh_threads_noop =
+static struct ssh_threads_callbacks_struct ssh_threads_noop =
{
"threads_noop",
threads_noop,
@@ -49,6 +49,10 @@ struct ssh_threads_callbacks_struct ssh_threads_noop =
threads_id_noop
};
+struct ssh_threads_callbacks_struct *ssh_threads_get_noop(){
+ return &ssh_threads_noop;
+}
+
static struct ssh_threads_callbacks_struct *user_callbacks =&ssh_threads_noop;
#ifdef HAVE_LIBGCRYPT
diff --git a/src/threads/pthread.c b/src/threads/pthread.c
index 84966d01..fdfd27d0 100644
--- a/src/threads/pthread.c
+++ b/src/threads/pthread.c
@@ -78,7 +78,7 @@ static unsigned long ssh_pthread_thread_id (void){
return (unsigned long) pthread_self();
}
-struct ssh_threads_callbacks_struct ssh_threads_pthread =
+static struct ssh_threads_callbacks_struct ssh_threads_pthread =
{
.type="threads_pthread",
.mutex_init=ssh_pthread_mutex_init,
@@ -88,4 +88,8 @@ struct ssh_threads_callbacks_struct ssh_threads_pthread =
.thread_id=ssh_pthread_thread_id
};
+struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(){
+ return &ssh_threads_pthread;
+}
+
#endif /* HAVE_PTHREAD */
diff --git a/tests/unittests/torture_rand.c b/tests/unittests/torture_rand.c
index 74193977..9962564a 100644
--- a/tests/unittests/torture_rand.c
+++ b/tests/unittests/torture_rand.c
@@ -15,7 +15,7 @@
static void setup(){
printf("setup\n");
- ssh_threads_set_callbacks(&ssh_threads_pthread);
+ ssh_threads_set_callbacks(ssh_threads_get_pthread());
ssh_init();
}