Compare commits

...

15 Commits

Author SHA1 Message Date
mistachkin 07bfe57ebd Merge updates from trunk.
FossilOrigin-Name: a447cf90ddfd2930274f58de4bae3b07f2886632
2015-10-15 21:12:27 +00:00
mistachkin 24271dc24b Correct superfluous whitespace difference. No functional changes.
FossilOrigin-Name: 8d69983dc2b94ca752259dcec360c32d60a8e9dd
2015-09-23 16:33:44 +00:00
mistachkin ffce11ae54 Simplify thread-safety of mutex initialization.
FossilOrigin-Name: da0587c522163833e5e542f7722aeb69b3183ac1
2015-09-23 16:24:19 +00:00
mistachkin 4221e628c1 Merge updates from trunk.
FossilOrigin-Name: 6b85f8cd4d87d616a3cb362647ae3869c45c2801
2015-09-23 15:54:36 +00:00
mistachkin 5c870cb03c Experimental changes to avoid recusrively calling xMutexInit.
FossilOrigin-Name: c9400ff167d9520119081c9b92436794dcd53d22
2015-09-13 18:45:50 +00:00
mistachkin b25754a62d Merge updates from trunk.
FossilOrigin-Name: b42c2e2076da1a61f667876ff2c18e4ebed50a7f
2015-09-13 18:43:53 +00:00
mistachkin e7c4184348 Merge updates from trunk.
FossilOrigin-Name: d8051f611acabc2aaf8d23e8707c2a45961be416
2015-09-12 18:58:32 +00:00
mistachkin aa985b3208 Merge updates from trunk.
FossilOrigin-Name: 4859778900a99e7e50ce3d56910ad4c5469f2cdb
2015-09-12 16:59:38 +00:00
mistachkin 3f44c65513 Fix comments.
FossilOrigin-Name: de3fa51e931d34f341fc3432bfdf97390bb68d4e
2015-09-12 04:22:01 +00:00
mistachkin acc8f7b24c Specifying an invalid mutex implementation (via SQLITE_CONFIG_MUTEX) should cause the default one to be used instead.
FossilOrigin-Name: 1a97bc81ccfc88f2dd527dff16e9e395718675bc
2015-09-12 04:19:51 +00:00
mistachkin a4da3c17c3 Clarify the new mutex implementation reset logic in sqlite3_shutdown().
FossilOrigin-Name: f9a034834e6c6e32ac350cf48bec981490e533ad
2015-09-12 03:40:13 +00:00
mistachkin 89e57dd671 Add more asserts to the mutex subsystem.
FossilOrigin-Name: 7562f1fbede70b19bbbb928e0a534203528b5b65
2015-09-12 03:35:55 +00:00
mistachkin db17a83295 Fix typo in the Win32 implementation of sqlite3CompareAndSwap.
FossilOrigin-Name: 31a26a1dd796e073e847e1e9c636f1976ffbb085
2015-09-12 01:17:20 +00:00
mistachkin 4b3f0d6281 Make sure that the mutex implementation can be altered after calling sqlite3_shutdown().
FossilOrigin-Name: dc2cf8974337ca1ef705aee4efd4a96b91ca3edd
2015-09-11 23:24:50 +00:00
mistachkin 8bdc914af3 Enhance mutex initialization to prevent possible race conditions between sqlite3_initialize() and sqlite3_config(). Also, re-check sqlite3GlobalConfig.isInit after the mutex subsystem has been initialized.
FossilOrigin-Name: f6a8f577957769171acd72df3cc9aa5ad474d84b
2015-09-11 05:06:15 +00:00
8 changed files with 129 additions and 27 deletions
+12 -12
View File
@@ -1,5 +1,5 @@
C Enhance\sthe\suse\sof\sthe\scolumn\scache\sfor\sUPDATE\sstatements,\smaking\sthem\nmore\sefficient\sfor\sthe\scase\swhere\sa\scolumn\sis\smodified\sto\sbe\san\sexpression\nof\sother\sunmodified\scolumns.
D 2015-10-15T19:21:51.254
C Merge\supdates\sfrom\strunk.
D 2015-10-15T21:12:27.435
F Makefile.in 2ea961bc09e441874eb3d1bf7398e04feb24f3ee
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 8e42cb55739cd8c12e1fd25401956e2019448f6a
@@ -303,7 +303,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e
F src/lempar.c d344a95d60c24e2f490ee59db9784b1b17439012
F src/loadext.c 18586e45a215325f15096821e9c082035d4fb810
F src/main.c fec97668771438033a7559883401067b139729e1
F src/main.c 2082c1c7aa1687849848581e084f6046c503841d
F src/malloc.c 0a2e42b835c980ba91c17866e9b6a9810ff54d75
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 52485a88f22649c3b3b4f3eb15760505d49ccf71
@@ -312,11 +312,11 @@ F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a
F src/mem5.c c1ab1153bd6443bdf6f71e4213c6fb31221b9eb7
F src/memjournal.c 3eb2c0b51adbd869cb6a44780323f05fa904dc85
F src/msvc.h d9ba56c6851227ab44b3f228a35f3f5772296495
F src/mutex.c 8e45800ee78e0cd1f1f3fe8e398853307f4a085c
F src/mutex.c 40dc52f7525fa86f35dff2a7c9b6e6870240952a
F src/mutex.h 779d588e3b7756ec3ecf7d78cde1d84aba414f85
F src/mutex_noop.c 9d4309c075ba9cc7249e19412d3d62f7f94839c4
F src/mutex_unix.c a94b46f3f7beba307dde1b298b0f99f9c3677a93
F src/mutex_w32.c 5e6fe1c298fb5a8a15aaed4161d5759311431c17
F src/mutex_noop.c f03e26ba8258399da23b51234f6b6a97197c1900
F src/mutex_unix.c 77d84839735aec71f9fe731bfd845d81cec2bb65
F src/mutex_w32.c c3a5049bc413dd8321480b28f275fbf2b99c846e
F src/notify.c 9711a7575036f0d3040ba61bc6e217f13a9888e7
F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8
F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf
@@ -343,7 +343,7 @@ F src/shell.c d25df04168d6ba5a4fa05bdbf859df667f9eb621
F src/sqlite.h.in 839c818e16ea68703d90d17bd2bb3607191debce
F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
F src/sqlite3ext.h 4b66e3e3435da4b4c8c83696d0349f0c503b3924
F src/sqliteInt.h 1ad779ee62efee60494af0a75d8d45592f9f53c3
F src/sqliteInt.h 2d82464793c7d07b01dfcdc43942a27063ea398d
F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46
F src/status.c 286f6398a4d2cd1e8ff0771e3d30f8dddb4768ea
F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e
@@ -1391,7 +1391,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 3a2f73a4924860fde8ee41ad646e7a02d29ad9d5
R 16722b48de28ae59c1a22e712b62a0b0
U drh
Z fcd4e595e3a40ac192e62fadc88a95a3
P 8d69983dc2b94ca752259dcec360c32d60a8e9dd 871e091df651b2275a672c35ff938bd4b6db0d7f
R 2967669474e0bc8a932a9ea55508690e
U mistachkin
Z 30c10e55f7847c468e81b5b9567db928
+1 -1
View File
@@ -1 +1 @@
871e091df651b2275a672c35ff938bd4b6db0d7f
a447cf90ddfd2930274f58de4bae3b07f2886632
+6 -2
View File
@@ -391,14 +391,18 @@ int sqlite3_config(int op, ...){
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
case SQLITE_CONFIG_MUTEX: {
/* Specify an alternative mutex implementation */
sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
sqlite3MutexCopy(&sqlite3GlobalConfig.mutex,
va_arg(ap, sqlite3_mutex_methods*));
sqlite3MemoryBarrier();
break;
}
#endif
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */
case SQLITE_CONFIG_GETMUTEX: {
/* Retrieve the current mutex implementation */
*va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
sqlite3MemoryBarrier();
sqlite3MutexCopy(va_arg(ap, sqlite3_mutex_methods*),
&sqlite3GlobalConfig.mutex);
break;
}
#endif
+26 -12
View File
@@ -26,35 +26,49 @@ static SQLITE_WSD int mutexIsInit = 0;
#ifndef SQLITE_MUTEX_OMIT
/*
** Copies a mutex implementation. Both arguments must point to valid
** memory.
*/
void sqlite3MutexCopy(
sqlite3_mutex_methods *pTo,
sqlite3_mutex_methods const *pFrom
){
pTo->xMutexInit = pFrom->xMutexInit;
pTo->xMutexEnd = pFrom->xMutexEnd;
pTo->xMutexFree = pFrom->xMutexFree;
pTo->xMutexEnter = pFrom->xMutexEnter;
pTo->xMutexTry = pFrom->xMutexTry;
pTo->xMutexLeave = pFrom->xMutexLeave;
pTo->xMutexHeld = pFrom->xMutexHeld;
pTo->xMutexNotheld = pFrom->xMutexNotheld;
pTo->xMutexAlloc = pFrom->xMutexAlloc;
}
/*
** Initialize the mutex system.
*/
int sqlite3MutexInit(void){
int rc = SQLITE_OK;
if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){
int rc;
sqlite3MemoryBarrier();
if( sqlite3CompareAndSwap(
(void * volatile *)&sqlite3GlobalConfig.mutex.xMutexAlloc,
0, sqlite3GlobalConfig.mutex.xMutexAlloc)==0 ){
/* If the xMutexAlloc method has not been set, then the user did not
** install a mutex implementation via sqlite3_config() prior to
** sqlite3_initialize() being called. This block copies pointers to
** the default implementation into the sqlite3GlobalConfig structure.
*/
sqlite3_mutex_methods const *pFrom;
sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex;
if( sqlite3GlobalConfig.bCoreMutex ){
pFrom = sqlite3DefaultMutex();
}else{
pFrom = sqlite3NoopMutex();
}
pTo->xMutexInit = pFrom->xMutexInit;
pTo->xMutexEnd = pFrom->xMutexEnd;
pTo->xMutexFree = pFrom->xMutexFree;
pTo->xMutexEnter = pFrom->xMutexEnter;
pTo->xMutexTry = pFrom->xMutexTry;
pTo->xMutexLeave = pFrom->xMutexLeave;
pTo->xMutexHeld = pFrom->xMutexHeld;
pTo->xMutexNotheld = pFrom->xMutexNotheld;
sqlite3MutexCopy(&sqlite3GlobalConfig.mutex, pFrom);
sqlite3MemoryBarrier();
pTo->xMutexAlloc = pFrom->xMutexAlloc;
}
assert( sqlite3GlobalConfig.mutex.xMutexInit );
rc = sqlite3GlobalConfig.mutex.xMutexInit();
+22
View File
@@ -29,6 +29,28 @@
#ifndef SQLITE_MUTEX_OMIT
/*
** Try to provide an atomic compare-and-swap operation on a void pointer,
** needed for initialization only.
*/
void *sqlite3NoopCompareAndSwap(
void *volatile *pCurVal,
void *cmpVal,
void *swapVal
){
/*
** This platform may not have a way to perform an atomic compare-and-swap
** operation; therefore, use the fallback algorithm.
**
** WARNING: This code is almost certainly not thread-safe.
*/
void *oldVal = *pCurVal;
if( oldVal==cmpVal ){
*pCurVal = swapVal;
}
return oldVal;
}
#ifndef SQLITE_DEBUG
/*
** Stub routines for all mutex methods.
+28
View File
@@ -93,6 +93,34 @@ void sqlite3MemoryBarrier(void){
#endif
}
/*
** Try to provide an atomic compare-and-swap operation on a void pointer,
** needed for initialization only.
*/
void *sqlite3CompareAndSwap(
void *volatile *pCurVal,
void *cmpVal,
void *swapVal
){
#if defined(SQLITE_COMPARE_AND_SWAP)
return SQLITE_COMPARE_AND_SWAP(pCurVal, cmpVal, swapVal);
#elif defined(__GNUC__) && GCC_VERSION>=4001000 && SQLITE_PTRSIZE>4
return (void *)__sync_val_compare_and_swap_8(
(u64 volatile *)pCurVal, (u64)cmpVal, (u64)swapVal);
#elif defined(__GNUC__) && GCC_VERSION>=4001000
return (void *)__sync_val_compare_and_swap_4(
(u32 volatile *)pCurVal, (u32)cmpVal, (u32)swapVal);
#else
/*
** This platform may not have a way to perform an atomic compare-and-swap
** operation; therefore, use the fallback algorithm.
**
** WARNING: This code is almost certainly not thread-safe.
*/
return sqlite3NoopCompareAndSwap(pCurVal, cmpVal, swapVal);
#endif
}
/*
** Initialize and deinitialize the mutex subsystem.
*/
+22
View File
@@ -95,6 +95,28 @@ void sqlite3MemoryBarrier(void){
#endif
}
/*
** Try to provide an atomic compare-and-swap operation on a void pointer,
** needed for initialization only.
*/
void *sqlite3CompareAndSwap(
void * volatile *pCurVal,
void *cmpVal,
void *swapVal
){
#if defined(SQLITE_COMPARE_AND_SWAP)
return SQLITE_COMPARE_AND_SWAP(pCurVal, cmpVal, swapVal);
#elif SQLITE_PTRSIZE>4
return (void *)InterlockedCompareExchange64(
(LONGLONG SQLITE_WIN32_VOLATILE *)pCurVal, (LONGLONG)swapVal,
(LONGLONG)cmpVal);
#else
return (void *)InterlockedCompareExchange(
(LONG SQLITE_WIN32_VOLATILE *)pCurVal, (LONG)swapVal,
(LONG)cmpVal);
#endif
}
/*
** Initialize and deinitialize the mutex subsystem.
*/
+12
View File
@@ -3196,15 +3196,27 @@ const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
#ifndef SQLITE_MUTEX_OMIT
sqlite3_mutex_methods const *sqlite3DefaultMutex(void);
sqlite3_mutex_methods const *sqlite3NoopMutex(void);
void *sqlite3NoopCompareAndSwap(void * volatile *, void *, void *);
sqlite3_mutex *sqlite3MutexAlloc(int);
int sqlite3MutexInit(void);
int sqlite3MutexEnd(void);
#endif
#if !defined(SQLITE_MUTEX_OMIT) && !defined(SQLITE_MUTEX_NOOP)
void sqlite3MutexCopy(sqlite3_mutex_methods *, sqlite3_mutex_methods const *);
void sqlite3MemoryBarrier(void);
#else
# define sqlite3MutexCopy(x,y)
# define sqlite3MemoryBarrier()
#endif
#if !defined(SQLITE_MUTEX_OMIT)
# if !defined(SQLITE_MUTEX_NOOP)
void *sqlite3CompareAndSwap(void * volatile *, void *, void *);
# else
# define sqlite3CompareAndSwap sqlite3NoopCompareAndSwap
# endif
#else
# define sqlite3CompareAndSwap(x,y,z)
#endif
sqlite3_int64 sqlite3StatusValue(int);
void sqlite3StatusUp(int, int);