Guardtime KSI c SDK
Macros | Typedefs | Enumerations | Functions
Multithreading

Macros

#define KSI_LOCK(n)   KSI_LOCK_set(KSI_LOCK_ON, (n), __FILE__, __LINE__)
 
#define KSI_UNLOCK(n)   KSI_LOCK_set(KSI_LOCK_OFF, (n), __FILE__, __LINE__)
 

Typedefs

typedef int(* KSI_Lock_cb) (int mode, int n, const char *file, int line)
 

Enumerations

enum  KSI_Lock_en {
  KSI_MUTEX_GLOBALS = 0, KSI_MUTEX_TRANSPORT, KSI_MUTEX_HASHING, KSI_MUTEX_CRYPTO,
  __KSI_NUMBER_OF_LOCKS
}
 
enum  KSI_LockMode_en { KSI_LOCK_ON = 0x01, KSI_LOCK_OFF = 0x02 }
 

Functions

int KSI_LOCK_count ()
 
int KSI_LOCK_setCallback (KSI_Lock_cb cb)
 
int KSI_LOCK_set (int mode, int n, const char *file, int line)
 

Detailed Description

The SDK does not implicitly support multithreading as this is not a standard functionality in c. However, as long as the user does not share contexts between threads, the user can define custom locking functionality.

The number of required locks can be aquired by calling KSI_LOCK_count function.

Macro Definition Documentation

◆ KSI_LOCK

#define KSI_LOCK (   n)    KSI_LOCK_set(KSI_LOCK_ON, (n), __FILE__, __LINE__)

◆ KSI_UNLOCK

#define KSI_UNLOCK (   n)    KSI_LOCK_set(KSI_LOCK_OFF, (n), __FILE__, __LINE__)

Typedef Documentation

◆ KSI_Lock_cb

typedef int(* KSI_Lock_cb) (int mode, int n, const char *file, int line)

Mutex locking callback function type.

Parameters
[in]modeBit map combined of the enum KSI_LockMode_en.
[in]nThe number of the lock (KSI_Lock_en).
[in]fileFilename where the call was made.
[in]lineThe line number in the file where the call was made.
Returns
KSI_OK when successful.

Enumeration Type Documentation

◆ KSI_Lock_en

Enumerator
KSI_MUTEX_GLOBALS 
KSI_MUTEX_TRANSPORT 
KSI_MUTEX_HASHING 
KSI_MUTEX_CRYPTO 
__KSI_NUMBER_OF_LOCKS 

◆ KSI_LockMode_en

Enumerator
KSI_LOCK_ON 
KSI_LOCK_OFF 

Function Documentation

◆ KSI_LOCK_count()

int KSI_LOCK_count ( )

Returns the number of locks required.

Note
The return value is not guarenteed to be equal to __KSI_NUMBER_OF_LOCKS.

◆ KSI_LOCK_set()

int KSI_LOCK_set ( int  mode,
int  n,
const char *  file,
int  line 
)

Calls the callback with the given arguments. If callback is not set, the function does nothing.

See also
KSI_Lock_cb.

◆ KSI_LOCK_setCallback()

int KSI_LOCK_setCallback ( KSI_Lock_cb  cb)

Sets the locking callback function, where the mode is a bit vector combined of the enum KSI_LockMode_en; n is one of the KSI_Lock_en values; file and line are used for debugging and indicates where the lock was issued from. The callback function must free the lock
iff (mode & KSI_LOCK_OFF) == 1.

Parameters
[in]cbCallback to be called when a mutex is locked or unlocked.