29 #include <sys/types.h>
32 #include <sys/locking.h>
40 #include <yaz/xmalloc.h>
86 int dlen = dir ? strlen(dir) : 0;
87 char *
fname = xmalloc(dlen + strlen(name) + 2);
92 int last_one = dir[dlen-1];
95 if (!strchr(
"/\\:", last_one))
98 if (!strchr(
"/", last_one))
139 yaz_log(YLOG_WARN | YLOG_ERRNO,
140 "zebra_lock_create fail fname=%s",
fname);
168 yaz_log(
log_level,
"zebra_lock_create fd=%d p=%p fname=%s",
181 yaz_log(
log_level,
"zebra_lock_destroy fd=%d p=%p fname=%s",
184 yaz_log(
log_level,
"zebra_lock_destroy fd=%d p=%p fname=%s refcount=%d",
203 yaz_log(
log_level,
"zebra_lock_destroy fd=%d p=%p fname=%s remove",
226 area.l_whence = SEEK_SET;
227 area.l_len = area.l_start = 0L;
229 yaz_log(
log_level,
"fcntl begin type=%d fd=%d", type,
fd);
230 r = fcntl(
fd, cmd, &area);
232 yaz_log(YLOG_WARN|YLOG_ERRNO,
"fcntl FAIL type=%d fd=%d", type,
fd);
234 yaz_log(
log_level,
"fcntl type=%d OK fd=%d", type,
fd);
244 yaz_log(
log_level,
"zebra_lock_w fd=%d p=%p fname=%s begin",
248 while ((r = _locking(h->
p->
fd, _LK_LOCK, 1)))
271 yaz_log(
log_level,
"zebra_lock_w fd=%d p=%p fname=%s end",
282 yaz_log(
log_level,
"zebra_lock_r fd=%d p=%p fname=%s begin",
285 while ((r = _locking(h->
p->
fd, _LK_LOCK, 1)))
308 yaz_log(
log_level,
"zebra_lock_r fd=%d p=%p fname=%s end",
316 yaz_log(
log_level,
"zebra_unlock fd=%d p=%p fname=%s begin",
319 r = _locking(h->
p->
fd, _LK_UNLCK, 1);
350 yaz_log(
log_level,
"zebra_unlock fd=%d p=%p fname=%s end",
363 #ifdef _CS_GNU_LIBPTHREAD_VERSION
365 size_t r = confstr(_CS_GNU_LIBPTHREAD_VERSION, conf_buf,
sizeof(conf_buf));
368 yaz_log(YLOG_WARN|YLOG_ERRNO,
"confstr failed");
371 if (strncmp(conf_buf,
"linuxthreads", 12) == 0)
385 log_level = yaz_log_module_level(
"flock");
static int unixLock(int fd, int type, int cmd)
Zebra_mutex lock_list_mutex
static struct zebra_lock_info * lock_list
int zebra_lock_r(ZebraLockHandle h)
int zebra_lock_w(ZebraLockHandle h)
static int check_for_linuxthreads(void)
see if the fcntl locking is not POSIX
void zebra_lock_destroy(ZebraLockHandle h)
ZebraLockHandle zebra_lock_create(const char *dir, const char *name)
char * zebra_mk_fname(const char *dir, const char *name)
int zebra_unlock(ZebraLockHandle h)
struct zebra_lock_handle * ZebraLockHandle
struct zebra_lock_info * p
Zebra_lock_rdwr rdwr_lock
struct zebra_lock_info * next
int zebra_mutex_unlock(Zebra_mutex *p)
int zebra_mutex_init(Zebra_mutex *p)
int zebra_lock_rdwr_rlock(Zebra_lock_rdwr *p)
int zebra_lock_rdwr_wlock(Zebra_lock_rdwr *p)
int zebra_lock_rdwr_destroy(Zebra_lock_rdwr *p)
int zebra_lock_rdwr_wunlock(Zebra_lock_rdwr *p)
int zebra_lock_rdwr_runlock(Zebra_lock_rdwr *p)
int zebra_mutex_lock(Zebra_mutex *p)
int zebra_lock_rdwr_init(Zebra_lock_rdwr *p)
int zebra_mutex_destroy(Zebra_mutex *p)