Add spinlock primitives
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
@@ -123,9 +123,27 @@ static inline int iscsi_mt_mutex_unlock(libiscsi_mutex_t *mutex)
|
||||
return pthread_mutex_unlock(mutex);
|
||||
}
|
||||
|
||||
typedef pthread_spinlock_t libiscsi_spinlock_t;
|
||||
static inline int iscsi_mt_spin_init(libiscsi_spinlock_t *spinlock, int shared)
|
||||
{
|
||||
return pthread_spin_init(spinlock, shared);
|
||||
}
|
||||
static inline int iscsi_mt_spin_destroy(libiscsi_spinlock_t *spinlock)
|
||||
{
|
||||
return pthread_spin_destroy(spinlock);
|
||||
}
|
||||
static inline int iscsi_mt_spin_lock(libiscsi_spinlock_t *spinlock)
|
||||
{
|
||||
return pthread_spin_lock(spinlock);
|
||||
}
|
||||
static inline int iscsi_mt_spin_unlock(libiscsi_spinlock_t *spinlock)
|
||||
{
|
||||
return pthread_spin_unlock(spinlock);
|
||||
}
|
||||
|
||||
#elif defined(WIN32)
|
||||
typedef HANDLE libiscsi_mutex_t;
|
||||
static inline int iscsi_mt_mutex_init(libiscsi_mutex_t* mutex)
|
||||
static inline int iscsi_mt_mutex_init(libiscsi_mutex_t* mutex)
|
||||
{
|
||||
*mutex = CreateSemaphoreA(NULL, 1, 1, NULL);
|
||||
return 0;
|
||||
@@ -156,6 +174,11 @@ typedef const int libiscsi_mutex_t;
|
||||
#define iscsi_mt_mutex_destroy(x) ;
|
||||
#define iscsi_mt_mutex_lock(x) ;
|
||||
#define iscsi_mt_mutex_unlock(x) ;
|
||||
typedef const int libiscsi_spinlock_t;
|
||||
#define iscsi_mt_spin_init(x) ;
|
||||
#define iscsi_mt_spin_destroy(x) ;
|
||||
#define iscsi_mt_spin_lock(x) ;
|
||||
#define iscsi_mt_spin_unlock(x) ;
|
||||
|
||||
#endif /* mutex */
|
||||
|
||||
|
||||
@@ -213,6 +213,7 @@ struct iscsi_context {
|
||||
|
||||
#ifdef HAVE_MULTITHREADING
|
||||
int multithreading_enabled;
|
||||
libiscsi_spinlock_t iscsi_lock;
|
||||
libiscsi_mutex_t iscsi_mutex;
|
||||
libiscsi_thread_t service_thread;
|
||||
int poll_timeout;
|
||||
|
||||
@@ -215,6 +215,7 @@ iscsi_create_context(const char *initiator_name)
|
||||
|
||||
memset(iscsi, 0, sizeof(struct iscsi_context));
|
||||
|
||||
iscsi_mt_spin_init(&iscsi->iscsi_lock, PTHREAD_PROCESS_PRIVATE);
|
||||
iscsi_mt_mutex_init(&iscsi->iscsi_mutex);
|
||||
iscsi->poll_timeout = 100;
|
||||
|
||||
@@ -433,6 +434,7 @@ iscsi_destroy_context(struct iscsi_context *iscsi)
|
||||
iscsi_destroy_context(iscsi->old_iscsi);
|
||||
}
|
||||
|
||||
iscsi_mt_spin_destroy(&iscsi->iscsi_lock);
|
||||
iscsi_mt_mutex_destroy(&iscsi->iscsi_mutex);
|
||||
|
||||
memset(iscsi, 0, sizeof(struct iscsi_context));
|
||||
|
||||
Reference in New Issue
Block a user