YAZ  5.23.1
Functions
mutex.c File Reference

Implements MUTEX functions. More...

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stddef.h>
#include <yaz/xmalloc.h>
#include <yaz/nmem.h>
#include <yaz/log.h>
#include <yaz/mutex.h>
#include <yaz/gettimeofday.h>
#include <time.h>
#include "mutex-p.h"

Go to the source code of this file.

Functions

void yaz_mutex_create (YAZ_MUTEX *p)
 create MUTEX More...
 
void yaz_mutex_set_name (YAZ_MUTEX p, int log_level, const char *name)
 sets name of MUTEX for debugging purposes More...
 
void yaz_mutex_enter (YAZ_MUTEX p)
 enter critical section / AKA lock More...
 
void yaz_mutex_leave (YAZ_MUTEX p)
 leave critical section / AKA unlock More...
 
void yaz_mutex_destroy (YAZ_MUTEX *p)
 destroy MUTEX More...
 

Detailed Description

Implements MUTEX functions.

Definition in file mutex.c.

Function Documentation

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.