added sqlite busy handler: retries on locking conflicts
authorMartin Willi <martin@strongswan.org>
Thu, 21 Aug 2008 09:25:06 +0000 (09:25 -0000)
committerMartin Willi <martin@strongswan.org>
Thu, 21 Aug 2008 09:25:06 +0000 (09:25 -0000)
src/libstrongswan/plugins/sqlite/sqlite_database.c

index c1927b5..2d41219 100644 (file)
@@ -18,6 +18,7 @@
 #include "sqlite_database.h"
 
 #include <sqlite3.h>
+#include <unistd.h>
 #include <library.h>
 #include <debug.h>
 #include <utils/mutex.h>
@@ -290,6 +291,17 @@ static db_driver_t get_driver(private_sqlite_database_t *this)
 }
 
 /**
+ * Busy handler implementation
+ */
+static int busy_handler(private_sqlite_database_t *this, int count)
+{
+       /* add an sleep, exponentially longer on every try */
+       usleep(count * count * 1000);
+       /* always retry */
+       return 1;
+}
+
+/**
  * Implementation of database_t.destroy
  */
 static void destroy(private_sqlite_database_t *this)
@@ -333,6 +345,8 @@ sqlite_database_t *sqlite_database_create(char *uri)
                return NULL;
        }
        
+       sqlite3_busy_handler(this->db, (void*)busy_handler, this);
+       
        return &this->public;
 }