// NOTE: Locks applied using flock(2) and fcntl(2) are oblivious // to each other, so attempting to query locks set by flock using // using fcntl(,F_GETLK,) will not work. see kernel doc at // Documentation/filesystems/locks.txt.
{
ScopedFlock file_lock = LockedFile::Open(scratch_file.GetFilename().c_str(),
&error_msg);
ASSERT_TRUE(file_lock.get() != nullptr);
// Attempt to acquire a second lock on the same file. This must fail.
ScopedFlock second_lock = LockedFile::Open(scratch_file.GetFilename().c_str(),
O_RDONLY, /* block= */ false,
&error_msg);
ASSERT_TRUE(second_lock.get() == nullptr);
ASSERT_TRUE(!error_msg.empty());
}
{ // Attempt to reacquire the lock once the first lock has been released, this // must succeed.
ScopedFlock file_lock = LockedFile::Open(scratch_file.GetFilename().c_str(),
&error_msg);
ASSERT_TRUE(file_lock.get() != nullptr);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.