OLD | NEW |
1 /* | 1 /* |
2 ** 2008 October 07 | 2 ** 2008 October 07 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 */ | 100 */ |
101 static int debugMutexInit(void){ return SQLITE_OK; } | 101 static int debugMutexInit(void){ return SQLITE_OK; } |
102 static int debugMutexEnd(void){ return SQLITE_OK; } | 102 static int debugMutexEnd(void){ return SQLITE_OK; } |
103 | 103 |
104 /* | 104 /* |
105 ** The sqlite3_mutex_alloc() routine allocates a new | 105 ** The sqlite3_mutex_alloc() routine allocates a new |
106 ** mutex and returns a pointer to it. If it returns NULL | 106 ** mutex and returns a pointer to it. If it returns NULL |
107 ** that means that a mutex could not be allocated. | 107 ** that means that a mutex could not be allocated. |
108 */ | 108 */ |
109 static sqlite3_mutex *debugMutexAlloc(int id){ | 109 static sqlite3_mutex *debugMutexAlloc(int id){ |
110 static sqlite3_debug_mutex aStatic[SQLITE_MUTEX_STATIC_APP3 - 1]; | 110 static sqlite3_debug_mutex aStatic[SQLITE_MUTEX_STATIC_VFS3 - 1]; |
111 sqlite3_debug_mutex *pNew = 0; | 111 sqlite3_debug_mutex *pNew = 0; |
112 switch( id ){ | 112 switch( id ){ |
113 case SQLITE_MUTEX_FAST: | 113 case SQLITE_MUTEX_FAST: |
114 case SQLITE_MUTEX_RECURSIVE: { | 114 case SQLITE_MUTEX_RECURSIVE: { |
115 pNew = sqlite3Malloc(sizeof(*pNew)); | 115 pNew = sqlite3Malloc(sizeof(*pNew)); |
116 if( pNew ){ | 116 if( pNew ){ |
117 pNew->id = id; | 117 pNew->id = id; |
118 pNew->cnt = 0; | 118 pNew->cnt = 0; |
119 } | 119 } |
120 break; | 120 break; |
121 } | 121 } |
122 default: { | 122 default: { |
123 assert( id-2 >= 0 ); | 123 #ifdef SQLITE_ENABLE_API_ARMOR |
124 assert( id-2 < (int)(sizeof(aStatic)/sizeof(aStatic[0])) ); | 124 if( id-2<0 || id-2>=ArraySize(aStatic) ){ |
| 125 (void)SQLITE_MISUSE_BKPT; |
| 126 return 0; |
| 127 } |
| 128 #endif |
125 pNew = &aStatic[id-2]; | 129 pNew = &aStatic[id-2]; |
126 pNew->id = id; | 130 pNew->id = id; |
127 break; | 131 break; |
128 } | 132 } |
129 } | 133 } |
130 return (sqlite3_mutex*)pNew; | 134 return (sqlite3_mutex*)pNew; |
131 } | 135 } |
132 | 136 |
133 /* | 137 /* |
134 ** This routine deallocates a previously allocated mutex. | 138 ** This routine deallocates a previously allocated mutex. |
135 */ | 139 */ |
136 static void debugMutexFree(sqlite3_mutex *pX){ | 140 static void debugMutexFree(sqlite3_mutex *pX){ |
137 sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX; | 141 sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX; |
138 assert( p->cnt==0 ); | 142 assert( p->cnt==0 ); |
139 assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ); | 143 if( p->id==SQLITE_MUTEX_RECURSIVE || p->id==SQLITE_MUTEX_FAST ){ |
140 sqlite3_free(p); | 144 sqlite3_free(p); |
| 145 }else{ |
| 146 #ifdef SQLITE_ENABLE_API_ARMOR |
| 147 (void)SQLITE_MISUSE_BKPT; |
| 148 #endif |
| 149 } |
141 } | 150 } |
142 | 151 |
143 /* | 152 /* |
144 ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt | 153 ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt |
145 ** to enter a mutex. If another thread is already within the mutex, | 154 ** to enter a mutex. If another thread is already within the mutex, |
146 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return | 155 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return |
147 ** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK | 156 ** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK |
148 ** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can | 157 ** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can |
149 ** be entered multiple times by the same thread. In such cases the, | 158 ** be entered multiple times by the same thread. In such cases the, |
150 ** mutex must be exited an equal number of times before another thread | 159 ** mutex must be exited an equal number of times before another thread |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 /* | 206 /* |
198 ** If compiled with SQLITE_MUTEX_NOOP, then the no-op mutex implementation | 207 ** If compiled with SQLITE_MUTEX_NOOP, then the no-op mutex implementation |
199 ** is used regardless of the run-time threadsafety setting. | 208 ** is used regardless of the run-time threadsafety setting. |
200 */ | 209 */ |
201 #ifdef SQLITE_MUTEX_NOOP | 210 #ifdef SQLITE_MUTEX_NOOP |
202 sqlite3_mutex_methods const *sqlite3DefaultMutex(void){ | 211 sqlite3_mutex_methods const *sqlite3DefaultMutex(void){ |
203 return sqlite3NoopMutex(); | 212 return sqlite3NoopMutex(); |
204 } | 213 } |
205 #endif /* defined(SQLITE_MUTEX_NOOP) */ | 214 #endif /* defined(SQLITE_MUTEX_NOOP) */ |
206 #endif /* !defined(SQLITE_MUTEX_OMIT) */ | 215 #endif /* !defined(SQLITE_MUTEX_OMIT) */ |
OLD | NEW |