Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Update OS/2 mutex implementation: make methods static and don't use them by the old names any more. Held/Notheld should be debug only. (CVS 5290) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
d92418ca502f5f58dc968668e11c4295 |
User & Date: | pweilbacher 2008-06-23 22:13:28.000 |
Context
2008-06-24
| ||
00:32 | The compound-select merge optimization is mostly working with this check-in. But there are still a few problems and so the optimization is disabled by and "#if 0". This check-in is to synchronize with the other changes happening in parallel. (CVS 5291) (check-in: e2ba324cbc user: drh tags: trunk) | |
2008-06-23
| ||
22:13 | Update OS/2 mutex implementation: make methods static and don't use them by the old names any more. Held/Notheld should be debug only. (CVS 5290) (check-in: d92418ca50 user: pweilbacher tags: trunk) | |
21:26 | Reverted previous checkin (on second thought, changing case could break badly written homegrown parsers such as sometimes encountered in embedded firmware.) (CVS 5289) (check-in: bf2e283d6f user: mihailim tags: trunk) | |
Changes
Changes to src/mutex_os2.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2007 August 28 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains the C functions that implement mutexes for OS/2 ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2007 August 28 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains the C functions that implement mutexes for OS/2 ** ** $Id: mutex_os2.c,v 1.10 2008/06/23 22:13:28 pweilbacher Exp $ */ #include "sqliteInt.h" /* ** The code in this file is only used if SQLITE_MUTEX_OS2 is defined. ** See the mutex.h file for details. */ |
︙ | ︙ | |||
38 39 40 41 42 43 44 | }; #define OS2_MUTEX_INITIALIZER 0,0,0,0 /* ** Initialize and deinitialize the mutex subsystem. */ | | | | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | }; #define OS2_MUTEX_INITIALIZER 0,0,0,0 /* ** Initialize and deinitialize the mutex subsystem. */ static int os2MutexInit(void){ return SQLITE_OK; } static int os2MutexEnd(void){ return SQLITE_OK; } /* ** The sqlite3_mutex_alloc() routine allocates a new ** mutex and returns a pointer to it. If it returns NULL ** that means that a mutex could not be allocated. ** SQLite will unwind its stack and return an error. The argument ** to sqlite3_mutex_alloc() is one of these integer constants: |
︙ | ︙ | |||
80 81 82 83 84 85 86 | ** ** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() ** returns a different mutex on every call. But for the static ** mutex types, the same mutex is returned on every call that has ** the same type number. */ | | | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | ** ** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() ** returns a different mutex on every call. But for the static ** mutex types, the same mutex is returned on every call that has ** the same type number. */ static sqlite3_mutex *os2MutexAlloc(int iType){ sqlite3_mutex *p = NULL; switch( iType ){ case SQLITE_MUTEX_FAST: case SQLITE_MUTEX_RECURSIVE: { p = sqlite3MallocZero( sizeof(*p) ); if( p ){ p->id = iType; |
︙ | ︙ | |||
148 149 150 151 152 153 154 | } /* ** This routine deallocates a previously allocated mutex. ** SQLite is careful to deallocate every mutex that it allocates. */ | | | | | | | > | | > | > | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | } /* ** This routine deallocates a previously allocated mutex. ** SQLite is careful to deallocate every mutex that it allocates. */ static void os2MutexFree(sqlite3_mutex *p){ if( p==0 ) return; assert( p->nRef==0 ); assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ); DosCloseMutexSem( p->mutex ); sqlite3_free( p ); } /* ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt ** to enter a mutex. If another thread is already within the mutex, ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return ** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK ** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can ** be entered multiple times by the same thread. In such cases the, ** mutex must be exited an equal number of times before another thread ** can enter. If the same thread tries to enter any other kind of mutex ** more than once, the behavior is undefined. */ static void os2MutexEnter(sqlite3_mutex *p){ TID tid; PID holder1; ULONG holder2; if( p==0 ) return; assert( p->id==SQLITE_MUTEX_RECURSIVE || os2MutexNotheld(p) ); DosRequestMutexSem(p->mutex, SEM_INDEFINITE_WAIT); DosQueryMutexSem(p->mutex, &holder1, &tid, &holder2); p->owner = tid; p->nRef++; } static int os2MutexTry(sqlite3_mutex *p){ int rc; TID tid; PID holder1; ULONG holder2; if( p==0 ) return SQLITE_OK; assert( p->id==SQLITE_MUTEX_RECURSIVE || os2MutexNotheld(p) ); if( DosRequestMutexSem(p->mutex, SEM_IMMEDIATE_RETURN) == NO_ERROR) { DosQueryMutexSem(p->mutex, &holder1, &tid, &holder2); p->owner = tid; p->nRef++; rc = SQLITE_OK; } else { rc = SQLITE_BUSY; } return rc; } /* ** The sqlite3_mutex_leave() routine exits a mutex that was ** previously entered by the same thread. The behavior ** is undefined if the mutex is not currently entered or ** is not currently allocated. SQLite will never do either. */ static void os2MutexLeave(sqlite3_mutex *p){ TID tid; PID holder1; ULONG holder2; if( p==0 ) return; assert( p->nRef>0 ); DosQueryMutexSem(p->mutex, &holder1, &tid, &holder2); assert( p->owner==tid ); p->nRef--; assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE ); DosReleaseMutexSem(p->mutex); } #ifdef SQLITE_DEBUG /* ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are ** intended for use inside assert() statements. */ static int os2MutexHeld(sqlite3_mutex *p){ TID tid; PID pid; ULONG ulCount; PTIB ptib; if( p!=0 ) { DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount); } else { DosGetInfoBlocks(&ptib, NULL); tid = ptib->tib_ptib2->tib2_ultid; } return p==0 || (p->nRef!=0 && p->owner==tid); } static int os2MutexNotheld(sqlite3_mutex *p){ TID tid; PID pid; ULONG ulCount; PTIB ptib; if( p!= 0 ) { DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount); } else { DosGetInfoBlocks(&ptib, NULL); tid = ptib->tib_ptib2->tib2_ultid; } return p==0 || p->nRef==0 || p->owner!=tid; } #endif sqlite3_mutex_methods *sqlite3DefaultMutex(void){ static sqlite3_mutex_methods sMutex = { os2MutexInit, os2MutexEnd, os2MutexAlloc, os2MutexFree, os2MutexEnter, os2MutexTry, os2MutexLeave, #ifdef SQLITE_DEBUG os2MutexHeld, os2MutexNotheld #endif }; return &sMutex; } #endif /* SQLITE_MUTEX_OS2 */ |