return code;
}
-#ifdef AFS_DEMAND_ATTACH_FS
+#ifdef AFS_PTHREAD_ENV
+# define AFS_LF_LOCK(lf) assert(pthread_mutex_lock(&((lf)->mutex)) == 0)
+# define AFS_LF_UNLOCK(lf) assert(pthread_mutex_unlock(&((lf)->mutex)) == 0)
+#else
+# define AFS_LF_LOCK(lf)
+# define AFS_LF_UNLOCK(lf)
+#endif /* AFS_PTHREAD_ENV */
/**
* initialize a struct VLockFile.
memset(lf, 0, sizeof(*lf));
lf->path = strdup(path);
lf->fd = INVALID_FD;
+#ifdef AFS_PTHREAD_ENV
assert(pthread_mutex_init(&lf->mutex, NULL) == 0);
+#endif /* AFS_PTHREAD_ENV */
}
-# ifdef AFS_NT40_ENV
+#ifdef AFS_NT40_ENV
static_inline FD_t
_VOpenPath(const char *path)
{
CloseHandle(lf->fd);
}
-# else /* !AFS_NT40_ENV */
+#else /* !AFS_NT40_ENV */
/**
* open a file on the local filesystem suitable for locking
"fd %d\n", errno, fd);
}
}
-# endif /* !AFS_NT40_ENV */
+#endif /* !AFS_NT40_ENV */
/**
* lock a file on disk for the process.
{
int code;
- assert(pthread_mutex_lock(&lf->mutex) == 0);
+ AFS_LF_LOCK(lf);
if (lf->fd == INVALID_FD) {
lf->fd = _VOpenPath(lf->path);
if (lf->fd == INVALID_FD) {
- assert(pthread_mutex_unlock(&lf->mutex) == 0);
+ AFS_LF_UNLOCK(lf);
return EIO;
}
}
lf->refcount++;
- assert(pthread_mutex_unlock(&lf->mutex) == 0);
+ AFS_LF_UNLOCK(lf);
code = _VLockFd(lf->fd, offset, locktype, nonblock);
if (code) {
- assert(pthread_mutex_lock(&lf->mutex) == 0);
+ AFS_LF_LOCK(lf);
if (--lf->refcount < 1) {
_VCloseFd(lf->fd);
lf->fd = INVALID_FD;
}
- assert(pthread_mutex_unlock(&lf->mutex) == 0);
+ AFS_LF_UNLOCK(lf);
}
return code;
void
VLockFileUnlock(struct VLockFile *lf, afs_uint32 offset)
{
- assert(pthread_mutex_lock(&lf->mutex) == 0);
+ AFS_LF_LOCK(lf);
if (--lf->refcount < 1) {
_VCloseFd(lf->fd);
_VUnlockFd(lf->fd, offset);
}
- assert(pthread_mutex_unlock(&lf->mutex) == 0);
+ AFS_LF_UNLOCK(lf);
}
+#ifdef AFS_DEMAND_ATTACH_FS
+
/**
* initialize a struct VDiskLock.
*