added sqlite busy handler: retries on locking conflicts

This commit is contained in:
Martin Willi 2008-08-21 09:25:06 +00:00
parent 02e907fe66
commit 2d6559b107
1 changed files with 14 additions and 0 deletions

View 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>
@ -289,6 +290,17 @@ static db_driver_t get_driver(private_sqlite_database_t *this)
return DB_SQLITE;
}
/**
* 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
*/
@ -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;
}