aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordan <dan@noemail.net>2020-03-30 13:35:05 +0000
committerdan <dan@noemail.net>2020-03-30 13:35:05 +0000
commit892edb69c4f1071b682d88d13be45f7faa980f63 (patch)
tree8bceda36b2f53eb1fa1501a296a04cd6566bb403 /src
parent3e42b9917566acdc67a04b08dbf8fc3227fc785d (diff)
downloadsqlite-892edb69c4f1071b682d88d13be45f7faa980f63.tar.gz
sqlite-892edb69c4f1071b682d88d13be45f7faa980f63.zip
Use __atomic_load_n() and __atomic_store_n() for a few more things where they are available.
FossilOrigin-Name: a49f8ec552bede7da731e0571ccf49de1a30e7be3a5673150436c8b411ba6ffc
Diffstat (limited to 'src')
-rw-r--r--src/btree.c4
-rw-r--r--src/main.c4
-rw-r--r--src/malloc.c4
-rw-r--r--src/sqliteInt.h15
-rw-r--r--src/tokenize.c4
-rw-r--r--src/vdbe.c6
-rw-r--r--src/vdbeapi.c2
-rw-r--r--src/vdbeaux.c2
-rw-r--r--src/wal.c14
9 files changed, 29 insertions, 26 deletions
diff --git a/src/btree.c b/src/btree.c
index 083968391..20bb7c7d9 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -9530,7 +9530,7 @@ int sqlite3BtreeCount(sqlite3 *db, BtCursor *pCur, i64 *pnEntry){
/* Unless an error occurs, the following loop runs one iteration for each
** page in the B-Tree structure (not including overflow pages).
*/
- while( rc==SQLITE_OK && !db->u1.isInterrupted ){
+ while( rc==SQLITE_OK && !AtomicLoad(&db->u1.isInterrupted) ){
int iIdx; /* Index of child node in parent */
MemPage *pPage; /* Current page of the b-tree */
@@ -9656,7 +9656,7 @@ static int checkRef(IntegrityCk *pCheck, Pgno iPage){
checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
return 1;
}
- if( pCheck->db->u1.isInterrupted ) return 1;
+ if( AtomicLoad(&pCheck->db->u1.isInterrupted) ) return 1;
setPageReferenced(pCheck, iPage);
return 0;
}
diff --git a/src/main.c b/src/main.c
index 9491eb4b1..d693621b1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1733,7 +1733,7 @@ void sqlite3_interrupt(sqlite3 *db){
return;
}
#endif
- db->u1.isInterrupted = 1;
+ AtomicStore(&db->u1.isInterrupted, 1);
}
@@ -2355,7 +2355,7 @@ int sqlite3_wal_checkpoint_v2(
/* If there are no active statements, clear the interrupt flag at this
** point. */
if( db->nVdbeActive==0 ){
- db->u1.isInterrupted = 0;
+ AtomicStore(&db->u1.isInterrupted, 0);
}
sqlite3_mutex_leave(db->mutex);
diff --git a/src/malloc.c b/src/malloc.c
index 9dd400a3b..a19d8bdfb 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -760,7 +760,7 @@ void sqlite3OomFault(sqlite3 *db){
if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
db->mallocFailed = 1;
if( db->nVdbeExec>0 ){
- db->u1.isInterrupted = 1;
+ AtomicStore(&db->u1.isInterrupted, 1);
}
DisableLookaside;
if( db->pParse ){
@@ -779,7 +779,7 @@ void sqlite3OomFault(sqlite3 *db){
void sqlite3OomClear(sqlite3 *db){
if( db->mallocFailed && db->nVdbeExec==0 ){
db->mallocFailed = 0;
- db->u1.isInterrupted = 0;
+ AtomicStore(&db->u1.isInterrupted, 0);
assert( db->lookaside.bDisable>0 );
EnableLookaside;
}
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 489768bbc..d08c7ce1e 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -187,6 +187,21 @@
#endif
/*
+** WAL mode depends on atomic aligned 32-bit loads and stores in a few
+** places. The following macros try to make this explicit.
+*/
+#ifndef __has_feature
+# define __has_feature(x) 0 /* compatibility with non-clang compilers */
+#endif
+#if GCC_VERSION>=4007000 || __has_feature(c_atomic)
+# define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED)
+# define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED)
+#else
+# define AtomicLoad(PTR) (*(PTR))
+# define AtomicStore(PTR,VAL) (*(PTR) = (VAL))
+#endif
+
+/*
** Include standard header files as necessary
*/
#ifdef HAVE_STDINT_H
diff --git a/src/tokenize.c b/src/tokenize.c
index 48f92218d..8467c0ffe 100644
--- a/src/tokenize.c
+++ b/src/tokenize.c
@@ -568,7 +568,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
assert( zSql!=0 );
mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
if( db->nVdbeActive==0 ){
- db->u1.isInterrupted = 0;
+ AtomicStore(&db->u1.isInterrupted, 0);
}
pParse->rc = SQLITE_OK;
pParse->zTail = zSql;
@@ -613,7 +613,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
if( tokenType>=TK_SPACE ){
assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
#endif /* SQLITE_OMIT_WINDOWFUNC */
- if( db->u1.isInterrupted ){
+ if( AtomicLoad(&db->u1.isInterrupted) ){
pParse->rc = SQLITE_INTERRUPT;
break;
}
diff --git a/src/vdbe.c b/src/vdbe.c
index 7f0532866..1f1d352cd 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -707,7 +707,7 @@ int sqlite3VdbeExec(
assert( p->explain==0 );
p->pResultSet = 0;
db->busyHandler.nBusy = 0;
- if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
+ if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
sqlite3VdbeIOTraceSql(p);
#ifdef SQLITE_DEBUG
sqlite3BeginBenignMalloc();
@@ -891,7 +891,7 @@ jump_to_p2_and_check_for_interrupt:
** checks on every opcode. This helps sqlite3_step() to run about 1.5%
** faster according to "valgrind --tool=cachegrind" */
check_for_interrupt:
- if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
+ if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
/* Call the progress callback if it is configured and the required number
** of VDBE ops have been executed (either since this invocation of
@@ -7999,7 +7999,7 @@ no_mem:
** flag.
*/
abort_due_to_interrupt:
- assert( db->u1.isInterrupted );
+ assert( AtomicLoad(&db->u1.isInterrupted) );
rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
p->rc = rc;
sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index 074d45881..4337a33a5 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -663,7 +663,7 @@ static int sqlite3Step(Vdbe *p){
** from interrupting a statement that has not yet started.
*/
if( db->nVdbeActive==0 ){
- db->u1.isInterrupted = 0;
+ AtomicStore(&db->u1.isInterrupted, 0);
}
assert( db->nVdbeWrite>0 || db->autoCommit==0
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index e18a811b6..cfddc0f61 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -2093,7 +2093,7 @@ int sqlite3VdbeList(
}
if( rc==SQLITE_OK ){
- if( db->u1.isInterrupted ){
+ if( AtomicLoad(&db->u1.isInterrupted) ){
p->rc = SQLITE_INTERRUPT;
rc = SQLITE_ERROR;
sqlite3VdbeError(p, sqlite3ErrStr(p->rc));
diff --git a/src/wal.c b/src/wal.c
index 9fbc0e18a..3e4f4acfd 100644
--- a/src/wal.c
+++ b/src/wal.c
@@ -259,18 +259,6 @@ int sqlite3WalTrace = 0;
#endif
/*
-** WAL mode depends on atomic aligned 32-bit loads and stores in a few
-** places. The following macros try to make this explicit.
-*/
-#if GCC_VERSION>=5004000
-# define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED)
-# define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED)
-#else
-# define AtomicLoad(PTR) (*(PTR))
-# define AtomicStore(PTR,VAL) (*(PTR) = (VAL))
-#endif
-
-/*
** The maximum (and only) versions of the wal and wal-index formats
** that may be interpreted by this version of SQLite.
**
@@ -1891,7 +1879,7 @@ static int walCheckpoint(
while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
i64 iOffset;
assert( walFramePgno(pWal, iFrame)==iDbpage );
- if( db->u1.isInterrupted ){
+ if( AtomicLoad(&db->u1.isInterrupted) ){
rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
break;
}