summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/sql
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-08-04 11:41:34 +0100
committerSteve Block <steveblock@google.com>2010-08-09 12:04:44 +0100
commitdb14019a23d96bc8a444b6576a5da8bd1cfbc8b0 (patch)
tree9f793c5b0f5e1f2aca8247158920e2c4bf962bbf /WebCore/platform/sql
parentbf916837aa84f1e4b00e6ed6268516c2acd27545 (diff)
downloadexternal_webkit-db14019a23d96bc8a444b6576a5da8bd1cfbc8b0.zip
external_webkit-db14019a23d96bc8a444b6576a5da8bd1cfbc8b0.tar.gz
external_webkit-db14019a23d96bc8a444b6576a5da8bd1cfbc8b0.tar.bz2
Merge WebKit at r64523 : Initial merge by git.
Change-Id: Ibb796c6802e757b1d9b40f58205cfbe4da95fcd4
Diffstat (limited to 'WebCore/platform/sql')
-rw-r--r--WebCore/platform/sql/SQLiteDatabase.cpp43
-rw-r--r--WebCore/platform/sql/SQLiteDatabase.h11
-rw-r--r--WebCore/platform/sql/SQLiteStatement.cpp10
3 files changed, 46 insertions, 18 deletions
diff --git a/WebCore/platform/sql/SQLiteDatabase.cpp b/WebCore/platform/sql/SQLiteDatabase.cpp
index 75fc032..05a2a22 100644
--- a/WebCore/platform/sql/SQLiteDatabase.cpp
+++ b/WebCore/platform/sql/SQLiteDatabase.cpp
@@ -31,8 +31,8 @@
#include "Logging.h"
#include "SQLiteFileSystem.h"
#include "SQLiteStatement.h"
-
#include <sqlite3.h>
+#include <wtf/Threading.h>
namespace WebCore {
@@ -42,7 +42,7 @@ const int SQLResultOk = SQLITE_OK;
const int SQLResultRow = SQLITE_ROW;
const int SQLResultSchema = SQLITE_SCHEMA;
const int SQLResultFull = SQLITE_FULL;
-
+const int SQLResultInterrupt = SQLITE_INTERRUPT;
SQLiteDatabase::SQLiteDatabase()
: m_db(0)
@@ -50,6 +50,7 @@ SQLiteDatabase::SQLiteDatabase()
, m_transactionInProgress(false)
, m_sharable(false)
, m_openingThread(0)
+ , m_interrupted(false)
{
}
@@ -85,13 +86,37 @@ void SQLiteDatabase::close()
if (m_db) {
// FIXME: This is being called on themain thread during JS GC. <rdar://problem/5739818>
// ASSERT(currentThread() == m_openingThread);
- sqlite3_close(m_db);
- m_db = 0;
+ sqlite3* db = m_db;
+ {
+ MutexLocker locker(m_databaseClosingMutex);
+ m_db = 0;
+ }
+ sqlite3_close(db);
}
m_openingThread = 0;
}
+void SQLiteDatabase::interrupt()
+{
+ m_interrupted = true;
+ while (!m_lockingMutex.tryLock()) {
+ MutexLocker locker(m_databaseClosingMutex);
+ if (!m_db)
+ return;
+ sqlite3_interrupt(m_db);
+ yield();
+ }
+
+ m_lockingMutex.unlock();
+}
+
+bool SQLiteDatabase::isInterrupted()
+{
+ ASSERT(!m_lockingMutex.tryLock());
+ return m_interrupted;
+}
+
void SQLiteDatabase::setFullsync(bool fsync)
{
if (fsync)
@@ -397,16 +422,6 @@ void SQLiteDatabase::enableAuthorizer(bool enable)
sqlite3_set_authorizer(m_db, NULL, 0);
}
-void SQLiteDatabase::lock()
-{
- m_lockingMutex.lock();
-}
-
-void SQLiteDatabase::unlock()
-{
- m_lockingMutex.unlock();
-}
-
bool SQLiteDatabase::isAutoCommitOn() const
{
return sqlite3_get_autocommit(m_db);
diff --git a/WebCore/platform/sql/SQLiteDatabase.h b/WebCore/platform/sql/SQLiteDatabase.h
index c5924c0..8151380 100644
--- a/WebCore/platform/sql/SQLiteDatabase.h
+++ b/WebCore/platform/sql/SQLiteDatabase.h
@@ -48,6 +48,7 @@ extern const int SQLResultOk;
extern const int SQLResultRow;
extern const int SQLResultSchema;
extern const int SQLResultFull;
+extern const int SQLResultInterrupt;
class SQLiteDatabase : public Noncopyable {
friend class SQLiteTransaction;
@@ -58,6 +59,8 @@ public:
bool open(const String& filename, bool forWebSQLDatabase = false);
bool isOpen() const { return m_db; }
void close();
+ void interrupt();
+ bool isInterrupted();
bool executeCommand(const String&);
bool returnsAtLeastOneResult(const String&);
@@ -105,9 +108,7 @@ public:
void setAuthorizer(PassRefPtr<DatabaseAuthorizer>);
- // (un)locks the database like a mutex
- void lock();
- void unlock();
+ Mutex& databaseMutex() { return m_lockingMutex; }
bool isAutoCommitOn() const;
// The SQLite AUTO_VACUUM pragma can be either NONE, FULL, or INCREMENTAL.
@@ -149,7 +150,9 @@ private:
Mutex m_lockingMutex;
ThreadIdentifier m_openingThread;
-
+
+ Mutex m_databaseClosingMutex;
+ bool m_interrupted;
}; // class SQLiteDatabase
} // namespace WebCore
diff --git a/WebCore/platform/sql/SQLiteStatement.cpp b/WebCore/platform/sql/SQLiteStatement.cpp
index 78bbfeb..ac467a6 100644
--- a/WebCore/platform/sql/SQLiteStatement.cpp
+++ b/WebCore/platform/sql/SQLiteStatement.cpp
@@ -61,6 +61,11 @@ SQLiteStatement::~SQLiteStatement()
int SQLiteStatement::prepare()
{
ASSERT(!m_isPrepared);
+
+ MutexLocker databaseLock(m_database.databaseMutex());
+ if (m_database.isInterrupted())
+ return SQLITE_INTERRUPT;
+
const void* tail = 0;
LOG(SQLDatabase, "SQL - prepare - %s", m_query.ascii().data());
String strippedQuery = m_query.stripWhiteSpace();
@@ -88,6 +93,11 @@ int SQLiteStatement::prepare()
int SQLiteStatement::step()
{
ASSERT(m_isPrepared);
+
+ MutexLocker databaseLock(m_database.databaseMutex());
+ if (m_database.isInterrupted())
+ return SQLITE_INTERRUPT;
+
if (!m_statement)
return SQLITE_OK;
LOG(SQLDatabase, "SQL - step - %s", m_query.ascii().data());