aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-09-06 02:51:04 +0000
committerdrh <drh@noemail.net>2015-09-06 02:51:04 +0000
commit6081c1dbdf7730752bbde89ebb17d01bb30bf8f0 (patch)
treee82661b7eaaab7bde1934ddb05ecd9cdd9a2da60 /src
parent0b8d255c37ea9830cecabb57f1c2ba6305eacc44 (diff)
downloadsqlite-6081c1dbdf7730752bbde89ebb17d01bb30bf8f0.tar.gz
sqlite-6081c1dbdf7730752bbde89ebb17d01bb30bf8f0.zip
Add a memory barrier to the mutex initialization logic, try to work around
an issue reported by WebKit. FossilOrigin-Name: 11a9a786ec06403addb47f5c6fb142b382fae522
Diffstat (limited to 'src')
-rw-r--r--src/mutex.c1
-rw-r--r--src/mutex.h1
-rw-r--r--src/mutex_unix.c12
-rw-r--r--src/mutex_w32.c7
-rw-r--r--src/sqliteInt.h1
5 files changed, 22 insertions, 0 deletions
diff --git a/src/mutex.c b/src/mutex.c
index 64efd3b05..a2e4e6387 100644
--- a/src/mutex.c
+++ b/src/mutex.c
@@ -53,6 +53,7 @@ int sqlite3MutexInit(void){
pTo->xMutexLeave = pFrom->xMutexLeave;
pTo->xMutexHeld = pFrom->xMutexHeld;
pTo->xMutexNotheld = pFrom->xMutexNotheld;
+ sqlite3MemoryBarrier();
pTo->xMutexAlloc = pFrom->xMutexAlloc;
}
rc = sqlite3GlobalConfig.mutex.xMutexInit();
diff --git a/src/mutex.h b/src/mutex.h
index 03eb1faad..8bcf2353f 100644
--- a/src/mutex.h
+++ b/src/mutex.h
@@ -64,6 +64,7 @@
#define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
#define sqlite3MutexInit() SQLITE_OK
#define sqlite3MutexEnd()
+#define sqlite3MemoryBarrier()
#define MUTEX_LOGIC(X)
#else
#define MUTEX_LOGIC(X) X
diff --git a/src/mutex_unix.c b/src/mutex_unix.c
index 0a493fa6a..e181ba5bd 100644
--- a/src/mutex_unix.c
+++ b/src/mutex_unix.c
@@ -81,6 +81,18 @@ static int pthreadMutexNotheld(sqlite3_mutex *p){
#endif
/*
+** Try to provide a memory barrier operation, needed for initialization only.
+*/
+void sqlite3MemoryBarrier(void){
+#if defined(__GNUC__)
+ __sync_synchronize();
+#endif
+#ifdef SQLITE_MEMORY_BARRIER
+ SQLITE_MEMORY_BARRIER;
+#endif
+}
+
+/*
** Initialize and deinitialize the mutex subsystem.
*/
static int pthreadMutexInit(void){ return SQLITE_OK; }
diff --git a/src/mutex_w32.c b/src/mutex_w32.c
index fc943acaa..9f2fb048f 100644
--- a/src/mutex_w32.c
+++ b/src/mutex_w32.c
@@ -78,6 +78,13 @@ static int winMutexNotheld(sqlite3_mutex *p){
#endif
/*
+** Try to provide a memory barrier operation, needed for initialization only.
+*/
+void sqlite3MemoryBarrier(void){
+ MemoryBarrier();
+}
+
+/*
** Initialize and deinitialize the mutex subsystem.
*/
static sqlite3_mutex winMutex_staticMutexes[] = {
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 89b3d798f..eeb0b9950 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -3191,6 +3191,7 @@ const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
sqlite3_mutex *sqlite3MutexAlloc(int);
int sqlite3MutexInit(void);
int sqlite3MutexEnd(void);
+ void sqlite3MemoryBarrier(void);
#endif
sqlite3_int64 sqlite3StatusValue(int);