YAZ  5.34.0
Typedefs | Functions
mutex.h File Reference

Header for Mutex functions. More...

#include <stddef.h>
#include <time.h>
#include <yaz/yconfig.h>

Go to the source code of this file.

Typedefs

typedef struct yaz_mutexYAZ_MUTEX
 YAZ MUTEX opaque pointer. More...
 
typedef struct yaz_condYAZ_COND
 YAZ condition opaque pointer. More...
 

Functions

void yaz_mutex_create (YAZ_MUTEX *mutexp)
 create MUTEX More...
 
void yaz_mutex_enter (YAZ_MUTEX mutex)
 enter critical section / AKA lock More...
 
void yaz_mutex_leave (YAZ_MUTEX mutex)
 leave critical section / AKA unlock More...
 
void yaz_mutex_destroy (YAZ_MUTEX *mutexp)
 destroy MUTEX More...
 
void yaz_mutex_set_name (YAZ_MUTEX mutex, int log_level, const char *name)
 sets name of MUTEX for debugging purposes More...
 
void yaz_cond_create (YAZ_COND *p)
 creates condition variable More...
 
void yaz_cond_destroy (YAZ_COND *p)
 destroys condition variable More...
 
int yaz_cond_wait (YAZ_COND p, YAZ_MUTEX m, const struct timeval *abstime)
 waits for condition More...
 
int yaz_cond_signal (YAZ_COND p)
 unblock one thread waiting for block More...
 
int yaz_cond_broadcast (YAZ_COND p)
 unblock all threads waiting for block More...
 

Detailed Description

Header for Mutex functions.

Definition in file mutex.h.

Typedef Documentation

◆ YAZ_COND

typedef struct yaz_cond* YAZ_COND

YAZ condition opaque pointer.

Definition at line 45 of file mutex.h.

◆ YAZ_MUTEX

typedef struct yaz_mutex* YAZ_MUTEX

YAZ MUTEX opaque pointer.

Definition at line 42 of file mutex.h.

Function Documentation

◆ yaz_cond_broadcast()

int yaz_cond_broadcast ( YAZ_COND  p)

unblock all threads waiting for block

Parameters
pcondition variable handle

Definition at line 120 of file condvar.c.

◆ yaz_cond_create()

void yaz_cond_create ( YAZ_COND p)

creates condition variable

Parameters
preference to condition handle

Upon successful completion *p holds the condition handle; *p = 0 on error.

Definition at line 49 of file condvar.c.

References malloc().

◆ yaz_cond_destroy()

void yaz_cond_destroy ( YAZ_COND p)

destroys condition variable

Parameters
preference to condition handle

Upon completion *p holds 0.

Definition at line 62 of file condvar.c.

References free().

◆ yaz_cond_signal()

int yaz_cond_signal ( YAZ_COND  p)

unblock one thread waiting for block

Parameters
pcondition variable handle

Definition at line 108 of file condvar.c.

◆ yaz_cond_wait()

int yaz_cond_wait ( YAZ_COND  p,
YAZ_MUTEX  m,
const struct timeval *  abstime 
)

waits for condition

Parameters
pcondition variable handle
mmutex
abstimewait until this time; 0 for indefinite wait

Semantics like pthread_cond_wait.

Definition at line 75 of file condvar.c.

References yaz_gettimeofday().

◆ yaz_mutex_create()

void yaz_mutex_create ( YAZ_MUTEX mutexp)

create MUTEX

Parameters
mutexpis pointer to MUTEX handle (*mutexp must be NULL)

It is important that *mutexp is NULL. If not, yaz_mutex_create will not modify the handle (assumes it is already created!)

Definition at line 43 of file mutex.c.

References malloc().

Referenced by resultset_use(), yaz_log_init_globals(), and ZOOM_resultset_create().

◆ yaz_mutex_destroy()

void yaz_mutex_destroy ( YAZ_MUTEX mutexp)

destroy MUTEX

Parameters
mutexppointer to MUTEX handle

If *mutexp is NULL, then this function does nothing.

Definition at line 141 of file mutex.c.

References free().

Referenced by resultset_destroy(), and yaz_log_deinit_globals().

◆ yaz_mutex_enter()

void yaz_mutex_enter ( YAZ_MUTEX  mutex)

enter critical section / AKA lock

Parameters
mutexMUTEX handle

Definition at line 72 of file mutex.c.

References yaz_mutex::log_level, yaz_mutex::name, and yaz_log().

Referenced by resultset_destroy(), resultset_use(), yaz_log_lock(), and ZOOM_resultset_addref().

◆ yaz_mutex_leave()

void yaz_mutex_leave ( YAZ_MUTEX  mutex)

leave critical section / AKA unlock

Parameters
mutexMUTEX handle

Definition at line 123 of file mutex.c.

References yaz_mutex::log_level, yaz_mutex::name, and yaz_log().

Referenced by resultset_destroy(), resultset_use(), yaz_log_unlock(), and ZOOM_resultset_addref().

◆ yaz_mutex_set_name()

void yaz_mutex_set_name ( YAZ_MUTEX  mutex,
int  log_level,
const char *  name 
)

sets name of MUTEX for debugging purposes

Parameters
mutexMUTEX handle
log_levelYAZ log level
nameuser-given name associated with MUTEX

If log_level != 0 and name != 0 this function will make yaz_mutex_enter and yaz_mutex_leave print information for each invocation using yaz_log with the level given. In particular when YAZ is compiled with pthreads, yaz_mutex_enter will inform if a lock is not immediately acquired. This function should be called after a MUTEX is created but before it is used for locking.

Definition at line 58 of file mutex.c.

References free(), log_level, yaz_mutex::log_level, malloc(), name, and yaz_mutex::name.