mail-index-lock.c revision b71e08759c02a49d02cdfb28343351ad28fc10b5
/* Copyright (c) 2003-2012 Dovecot authors, see the included COPYING file */
/*
Locking should never fail or timeout. Exclusive locks must be kept as short
time as possible. Shared locks can be long living, so if we can't get
exclusive lock directly, we'll recreate the index. That means the shared
lock holders can keep using the old file.
lock_id is used to figure out if acquired lock is still valid. When index
file is reopened, the lock_id can become invalid. It doesn't matter however,
as no-one's going to modify the old file anymore.
lock_id also tells us if we're referring to a shared or an exclusive lock.
This allows us to drop back to shared locking once all exclusive locks
are dropped. Shared locks have even numbers, exclusive locks have odd numbers.
The number is increased by two every time the lock is dropped or index file
is reopened.
*/
#include "lib.h"
#include "nfs-workarounds.h"
#include "mail-index-private.h"
#define MAIL_INDEX_SHARED_LOCK_TIMEOUT 120
int lock_type, unsigned int timeout_secs,
{
if (fd == -1) {
return 1;
}
}
{
return;
/* Assume flock() is emulated with fcntl(), because that's how most
OSes work nowadays. */
if (locked &&
} else {
}
}