return rc;
}
+/** Try to get exlusive lock, otherwise shared.
+ * Maintain *excl = -1: no/unknown lock, 0: shared, 1: exclusive.
+ */
static int
mdb_env_excl_lock(MDB_env *env, int *excl)
{
lock_info.l_len = 1;
if (!fcntl(env->me_lfd, F_SETLK, &lock_info)) {
*excl = 1;
- } else {
+ } else
+# ifdef MDB_USE_POSIX_SEM
+ if (*excl < 0) /* always true when !MDB_USE_POSIX_SEM */
+# endif
+ {
lock_info.l_type = F_RDLCK;
while ((rc = fcntl(env->me_lfd, F_SETLKW, &lock_info)) &&
(rc = ErrCode()) == EINTR) ;
int rc;
off_t size, rsize;
- *excl = 0;
+ *excl = -1;
#ifdef _WIN32
if ((env->me_lfd = CreateFile(lpath, GENERIC_READ|GENERIC_WRITE,
size = lseek(env->me_lfd, 0, SEEK_END);
#endif
rsize = (env->me_maxreaders-1) * sizeof(MDB_reader) + sizeof(MDB_txninfo);
- if (size < rsize && *excl) {
+ if (size < rsize && *excl > 0) {
#ifdef _WIN32
SetFilePointer(env->me_lfd, rsize, NULL, 0);
if (!SetEndOfFile(env->me_lfd)) {
env->me_txns = m;
#endif
}
- if (*excl) {
+ if (*excl > 0) {
#ifdef _WIN32
BY_HANDLE_FILE_INFORMATION stbuf;
struct {
goto leave;
}
#endif
- if (excl) {
+ if (excl > 0) {
rc = mdb_env_share_locks(env);
if (rc)
goto leave;