[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/3.5/kdepim/indexlib
From:       Luís Pedro Coelho <luis () luispedro ! org>
Date:       2005-09-22 13:19:13
Message-ID: 1127395153.753206.31131.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 462957 by luis_pedro:

Correctly set locked_ to false after unlocking
Add documentation


 M  +4 -1      lockfile.cpp  
 M  +14 -0     lockfile.h  


--- branches/KDE/3.5/kdepim/indexlib/lockfile.cpp #462956:462957
@@ -30,6 +30,7 @@
 
 #include "lockfile.h"
 #include "format.h"
+#include "logfile.h"
 #include <iostream>
 #include <fcntl.h>
 #include <unistd.h>
@@ -58,17 +59,19 @@
 		locked_ = true;
 		close( fd );
 	}
-	std::cerr << format( "trylock(%s) returning %s (fd:%s) (error:%s)\n" ) % filename_ \
% locked_ %fd % strerror( errno ); +	logfile() << format( "trylock(%s) returning %s \
(fd:%s) (error:%s)\n" ) % filename_ % locked_ %fd % strerror( errno );  return \
locked_;  }
 
 void lockfile::unlock() {
 	if ( locked() ) {
 		unlink( filename_.c_str() );
+		locked_ = false;
 	}
 }
 
 void lockfile::force_unlock() {
 	unlink( filename_.c_str() );
+	locked_ = false;
 }
 
--- branches/KDE/3.5/kdepim/indexlib/lockfile.h #462956:462957
@@ -35,15 +35,29 @@
 
 namespace indexlib { namespace detail {
 
+/**
+ * Implements a simple, file based lock.
+ *
+ * Given a filename, it can be used to ensure that only one such file is in use at \
the time. + */
 class lockfile {
 	public:
+		/** Creates the object, doesn't actually do anything */
 		explicit lockfile( std::string name );
+
+		/** if locked, unlocks */
 		~lockfile();
 
+		/** Returns whether the file is locked */
 		bool locked() const;
+
+		/** Tries to lock the file returning true in case of success */
 		bool trylock();
+
+		/** Unlocks if you own the lock, otherwise it's a nop. */
 		void unlock();
 
+		/** This removes the lock, no matter what. */
 		void force_unlock();
 	private:
 		std::string filename_;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic