blob: 8a8ae289bac6fdc1d8bd9e7380513564115ca4ca [file] [log] [blame]
drh437b9012007-08-28 16:34:42 +00001/*
2** 2007 August 14
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
mistachkin0174ffa2014-07-30 23:11:16 +000012** This file contains the C functions that implement mutexes for Win32.
drh437b9012007-08-28 16:34:42 +000013*/
14#include "sqliteInt.h"
15
mistachkin0f710542014-05-12 15:37:03 +000016#if SQLITE_OS_WIN
17/*
mistachkin0174ffa2014-07-30 23:11:16 +000018** Include code that is common to all os_*.c files
19*/
20#include "os_common.h"
21
22/*
mistachkin0f710542014-05-12 15:37:03 +000023** Include the header file for the Windows VFS.
24*/
25#include "os_win.h"
26#endif
27
drh437b9012007-08-28 16:34:42 +000028/*
29** The code in this file is only used if we are compiling multithreaded
mistachkin0174ffa2014-07-30 23:11:16 +000030** on a Win32 system.
drh437b9012007-08-28 16:34:42 +000031*/
drhc7ce76a2007-08-30 14:10:30 +000032#ifdef SQLITE_MUTEX_W32
drh437b9012007-08-28 16:34:42 +000033
34/*
35** Each recursive mutex is an instance of the following structure.
36*/
37struct sqlite3_mutex {
38 CRITICAL_SECTION mutex; /* Mutex controlling the lock */
39 int id; /* Mutex type */
shaneh1f4222f2010-02-13 02:31:09 +000040#ifdef SQLITE_DEBUG
drh72339a32010-05-13 20:19:17 +000041 volatile int nRef; /* Number of enterances */
42 volatile DWORD owner; /* Thread holding this mutex */
mistachkin091881b2018-02-18 00:54:06 +000043 volatile LONG trace; /* True to trace changes */
shaneh1f4222f2010-02-13 02:31:09 +000044#endif
drh437b9012007-08-28 16:34:42 +000045};
drha4189802008-06-19 16:07:07 +000046
drhd42d0be2014-07-30 21:10:12 +000047/*
mistachkin0174ffa2014-07-30 23:11:16 +000048** These are the initializer values used when declaring a "static" mutex
49** on Win32. It should be noted that all mutexes require initialization
50** on the Win32 platform.
drhd42d0be2014-07-30 21:10:12 +000051*/
mistachkin0174ffa2014-07-30 23:11:16 +000052#define SQLITE_W32_MUTEX_INITIALIZER { 0 }
53
54#ifdef SQLITE_DEBUG
mistachkin091881b2018-02-18 00:54:06 +000055#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id, \
mistachkin0174ffa2014-07-30 23:11:16 +000056 0L, (DWORD)0, 0 }
drhd42d0be2014-07-30 21:10:12 +000057#else
mistachkin091881b2018-02-18 00:54:06 +000058#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id }
drhd42d0be2014-07-30 21:10:12 +000059#endif
60
drha4189802008-06-19 16:07:07 +000061#ifdef SQLITE_DEBUG
danielk19776d2ab0e2008-06-17 17:21:18 +000062/*
63** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
64** intended for use only inside assert() statements.
65*/
66static int winMutexHeld(sqlite3_mutex *p){
67 return p->nRef!=0 && p->owner==GetCurrentThreadId();
68}
mistachkin0174ffa2014-07-30 23:11:16 +000069
shaneh1f4222f2010-02-13 02:31:09 +000070static int winMutexNotheld2(sqlite3_mutex *p, DWORD tid){
71 return p->nRef==0 || p->owner!=tid;
72}
mistachkin0174ffa2014-07-30 23:11:16 +000073
danielk19776d2ab0e2008-06-17 17:21:18 +000074static int winMutexNotheld(sqlite3_mutex *p){
mistachkin0174ffa2014-07-30 23:11:16 +000075 DWORD tid = GetCurrentThreadId();
shaneh1f4222f2010-02-13 02:31:09 +000076 return winMutexNotheld2(p, tid);
danielk19776d2ab0e2008-06-17 17:21:18 +000077}
drha4189802008-06-19 16:07:07 +000078#endif
danielk19776d2ab0e2008-06-17 17:21:18 +000079
drhdf6a81c2007-09-05 14:30:42 +000080/*
drh539482b2015-09-26 03:23:29 +000081** Try to provide a memory barrier operation, needed for initialization
82** and also for the xShmBarrier method of the VFS in cases when SQLite is
83** compiled without mutexes (SQLITE_THREADSAFE=0).
drh6081c1d2015-09-06 02:51:04 +000084*/
85void sqlite3MemoryBarrier(void){
drh2d640342015-09-06 10:31:37 +000086#if defined(SQLITE_MEMORY_BARRIER)
87 SQLITE_MEMORY_BARRIER;
88#elif defined(__GNUC__)
89 __sync_synchronize();
drh30a58312017-02-13 13:26:33 +000090#elif MSVC_VERSION>=1300
mistachkin8d9837a2015-10-06 01:44:53 +000091 _ReadWriteBarrier();
92#elif defined(MemoryBarrier)
drh6081c1d2015-09-06 02:51:04 +000093 MemoryBarrier();
drh2d640342015-09-06 10:31:37 +000094#endif
drh6081c1d2015-09-06 02:51:04 +000095}
96
97/*
drh40257ff2008-06-13 18:24:27 +000098** Initialize and deinitialize the mutex subsystem.
99*/
drhd42d0be2014-07-30 21:10:12 +0000100static sqlite3_mutex winMutex_staticMutexes[] = {
mistachkin091881b2018-02-18 00:54:06 +0000101 SQLITE3_MUTEX_INITIALIZER(2),
102 SQLITE3_MUTEX_INITIALIZER(3),
103 SQLITE3_MUTEX_INITIALIZER(4),
104 SQLITE3_MUTEX_INITIALIZER(5),
105 SQLITE3_MUTEX_INITIALIZER(6),
106 SQLITE3_MUTEX_INITIALIZER(7),
107 SQLITE3_MUTEX_INITIALIZER(8),
108 SQLITE3_MUTEX_INITIALIZER(9),
109 SQLITE3_MUTEX_INITIALIZER(10),
110 SQLITE3_MUTEX_INITIALIZER(11),
111 SQLITE3_MUTEX_INITIALIZER(12),
112 SQLITE3_MUTEX_INITIALIZER(13)
shaneh1f4222f2010-02-13 02:31:09 +0000113};
mistachkin0174ffa2014-07-30 23:11:16 +0000114
shane61b82d62009-06-01 17:06:07 +0000115static int winMutex_isInit = 0;
mistachkin202cb642014-07-31 18:54:01 +0000116static int winMutex_isNt = -1; /* <0 means "need to query" */
mistachkin0174ffa2014-07-30 23:11:16 +0000117
118/* As the winMutexInit() and winMutexEnd() functions are called as part
119** of the sqlite3_initialize() and sqlite3_shutdown() processing, the
120** "interlocked" magic used here is probably not strictly necessary.
shane61b82d62009-06-01 17:06:07 +0000121*/
mistachkince64d612014-08-14 18:31:56 +0000122static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0;
shane61b82d62009-06-01 17:06:07 +0000123
mistachkin0174ffa2014-07-30 23:11:16 +0000124int sqlite3_win32_is_nt(void); /* os_win.c */
mistachkin9721c212012-06-18 17:15:29 +0000125void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
126
mistachkin0174ffa2014-07-30 23:11:16 +0000127static int winMutexInit(void){
shane61b82d62009-06-01 17:06:07 +0000128 /* The first to increment to 1 does actual initialization */
shane1987c8d2009-08-10 03:23:21 +0000129 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
shane61b82d62009-06-01 17:06:07 +0000130 int i;
drh9ac06502009-08-17 13:42:29 +0000131 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
drhcf3d7a42012-03-01 20:05:41 +0000132#if SQLITE_OS_WINRT
133 InitializeCriticalSectionEx(&winMutex_staticMutexes[i].mutex, 0, 0);
134#else
shane61b82d62009-06-01 17:06:07 +0000135 InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
drhcf3d7a42012-03-01 20:05:41 +0000136#endif
shane61b82d62009-06-01 17:06:07 +0000137 }
138 winMutex_isInit = 1;
139 }else{
mistachkin0174ffa2014-07-30 23:11:16 +0000140 /* Another thread is (in the process of) initializing the static
141 ** mutexes */
shane61b82d62009-06-01 17:06:07 +0000142 while( !winMutex_isInit ){
mistachkinf4f327c2012-03-13 03:35:07 +0000143 sqlite3_win32_sleep(1);
shane61b82d62009-06-01 17:06:07 +0000144 }
145 }
mistachkin0174ffa2014-07-30 23:11:16 +0000146 return SQLITE_OK;
shane61b82d62009-06-01 17:06:07 +0000147}
148
mistachkin0174ffa2014-07-30 23:11:16 +0000149static int winMutexEnd(void){
150 /* The first to decrement to 0 does actual shutdown
shane61b82d62009-06-01 17:06:07 +0000151 ** (which should be the last to shutdown.) */
shane1987c8d2009-08-10 03:23:21 +0000152 if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){
shane61b82d62009-06-01 17:06:07 +0000153 if( winMutex_isInit==1 ){
154 int i;
drh9ac06502009-08-17 13:42:29 +0000155 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
shane61b82d62009-06-01 17:06:07 +0000156 DeleteCriticalSection(&winMutex_staticMutexes[i].mutex);
157 }
158 winMutex_isInit = 0;
159 }
160 }
mistachkin0174ffa2014-07-30 23:11:16 +0000161 return SQLITE_OK;
shane61b82d62009-06-01 17:06:07 +0000162}
drh40257ff2008-06-13 18:24:27 +0000163
164/*
drh437b9012007-08-28 16:34:42 +0000165** The sqlite3_mutex_alloc() routine allocates a new
166** mutex and returns a pointer to it. If it returns NULL
167** that means that a mutex could not be allocated. SQLite
168** will unwind its stack and return an error. The argument
169** to sqlite3_mutex_alloc() is one of these integer constants:
170**
171** <ul>
shane7c7c3112009-08-17 15:31:23 +0000172** <li> SQLITE_MUTEX_FAST
173** <li> SQLITE_MUTEX_RECURSIVE
174** <li> SQLITE_MUTEX_STATIC_MASTER
175** <li> SQLITE_MUTEX_STATIC_MEM
drhd42d0be2014-07-30 21:10:12 +0000176** <li> SQLITE_MUTEX_STATIC_OPEN
shane7c7c3112009-08-17 15:31:23 +0000177** <li> SQLITE_MUTEX_STATIC_PRNG
178** <li> SQLITE_MUTEX_STATIC_LRU
dan6d4fb832011-01-26 07:25:32 +0000179** <li> SQLITE_MUTEX_STATIC_PMEM
drhd42d0be2014-07-30 21:10:12 +0000180** <li> SQLITE_MUTEX_STATIC_APP1
181** <li> SQLITE_MUTEX_STATIC_APP2
182** <li> SQLITE_MUTEX_STATIC_APP3
mistachkin93de6532015-07-03 21:38:09 +0000183** <li> SQLITE_MUTEX_STATIC_VFS1
184** <li> SQLITE_MUTEX_STATIC_VFS2
185** <li> SQLITE_MUTEX_STATIC_VFS3
drh437b9012007-08-28 16:34:42 +0000186** </ul>
187**
188** The first two constants cause sqlite3_mutex_alloc() to create
189** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
190** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
191** The mutex implementation does not need to make a distinction
192** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
193** not want to. But SQLite will only request a recursive mutex in
194** cases where it really needs one. If a faster non-recursive mutex
195** implementation is available on the host platform, the mutex subsystem
196** might return such a mutex in response to SQLITE_MUTEX_FAST.
197**
198** The other allowed parameters to sqlite3_mutex_alloc() each return
shane7c7c3112009-08-17 15:31:23 +0000199** a pointer to a static preexisting mutex. Six static mutexes are
drh437b9012007-08-28 16:34:42 +0000200** used by the current version of SQLite. Future versions of SQLite
201** may add additional static mutexes. Static mutexes are for internal
202** use by SQLite only. Applications that use SQLite mutexes should
203** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
204** SQLITE_MUTEX_RECURSIVE.
205**
206** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
207** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
mistachkin0174ffa2014-07-30 23:11:16 +0000208** returns a different mutex on every call. But for the static
drh437b9012007-08-28 16:34:42 +0000209** mutex types, the same mutex is returned on every call that has
210** the same type number.
211*/
danielk19776d2ab0e2008-06-17 17:21:18 +0000212static sqlite3_mutex *winMutexAlloc(int iType){
drh437b9012007-08-28 16:34:42 +0000213 sqlite3_mutex *p;
214
215 switch( iType ){
216 case SQLITE_MUTEX_FAST:
217 case SQLITE_MUTEX_RECURSIVE: {
218 p = sqlite3MallocZero( sizeof(*p) );
mistachkin0174ffa2014-07-30 23:11:16 +0000219 if( p ){
drh437b9012007-08-28 16:34:42 +0000220 p->id = iType;
drhcbb3f332015-02-25 14:25:31 +0000221#ifdef SQLITE_DEBUG
mistachkin0174ffa2014-07-30 23:11:16 +0000222#ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC
223 p->trace = 1;
224#endif
drh72339a32010-05-13 20:19:17 +0000225#endif
mistachkindf562d52012-03-13 01:16:57 +0000226#if SQLITE_OS_WINRT
227 InitializeCriticalSectionEx(&p->mutex, 0, 0);
228#else
drh437b9012007-08-28 16:34:42 +0000229 InitializeCriticalSection(&p->mutex);
mistachkindf562d52012-03-13 01:16:57 +0000230#endif
drh437b9012007-08-28 16:34:42 +0000231 }
232 break;
233 }
234 default: {
mistachkincd54bab2014-12-20 21:14:14 +0000235#ifdef SQLITE_ENABLE_API_ARMOR
236 if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){
237 (void)SQLITE_MISUSE_BKPT;
238 return 0;
239 }
240#endif
shane61b82d62009-06-01 17:06:07 +0000241 p = &winMutex_staticMutexes[iType-2];
drhcbb3f332015-02-25 14:25:31 +0000242#ifdef SQLITE_DEBUG
mistachkin0174ffa2014-07-30 23:11:16 +0000243#ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC
mistachkin091881b2018-02-18 00:54:06 +0000244 InterlockedCompareExchange(&p->trace, 1, 0);
mistachkin0174ffa2014-07-30 23:11:16 +0000245#endif
drh72339a32010-05-13 20:19:17 +0000246#endif
drh437b9012007-08-28 16:34:42 +0000247 break;
248 }
249 }
mistachkin091881b2018-02-18 00:54:06 +0000250 assert( p==0 || p->id==iType );
drh437b9012007-08-28 16:34:42 +0000251 return p;
252}
253
254
255/*
256** This routine deallocates a previously
257** allocated mutex. SQLite is careful to deallocate every
258** mutex that it allocates.
259*/
danielk19776d2ab0e2008-06-17 17:21:18 +0000260static void winMutexFree(sqlite3_mutex *p){
drh437b9012007-08-28 16:34:42 +0000261 assert( p );
dan84612fe2010-08-10 07:12:26 +0000262 assert( p->nRef==0 && p->owner==0 );
drh96c707a2015-02-13 16:36:14 +0000263 if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ){
264 DeleteCriticalSection(&p->mutex);
265 sqlite3_free(p);
266 }else{
267#ifdef SQLITE_ENABLE_API_ARMOR
268 (void)SQLITE_MISUSE_BKPT;
mistachkin0174ffa2014-07-30 23:11:16 +0000269#endif
drh96c707a2015-02-13 16:36:14 +0000270 }
drh437b9012007-08-28 16:34:42 +0000271}
272
273/*
274** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
275** to enter a mutex. If another thread is already within the mutex,
276** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
277** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK
278** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can
279** be entered multiple times by the same thread. In such cases the,
280** mutex must be exited an equal number of times before another thread
281** can enter. If the same thread tries to enter any other kind of mutex
282** more than once, the behavior is undefined.
283*/
danielk19776d2ab0e2008-06-17 17:21:18 +0000284static void winMutexEnter(sqlite3_mutex *p){
mistachkin0174ffa2014-07-30 23:11:16 +0000285#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
286 DWORD tid = GetCurrentThreadId();
287#endif
drh72339a32010-05-13 20:19:17 +0000288#ifdef SQLITE_DEBUG
mistachkin0174ffa2014-07-30 23:11:16 +0000289 assert( p );
shaneh1f4222f2010-02-13 02:31:09 +0000290 assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
mistachkin0174ffa2014-07-30 23:11:16 +0000291#else
292 assert( p );
drh72339a32010-05-13 20:19:17 +0000293#endif
drhd42d0be2014-07-30 21:10:12 +0000294 assert( winMutex_isInit==1 );
drh437b9012007-08-28 16:34:42 +0000295 EnterCriticalSection(&p->mutex);
drh72339a32010-05-13 20:19:17 +0000296#ifdef SQLITE_DEBUG
dan84612fe2010-08-10 07:12:26 +0000297 assert( p->nRef>0 || p->owner==0 );
mistachkin0174ffa2014-07-30 23:11:16 +0000298 p->owner = tid;
drh437b9012007-08-28 16:34:42 +0000299 p->nRef++;
shaneh1f4222f2010-02-13 02:31:09 +0000300 if( p->trace ){
mistachkin0d5b3b72017-02-15 18:30:57 +0000301 OSTRACE(("ENTER-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
302 tid, p->id, p, p->trace, p->nRef));
shaneh1f4222f2010-02-13 02:31:09 +0000303 }
304#endif
drh437b9012007-08-28 16:34:42 +0000305}
mistachkin0174ffa2014-07-30 23:11:16 +0000306
danielk19776d2ab0e2008-06-17 17:21:18 +0000307static int winMutexTry(sqlite3_mutex *p){
mistachkin0174ffa2014-07-30 23:11:16 +0000308#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
309 DWORD tid = GetCurrentThreadId();
shaneh1da207e2010-03-09 14:41:12 +0000310#endif
drh86505062007-10-05 15:08:01 +0000311 int rc = SQLITE_BUSY;
mistachkin0174ffa2014-07-30 23:11:16 +0000312 assert( p );
shaneh1f4222f2010-02-13 02:31:09 +0000313 assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
drh86505062007-10-05 15:08:01 +0000314 /*
315 ** The sqlite3_mutex_try() routine is very rarely used, and when it
316 ** is used it is merely an optimization. So it is OK for it to always
mistachkin0174ffa2014-07-30 23:11:16 +0000317 ** fail.
drh86505062007-10-05 15:08:01 +0000318 **
319 ** The TryEnterCriticalSection() interface is only available on WinNT.
320 ** And some windows compilers complain if you try to use it without
321 ** first doing some #defines that prevent SQLite from building on Win98.
322 ** For that reason, we will omit this optimization for now. See
323 ** ticket #2685.
324 */
mistachkin0174ffa2014-07-30 23:11:16 +0000325#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400
drhd42d0be2014-07-30 21:10:12 +0000326 assert( winMutex_isInit==1 );
mistachkin202cb642014-07-31 18:54:01 +0000327 assert( winMutex_isNt>=-1 && winMutex_isNt<=1 );
328 if( winMutex_isNt<0 ){
329 winMutex_isNt = sqlite3_win32_is_nt();
330 }
331 assert( winMutex_isNt==0 || winMutex_isNt==1 );
332 if( winMutex_isNt && TryEnterCriticalSection(&p->mutex) ){
mistachkin0174ffa2014-07-30 23:11:16 +0000333#ifdef SQLITE_DEBUG
shaneh1f4222f2010-02-13 02:31:09 +0000334 p->owner = tid;
drh437b9012007-08-28 16:34:42 +0000335 p->nRef++;
mistachkin0174ffa2014-07-30 23:11:16 +0000336#endif
drh437b9012007-08-28 16:34:42 +0000337 rc = SQLITE_OK;
drh437b9012007-08-28 16:34:42 +0000338 }
shane1a389642009-01-30 16:09:22 +0000339#else
340 UNUSED_PARAMETER(p);
drh86505062007-10-05 15:08:01 +0000341#endif
shaneh1f4222f2010-02-13 02:31:09 +0000342#ifdef SQLITE_DEBUG
mistachkin0174ffa2014-07-30 23:11:16 +0000343 if( p->trace ){
mistachkin0d5b3b72017-02-15 18:30:57 +0000344 OSTRACE(("TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
345 tid, p->id, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
shaneh1f4222f2010-02-13 02:31:09 +0000346 }
347#endif
drh437b9012007-08-28 16:34:42 +0000348 return rc;
349}
350
351/*
352** The sqlite3_mutex_leave() routine exits a mutex that was
353** previously entered by the same thread. The behavior
354** is undefined if the mutex is not currently entered or
355** is not currently allocated. SQLite will never do either.
356*/
danielk19776d2ab0e2008-06-17 17:21:18 +0000357static void winMutexLeave(sqlite3_mutex *p){
mistachkin0174ffa2014-07-30 23:11:16 +0000358#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
shaneh1da207e2010-03-09 14:41:12 +0000359 DWORD tid = GetCurrentThreadId();
mistachkin0174ffa2014-07-30 23:11:16 +0000360#endif
361 assert( p );
362#ifdef SQLITE_DEBUG
drh437b9012007-08-28 16:34:42 +0000363 assert( p->nRef>0 );
shaneh1f4222f2010-02-13 02:31:09 +0000364 assert( p->owner==tid );
drh437b9012007-08-28 16:34:42 +0000365 p->nRef--;
dan84612fe2010-08-10 07:12:26 +0000366 if( p->nRef==0 ) p->owner = 0;
drh437b9012007-08-28 16:34:42 +0000367 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
drh72339a32010-05-13 20:19:17 +0000368#endif
drhd42d0be2014-07-30 21:10:12 +0000369 assert( winMutex_isInit==1 );
drh437b9012007-08-28 16:34:42 +0000370 LeaveCriticalSection(&p->mutex);
shaneh1f4222f2010-02-13 02:31:09 +0000371#ifdef SQLITE_DEBUG
372 if( p->trace ){
mistachkin0d5b3b72017-02-15 18:30:57 +0000373 OSTRACE(("LEAVE-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
374 tid, p->id, p, p->trace, p->nRef));
shaneh1f4222f2010-02-13 02:31:09 +0000375 }
376#endif
drh437b9012007-08-28 16:34:42 +0000377}
378
dan558814f2010-06-02 05:53:53 +0000379sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
380 static const sqlite3_mutex_methods sMutex = {
danielk19776d2ab0e2008-06-17 17:21:18 +0000381 winMutexInit,
danielk19774a9d1f62008-06-19 08:51:23 +0000382 winMutexEnd,
danielk19776d2ab0e2008-06-17 17:21:18 +0000383 winMutexAlloc,
384 winMutexFree,
385 winMutexEnter,
386 winMutexTry,
387 winMutexLeave,
drha4189802008-06-19 16:07:07 +0000388#ifdef SQLITE_DEBUG
danielk19776d2ab0e2008-06-17 17:21:18 +0000389 winMutexHeld,
390 winMutexNotheld
drh1875f7a2008-12-08 18:19:17 +0000391#else
392 0,
393 0
drha4189802008-06-19 16:07:07 +0000394#endif
danielk19776d2ab0e2008-06-17 17:21:18 +0000395 };
danielk19776d2ab0e2008-06-17 17:21:18 +0000396 return &sMutex;
drh437b9012007-08-28 16:34:42 +0000397}
mistachkin0174ffa2014-07-30 23:11:16 +0000398
drhc7ce76a2007-08-30 14:10:30 +0000399#endif /* SQLITE_MUTEX_W32 */