[fusion-commits] Compiz configuration system library: Changes to 'master' (7e114a16b845796538c8803885b09bdab8454de9)

onestone at server.beryl-project.org onestone at server.beryl-project.org
Tue Jul 10 11:34:28 CEST 2007


New commits:
commit 7e114a16b845796538c8803885b09bdab8454de9
Author: Dennis Kasprzyk <onestone at opencompositing.org>
Date:   Tue Jul 10 11:34:23 2007 +0200

    Revert "Use flock for file locking. (seams to be more stable)"
    - fcntl has much better performance
    
    This reverts commit c8a0d9f5777adf9615ca8628e64f1718345a0ae6.


 src/iniparser.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)


Modified: fusion/compizconfig/libcompizconfig/src/iniparser.c
===================================================================
--- fusion/compizconfig/libcompizconfig/src/iniparser.c
+++ fusion/compizconfig/libcompizconfig/src/iniparser.c
@@ -53,15 +53,19 @@ ini_file_lock (const char *fileName)
 {
     int          fd;
     FileLock     *lock;
+    struct flock lockinfo;
 
-    fd = open (fileName, O_RDONLY | O_CREAT);
+    fd = open (fileName, O_WRONLY | O_CREAT);
     if (fd < 0)
 	return NULL;
 
     lock = malloc (sizeof (FileLock));
     lock ->fd = fd;
+    memset (&lockinfo, 0, sizeof (struct flock));
 
-    flock (fd, LOCK_EX);
+    lockinfo.l_type = F_WRLCK;
+    lockinfo.l_pid = getpid();
+    fcntl (fd, F_SETLKW, &lockinfo);
 
     return lock;
 }
@@ -69,7 +73,13 @@ ini_file_lock (const char *fileName)
 static void
 ini_file_unlock (FileLock *lock)
 {
-    flock (lock->fd, LOCK_UN);
+    struct flock lockinfo;
+
+    memset (&lockinfo, 0, sizeof (struct flock));
+    lockinfo.l_type = F_UNLCK;
+    lockinfo.l_pid = getpid();
+
+    fcntl (lock ->fd, F_SETLKW, &lockinfo);
     close (lock ->fd);
     free (lock );
 }


More information about the commits mailing list