You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/06/19 23:58:50 UTC
svn commit: r1351874 - /incubator/mesos/trunk/src/linux/fs.cpp
Author: benh
Date: Tue Jun 19 21:58:50 2012
New Revision: 1351874
URL: http://svn.apache.org/viewvc?rev=1351874&view=rev
Log:
Fix locks in linux/fs.cpp (contributed by Charles Reiss, https://reviews.apache.org/r/5403).
Modified:
incubator/mesos/trunk/src/linux/fs.cpp
Modified: incubator/mesos/trunk/src/linux/fs.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/linux/fs.cpp?rev=1351874&r1=1351873&r2=1351874&view=diff
==============================================================================
--- incubator/mesos/trunk/src/linux/fs.cpp (original)
+++ incubator/mesos/trunk/src/linux/fs.cpp Tue Jun 19 21:58:50 2012
@@ -33,9 +33,10 @@ namespace fs {
// Lock for guarding accesses to fstab functions.
-static Lock* fstabLock = new Lock(new pthread_mutex_t);
+static pthread_mutex_t fstabMutex = PTHREAD_MUTEX_INITIALIZER;
+
// Lock for guarding accesses to mntent functions.
-static Lock* mntentLock = new Lock(new pthread_mutex_t);
+static pthread_mutex_t mntentMutex = PTHREAD_MUTEX_INITIALIZER;
bool MountTable::Entry::hasOption(const std::string& option)
@@ -81,8 +82,8 @@ Try<MountTable> MountTable::read(const s
table.entries.push_back(entry);
#else
// Reentrant version does not exist. Use locks.
- mntentLock->lock();
{
+ Lock lock(&mntentLock);
struct mntent* mntent = ::getmntent(file);
if (mntent == NULL) {
// NULL means the end of enties.
@@ -98,7 +99,6 @@ Try<MountTable> MountTable::read(const s
mntent->mnt_passno);
table.entries.push_back(entry);
}
- mntentLock->unlock();
#endif
}
@@ -113,11 +113,11 @@ Try<FileSystemTable> FileSystemTable::re
FileSystemTable table;
// Use locks since fstab functions are not thread-safe.
- fstabLock->lock();
{
+ Lock lock(&fstabMutex);
+
// Open file _PATH_FSTAB (/etc/fstab).
if (::setfsent() == 0) {
- fstabLock->unlock();
return Try<FileSystemTable>::error("Failed to open file system table");
}
@@ -140,7 +140,6 @@ Try<FileSystemTable> FileSystemTable::re
::endfsent();
}
- fstabLock->unlock();
return table;
}