| 
                         如果CoreMutex打开,则会设置全局的锁控制函数 
- /* 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; 
 -     sqlite3MemoryBarrier(); 
 -     pTo->xMutexAlloc = pFrom->xMutexAlloc; 
 
  
    - 而CoreMutext未打开的话,sqlite3NoopMutex()的实现如下(CoreMutext未打开的话,对应使用的锁函数均为空实现):
 
 
- sqlite3_mutex_methods const *sqlite3NoopMutex(void){ 
 -   static const sqlite3_mutex_methods sMutex = { 
 -     noopMutexInit, 
 -     noopMutexEnd, 
 -     noopMutexAlloc, 
 -     noopMutexFree, 
 -     noopMutexEnter, 
 -     noopMutexTry, 
 -     noopMutexLeave, 
 -     0, 
 -     0, 
 -   }; 
 -  
 -   return &sMutex; 
 - } 
 -  
 - // CoreMutext未打开的话,对应使用的锁函数均为空实现 
 - static int noopMutexInit(void){ return SQLITE_OK; } 
 - static int noopMutexEnd(void){ return SQLITE_OK; } 
 - static sqlite3_mutex *noopMutexAlloc(int id){  
 -   UNUSED_PARAMETER(id); 
 -   return (sqlite3_mutex*)8;  
 - } 
 - static void noopMutexFree(sqlite3_mutex *p){ UNUSED_PARAMETER(p); return; } 
 - static void noopMutexEnter(sqlite3_mutex *p){ UNUSED_PARAMETER(p); return; } 
 - static int noopMutexTry(sqlite3_mutex *p){ 
 -   UNUSED_PARAMETER(p); 
 -   return SQLITE_OK; 
 - } 
 - static void noopMutexLeave(sqlite3_mutex *p){ UNUSED_PARAMETER(p); return; } 
 
  
粗略看了一下,通过db->mutex(sqlite3_mutex_enter(db->mutex);)保护的逻辑块和函数主要如下列表: 
- sqlite3_db_status、sqlite3_finalize、sqlite3_reset、sqlite3_step、sqlite3_exec、 
 - sqlite3_preppare_v2、column_name、blob操作、sqlite3Close、sqlite3_errmsg... 
 
  
                        (编辑:泰州站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |