X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fflock.c;h=cae9fb1fca416de8494db0f8329216d227a9a853;hb=ecb3935e78cd9bcfdebafdee0834cfb1060d7b5e;hp=90e294f07222ce6cbd19c770c28ea291729d52ae;hpb=966aaa6c44c0c446a766bb75f643e37d34b2a099;p=idzebra-moved-to-github.git diff --git a/util/flock.c b/util/flock.c index 90e294f..cae9fb1 100644 --- a/util/flock.c +++ b/util/flock.c @@ -1,4 +1,4 @@ -/* $Id: flock.c,v 1.2 2006-03-23 20:38:00 adam Exp $ +/* $Id: flock.c,v 1.7 2006-05-10 08:13:46 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -44,7 +44,7 @@ struct zebra_lock_info { char *fname; }; -int log_level = 0; +static int log_level = 0 /* YLOG_LOG|YLOG_FLUSH */; char *zebra_mk_fname (const char *dir, const char *name) { @@ -95,9 +95,11 @@ ZebraLockHandle zebra_lock_create (const char *dir, const char *name) if (h->fd == -1) { xfree (h); - h = 0; + yaz_log(YLOG_WARN | YLOG_ERRNO, "zebra_lock_create fail fname=%s", fname); + return 0; } h->fname = fname; + yaz_log(log_level, "zebra_lock_create fd=%d p=%p fname=%s", h->fd, h, h->fname); return h; } @@ -105,6 +107,7 @@ void zebra_lock_destroy (ZebraLockHandle h) { if (!h) return; + yaz_log(log_level, "zebra_lock_destroy fd=%d p=%p fname=%s", h->fd, h, h->fname); if (h->fd != -1) close (h->fd); xfree (h->fname); @@ -124,22 +127,30 @@ static int unixLock (int fd, int type, int cmd) int zebra_lock_w (ZebraLockHandle h) { - yaz_log(log_level, "zebra_lock_w p=%p fname=%s", h, h->fname); + int r; + yaz_log(log_level, "zebra_lock_w fd=%d p=%p fname=%s", h->fd, h, h->fname); #ifdef WIN32 - return _locking (h->fd, _LK_LOCK, 1); + while ((r = _locking (h->fd, _LK_LOCK, 1))) + ; #else - return unixLock (h->fd, F_WRLCK, F_SETLKW); + r = unixLock (h->fd, F_WRLCK, F_SETLKW); #endif + yaz_log(log_level, "zebra_lock_w fd=%d p=%p fname=%s OK", h->fd, h, h->fname); + return r; } int zebra_lock_r (ZebraLockHandle h) { - yaz_log(log_level, "zebra_lock_r p=%p fname=%s", h, h->fname); + int r; + yaz_log(log_level, "zebra_lock_r fd=%d p=%p fname=%s", h->fd, h, h->fname); #ifdef WIN32 - return _locking (h->fd, _LK_LOCK, 1); + while ((r = _locking (h->fd, _LK_LOCK, 1))) + ; #else - return unixLock (h->fd, F_RDLCK, F_SETLKW); + r = unixLock (h->fd, F_RDLCK, F_SETLKW); #endif + yaz_log(log_level, "zebra_lock_r fd=%d p=%p fname=%s OK", h->fd, h, h->fname); + return r; } int zebra_unlock (ZebraLockHandle h) @@ -152,3 +163,11 @@ int zebra_unlock (ZebraLockHandle h) #endif } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +