mail-index-lock.c revision 6c80172147a5a1cf937dea3f0f02b6fabcea861c
1516N/A/* Copyright (c) 2003-2010 Dovecot authors, see the included COPYING file */ 281N/A Locking should never fail or timeout. Exclusive locks must be kept as short 281N/A time as possible. Shared locks can be long living, so if we can't get 281N/A exclusive lock directly, we'll recreate the index. That means the shared 281N/A lock holders can keep using the old file. 281N/A lock_id is used to figure out if acquired lock is still valid. When index 281N/A file is reopened, the lock_id can become invalid. It doesn't matter however, 281N/A as no-one's going to modify the old file anymore. 281N/A lock_id also tells us if we're referring to a shared or an exclusive lock. 281N/A This allows us to drop back to shared locking once all exclusive locks 281N/A are dropped. Shared locks have even numbers, exclusive locks have odd numbers. 281N/A The number is increased by two every time the lock is dropped or index file 1685N/A /* file is already locked */ 281N/A /* FIXME: exclusive locking will rewrite the index file every 1739N/A time. shouldn't really be needed.. reading doesn't require 281N/A /* Assume flock() is emulated with fcntl(), because that's how most 281N/A "Timeout (%us) while waiting for shared lock for index file %s",
1552N/A /* unlocking some older generation of the index file. 1552N/A we've already closed the file so just ignore this. */ 281N/A /* drop back to a shared lock. */