equal
deleted
inserted
replaced
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
152 /** |
152 /** |
153 Gives the calling thread an exclusive access to the SQLite resources (global variables, file handles, buffers, cache, etc.). |
153 Gives the calling thread an exclusive access to the SQLite resources (global variables, file handles, buffers, cache, etc.). |
154 The calling thread becomes a mutex owner. |
154 The calling thread becomes a mutex owner. |
155 If the mutex is already locked by another thread, the calling thread will block until the other thread releases the mutex. |
155 If the mutex is already locked by another thread, the calling thread will block until the other thread releases the mutex. |
156 The method can be called by the mutex owning thread more than once, even if the mutex is already entered. |
156 The method can be called by the mutex owning thread more than once, even if the mutex is already entered. |
|
157 |
|
158 @panic SqliteMt 23 Negative mutex lock counter (in debug builds only) |
157 */ |
159 */ |
158 void sqlite3_mutex::Enter() |
160 void sqlite3_mutex::Enter() |
159 { |
161 { |
|
162 __ASSERT_DEBUG(iRefCount >= 0, User::Panic(KPanicCategory, EPanicMutexLockCounter)); |
160 iMutex.Wait(); |
163 iMutex.Wait(); |
161 RThread currThread; |
164 RThread currThread; |
162 iOwnerThreadId = currThread.Id(); |
165 iOwnerThreadId = currThread.Id(); |
163 ++iRefCount; |
166 ++iRefCount; |
164 } |
167 } |
189 @return True if the mutex is locked, false otherwise |
192 @return True if the mutex is locked, false otherwise |
190 */ |
193 */ |
191 TBool sqlite3_mutex::IsHeld() const |
194 TBool sqlite3_mutex::IsHeld() const |
192 { |
195 { |
193 RThread currThread; |
196 RThread currThread; |
194 return iRefCount != 0 && iOwnerThreadId == currThread.Id(); |
197 return iRefCount > 0 && iOwnerThreadId == currThread.Id(); |
195 } |
198 } |
196 |
199 |
197 /** |
200 /** |
198 Creates the mutex. |
201 Creates the mutex. |
199 |
202 |
272 case SQLITE_MUTEX_FAST: |
275 case SQLITE_MUTEX_FAST: |
273 case SQLITE_MUTEX_RECURSIVE: |
276 case SQLITE_MUTEX_RECURSIVE: |
274 mutex = CRecursiveMutex::New(); |
277 mutex = CRecursiveMutex::New(); |
275 break; |
278 break; |
276 default: |
279 default: |
277 mutex = ::StaticMutex(aType - 2); |
280 mutex = ::StaticMutex(aType - 2);//"aType - 2" because the first SQLITE_MUTEX_STATIC_<type> mutex definition |
|
281 //value is 2 (SQLITE_MUTEX_FAST is 0, SQLITE_MUTEX_RECURSIVE is 1). |
278 break; |
282 break; |
279 } |
283 } |
280 return mutex; |
284 return mutex; |
281 } |
285 } |
282 |
286 |
415 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
419 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
416 ////////////////////////// TheMutexMethods ////////////////////////////////////////////////////////////////////////////////// |
420 ////////////////////////// TheMutexMethods ////////////////////////////////////////////////////////////////////////////////// |
417 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
421 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
418 |
422 |
419 /** |
423 /** |
|
424 sqlite3_mutex_methods is a structure declared in sqlite3.h header file. |
|
425 sqlite3_mutex_methods defines the mutex interface used by SQLite and implemented by the OS porting layer. |
420 */ |
426 */ |
421 static sqlite3_mutex_methods TheMutexMethods = |
427 static sqlite3_mutex_methods TheMutexMethods = |
422 { |
428 { |
423 &TMutexApi::Init, |
429 &TMutexApi::Init, |
424 &TMutexApi::End, |
430 &TMutexApi::End, |
1025 SQLite OS porting layer API. |
1031 SQLite OS porting layer API. |
1026 |
1032 |
1027 Checks if the file lock type is SQLITE_LOCK_RESERVED or bigger. |
1033 Checks if the file lock type is SQLITE_LOCK_RESERVED or bigger. |
1028 |
1034 |
1029 @param aDbFile A pointer to a TDbFile instance, that contains the file handle. |
1035 @param aDbFile A pointer to a TDbFile instance, that contains the file handle. |
1030 @param aResOut Output parameter. It should be set to 1 if the stored lock type is bigger or equal |
1036 @param aResOut Output parameter. It will be set to be non-zero if the stored lock type is bigger or equal |
1031 than SQLITE_LOCK_RESERVED. |
1037 than SQLITE_LOCK_RESERVED. |
1032 |
1038 |
1033 @return SQLITE_IOERR_CHECKRESERVEDLOCK, The operation has failed, |
1039 @return SQLITE_IOERR_CHECKRESERVEDLOCK, The operation has failed, |
1034 SQLITE_OK The operation has completed successfully. |
1040 SQLITE_OK The operation has completed successfully. |
1035 |
1041 |