3
# The author disclaims copyright to this source code. In place of
4
# a legal notice, here is a blessing:
6
# May you do good and not evil.
7
# May you find forgiveness for yourself and forgive others.
8
# May you share freely, never taking more than you give.
10
#***********************************************************************
12
# $Id: mutex1.test,v 1.10 2008/07/15 00:27:35 drh Exp $
14
set testdir [file dirname $argv0]
15
source $testdir/tester.tcl
17
if {[info exists tester_do_binarylog]} {
22
sqlite3_reset_auto_extension
24
proc mutex_counters {varname} {
27
foreach {name value} [read_mutex_counters] {
29
incr var(total) $value
33
#-------------------------------------------------------------------------
34
# Tests mutex1-1.* test that sqlite3_config() returns SQLITE_MISUSE if
35
# is called at the wrong time. And that the first time sqlite3_initialize
36
# is called it obtains the 'static_master' mutex 3 times and a recursive
37
# mutex (sqlite3Config.pInitMutex) twice. Subsequent calls are no-ops
38
# that do not require any mutexes.
41
install_mutex_counters 1
46
install_mutex_counters 1
51
install_mutex_counters 1
55
install_mutex_counters 0
59
install_mutex_counters 1
63
mutex_counters counters
72
mutex_counters counters
73
# list $counters(total) $counters(static_master)
74
expr {$counters(total)>0}
83
mutex_counters counters
84
list $counters(total) $counters(static_master)
87
#-------------------------------------------------------------------------
88
# Tests mutex1-2.* test the three thread-safety related modes that
89
# can be selected using sqlite3_config:
92
# * Multi-threaded mode,
93
# * Single-threaded mode.
95
set enable_shared_cache [sqlite3_enable_shared_cache 1]
96
ifcapable threadsafe {
97
foreach {mode mutexes} {
99
multithread {fast static_master static_mem static_prng}
100
serialized {fast recursive static_master static_mem static_prng}
102
ifcapable memorymanage {
103
if {$mode ne "singlethread"} {
104
lappend mutexes static_lru static_lru2 static_mem2
108
do_test mutex1.2.$mode.1 {
114
do_test mutex1.2.$mode.2 {
118
catchsql { CREATE TABLE abc(a, b, c) }
120
INSERT INTO abc VALUES(1, 2, 3);
124
do_test mutex1.2.$mode.3 {
125
mutex_counters counters
128
foreach {key value} [array get counters] {
129
if {$key ne "total" && $value > 0} {
137
sqlite3_enable_shared_cache $enable_shared_cache
139
# Open and use a connection in "nomutex" mode. Test that no recursive
140
# mutexes are obtained.
141
ifcapable threadsafe {
145
sqlite3 db test.db -nomutex 1
146
execsql { SELECT * FROM abc }
147
} {1 2 3 1 2 3 1 2 3}
149
mutex_counters counters
150
set counters(recursive)
158
install_mutex_counters 0
162
autoinstall_test_functions