webrtc_m130/webrtc/base/filelock.h
Thiago Farina ae0f0ee79e Cleanup: Remove DISALLOW_EVIL_CONSTRUCTORS macro.
Just use the less-evil version, DISALLOW_COPY_AND_ASSIGN macro.

This should help with my TODO in
https://chromium.googlesource.com/chromium/src/+/master/base/macros.h#33

Tested on Linux with the following command lines:

$ rm -rf out/
$ gn gen //out/Debug --args='is_debug=true target_cpu="x64" build_with_chromium=false'
$ ninja -C out/Debug

BUG=None
TEST=see above
R=tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/50599004

Patch from Thiago Farina <tfarina@chromium.org>.

Cr-Commit-Position: refs/heads/master@{#8927}
2015-04-04 23:56:56 +00:00

54 lines
1.5 KiB
C++

/*
* Copyright 2009 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_BASE_FILELOCK_H_
#define WEBRTC_BASE_FILELOCK_H_
#include <string>
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/scoped_ptr.h"
namespace rtc {
class FileStream;
// Implements a very simple cross process lock based on a file.
// When Lock(...) is called we try to open/create the file in read/write
// mode without any sharing. (Or locking it with flock(...) on Unix)
// If the process crash the OS will make sure that the file descriptor
// is released and another process can accuire the lock.
// This doesn't work on ancient OSX/Linux versions if used on NFS.
// (Nfs-client before: ~2.6 and Linux Kernel < 2.6.)
class FileLock {
public:
virtual ~FileLock();
// Attempts to lock the file. The caller owns the returned
// lock object. Returns NULL if the file already was locked.
static FileLock* TryLock(const std::string& path);
void Unlock();
protected:
FileLock(const std::string& path, FileStream* file);
private:
void MaybeUnlock();
std::string path_;
scoped_ptr<FileStream> file_;
DISALLOW_COPY_AND_ASSIGN(FileLock);
};
} // namespace rtc
#endif // WEBRTC_BASE_FILELOCK_H_