+ zebra_mutex_lock(&h->p->file_mutex);
+ if (h->write_flag)
+ {
+ if (h->p->no_file_write_lock > 0)
+ h->p->no_file_write_lock--;
+ }
+ else
+ {
+ if (h->p->no_file_read_lock > 0)
+ h->p->no_file_read_lock--;
+ }
+ if (h->p->no_file_read_lock == 0 && h->p->no_file_write_lock == 0)
+ r = unixLock(h->p->fd, F_UNLCK, F_SETLKW);
+ else
+ {
+ r = 0;
+ assert(posix_locks);
+ }
+
+ zebra_mutex_unlock(&h->p->file_mutex);
+
+ if (posix_locks)
+ {
+ if (h->write_flag)
+ zebra_lock_rdwr_wunlock(&h->p->rdwr_lock);
+ else
+ zebra_lock_rdwr_runlock(&h->p->rdwr_lock);
+ }
+#endif
+ yaz_log(log_level, "zebra_unlock fd=%d p=%p fname=%s end",
+ h->p->fd, h, h->p->fname);
+ return r;
+}
+
+/** \brief see if the fcntl locking is not POSIX
+ *
+ * The default posix_locks=1 is assumed.. This function sets posix_locks
+ * to zero if linuxthreads is in use.
+ */
+static int check_for_linuxthreads(void)
+{
+#if __linux
+#ifdef _CS_GNU_LIBPTHREAD_VERSION
+ char conf_buf[512];
+ size_t r = confstr(_CS_GNU_LIBPTHREAD_VERSION, conf_buf, sizeof(conf_buf));
+ if (r == 0)
+ {
+ yaz_log(YLOG_WARN|YLOG_ERRNO, "confstr failed");
+ return -1;
+ }
+ if (strncmp(conf_buf, "linuxthreads", 12) == 0)
+ posix_locks = 0; /* Using linuxthreads.. */
+#else
+ posix_locks = 0; /* Old GLIBC on Linux. Assume linuxthreads */