X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=include%2Fzebra-lock.h;fp=include%2Fzebra-lock.h;h=b7d61648de0462083d1803eb53e5b15e096878de;hb=eb2b742588ce07fb4516bbca22c93b938b13e433;hp=0000000000000000000000000000000000000000;hpb=83533000f9456dcab2fc171abafd84d6104d4087;p=idzebra-moved-to-github.git diff --git a/include/zebra-lock.h b/include/zebra-lock.h new file mode 100644 index 0000000..b7d6164 --- /dev/null +++ b/include/zebra-lock.h @@ -0,0 +1,37 @@ + +#ifndef ZEBRA_LOCK_H +#define ZEBRA_LOCK_H + +#if HAVE_PTHREAD_H +#include +#endif + +#include + +YAZ_BEGIN_CDECL + +typedef struct { + pthread_mutex_t mutex; +} Zebra_mutex; + +YAZ_EXPORT int zebra_mutex_init (Zebra_mutex *p); +YAZ_EXPORT int zebra_mutex_destroy (Zebra_mutex *p); +YAZ_EXPORT int zebra_mutex_lock (Zebra_mutex *p); +YAZ_EXPORT int zebra_mutex_unlock (Zebra_mutex *p); + +typedef struct { + int readers_reading; + int writers_writing; + pthread_mutex_t mutex; + pthread_cond_t lock_free; +} Zebra_lock_rdwr; + +YAZ_EXPORT int zebra_lock_rdwr_init (Zebra_lock_rdwr *p); +YAZ_EXPORT int zebra_lock_rdwr_destroy (Zebra_lock_rdwr *p); +YAZ_EXPORT int zebra_lock_rdwr_rlock (Zebra_lock_rdwr *p); +YAZ_EXPORT int zebra_lock_rdwr_wlock (Zebra_lock_rdwr *p); +YAZ_EXPORT int zebra_lock_rdwr_runlock (Zebra_lock_rdwr *p); +YAZ_EXPORT int zebra_lock_rdwr_wunlock (Zebra_lock_rdwr *p); + +YAZ_END_CDECL +#endif