diff options
author | Anderson Toshiyuki Sasaki <ansasaki@redhat.com> | 2018-07-02 13:03:12 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-08-03 16:43:03 +0200 |
commit | 83b43443e51b5db06184750fb874e1e8d7ece95a (patch) | |
tree | 9c81acc146ee9d0d129ab953a38e2363574fa888 /include/libssh/threads.h | |
parent | 6a077fe7509fb3141c0c63365a32208e42aa90f1 (diff) | |
download | libssh-83b43443e51b5db06184750fb874e1e8d7ece95a.tar.gz libssh-83b43443e51b5db06184750fb874e1e8d7ece95a.tar.xz libssh-83b43443e51b5db06184750fb874e1e8d7ece95a.zip |
threads: Automatically call ssh_init on load
This makes unnecessary to call ssh_init() when the library is
dynamically loaded. Also removes the threads shared library. The used
threads implementation is chosen in configuration time, changing the
ssh_threads_get_default() depending on the available threads library.
Internally, it is expected a threads implementation providing:
- void ssh_mutex_lock(void **mutex);
- void ssh_mutex_unlock(void **mutex);
- struct ssh_threads_callbacks_struct *ssh_threads_get_default(void);
and a crypto implementation providing:
- int crypto_thread_init(struct ssh_threads_callbacks_struct *user_callbacks);
- void crypto_thread_finalize(void);
This adds internal threads implementation for pthreads and noop.
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'include/libssh/threads.h')
-rw-r--r-- | include/libssh/threads.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/libssh/threads.h b/include/libssh/threads.h index 70072648..750793b2 100644 --- a/include/libssh/threads.h +++ b/include/libssh/threads.h @@ -24,8 +24,33 @@ #include <libssh/libssh.h> #include <libssh/callbacks.h> +#if HAVE_PTHREAD + +#include <pthread.h> +#define SSH_MUTEX pthread_mutex_t + +#if defined _GNU_SOURCE +#define SSH_MUTEX_STATIC_INIT PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP +#else +#define SSH_MUTEX_STATIC_INIT PTHREAD_MUTEX_INITIALIZER +#endif + +#else + +# define SSH_MUTEX void * +#define SSH_MUTEX_STATIC_INIT NULL + +#endif + int ssh_threads_init(void); void ssh_threads_finalize(void); const char *ssh_threads_get_type(void); +void ssh_mutex_lock(SSH_MUTEX *mutex); +void ssh_mutex_unlock(SSH_MUTEX *mutex); + +struct ssh_threads_callbacks_struct *ssh_threads_get_default(void); +int crypto_thread_init(struct ssh_threads_callbacks_struct *user_callbacks); +void crypto_thread_finalize(void); + #endif /* THREADS_H_ */ |