YAZ  5.23.1
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

typedef struct yaz_cond* YAZ_COND

YAZ condition opaque pointer.

Definition at line 45 of file mutex.h.

typedef struct yaz_mutex* YAZ_MUTEX

YAZ MUTEX opaque pointer.

Definition at line 42 of file mutex.h.

Function Documentation

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.

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().

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().

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.

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().

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 41 of file mutex.c.

References malloc().

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

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 138 of file mutex.c.

References free().

Referenced by resultset_destroy(), and yaz_log_deinit_globals().

void yaz_mutex_enter ( YAZ_MUTEX  mutex)

enter critical section / AKA lock

Parameters
mutexMUTEX handle

Definition at line 69 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().

void yaz_mutex_leave ( YAZ_MUTEX  mutex)

leave critical section / AKA unlock

Parameters
mutexMUTEX handle

Definition at line 120 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().

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 56 of file mutex.c.

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