Updating trunk VERSION from 1010.0 to 1011.0
[chromium-blink-merge.git] / net / disk_cache / file_lock.h
blobad8e5392ed38a2bd38dc0759c5765e72a0ee8cb7
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // See net/disk_cache/disk_cache.h for the public interface of the cache.
7 #ifndef NET_DISK_CACHE_FILE_LOCK_H__
8 #define NET_DISK_CACHE_FILE_LOCK_H__
9 #pragma once
11 #include "net/base/net_export.h"
12 #include "net/disk_cache/disk_format.h"
14 namespace disk_cache {
16 // This class implements a file lock that lives on the header of a memory mapped
17 // file. This is NOT a thread related lock, it is a lock to detect corruption
18 // of the file when the process crashes in the middle of an update.
19 // The lock is acquired on the constructor and released on the destructor.
20 // The typical use of the class is:
21 // {
22 // BlockFileHeader* header = GetFileHeader();
23 // FileLock lock(header);
24 // header->max_entries = num_entries;
25 // // At this point the destructor is going to release the lock.
26 // }
27 // It is important to perform Lock() and Unlock() operations in the right order,
28 // because otherwise the desired effect of the "lock" will not be achieved. If
29 // the operations are inlined / optimized, the "locked" operations can happen
30 // outside the lock.
31 class NET_EXPORT_PRIVATE FileLock {
32 public:
33 explicit FileLock(BlockFileHeader* header);
34 virtual ~FileLock();
36 // Virtual to make sure the compiler never inlines the calls.
37 virtual void Lock();
38 virtual void Unlock();
39 private:
40 bool acquired_;
41 volatile int32* updating_;
44 } // namespace disk_cache
46 #endif // NET_DISK_CACHE_FILE_LOCK_H__