/* ** 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: ** ** <ul> ** <li> SQLITE_MUTEX_FAST ** <li> SQLITE_MUTEX_RECURSIVE ** <li> SQLITE_MUTEX_STATIC_MASTER ** <li> SQLITE_MUTEX_STATIC_MEM ** <li> SQLITE_MUTEX_STATIC_MEM2 ** <li> SQLITE_MUTEX_STATIC_PRNG ** <li> SQLITE_MUTEX_STATIC_LRU ** <li> SQLITE_MUTEX_STATIC_PMEM ** </ul> ** ** The first two constants cause sqlite3_mutex_alloc() to create ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. ** The mutex implementation does not need to make a distinction ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does ** not want to. But SQLite will only request a recursive mutex in ** cases where it really needs one. If a faster non-recursive mutex ** implementation is available on the host platform, the mutex subsystem ** might return such a mutex in response to SQLITE_MUTEX_FAST. ** ** The other allowed parameters to sqlite3_mutex_alloc() each return ** a pointer to a static preexisting mutex. Six static mutexes are ** used by the current version of SQLite. Future versions of SQLite ** may add additional static mutexes. Static mutexes are for internal ** use by SQLite only. Applications that use SQLite mutexes should ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or ** SQLITE_MUTEX_RECURSIVE. ** ** 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 *vmsMutexAlloc(int iType){ static sqlite3_mutex staticMutexes[] = { SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_MASTER"), SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_MEM"), SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_MEM2"), SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_PRNG"), SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_LRU"), SQLITE3_MUTEX_INITIALIZER("SQLITE3_MUTEX_STATIC_PMEM") }; sqlite3_mutex *p; switch( iType ){ case SQLITE_MUTEX_RECURSIVE: { p = sqlite3MallocZero( sizeof(*p) ); if( p ){ #ifdef vax /* ** On OpenVMS VAX there is no way to create a recursive mutex in ** the tis interface. The routine tis_mutex_initwithname is in ** the header file and claims to enable this. However, it does ** not actually exist in the CMA$TIS_SHR RTL. So, while the ** jiggery-pokery of the lock field in pthread_mutex_t below is ** completely unsupported it does, in fact, seem to work. */ tis_mutex_init(&p->mutex); p->mutex.lock &= ~_PTHREAD_MSTATE_TYPE; /* Clear mutex type */ p->mutex.lock |= _PTHREAD_MTYPE_RECURS; /* Set mutex type to recursive */ #else /* ** Although not documented, this is the routine used by the ** CRTL on Alpha and I64 to implement the flock() routine. */ tis_mutex_init_type(&p->mutex, PTHREAD_MUTEX_RECURSIVE, 0); #endif } break; } case SQLITE_MUTEX_FAST: { p = sqlite3MallocZero( sizeof(*p) ); if( p ){ tis_mutex_init(&p->mutex); } break; } default: { assert( iType-2 >= 0 ); assert( iType-2 < ArraySize(staticMutexes) ); p = &staticMutexes[iType-2]; break; } } return p; }
pwr_tStatus sync_MutexInit ( thread_sMutex *mp ) { #if defined OS_ELN pwr_tStatus sts = SYNC__SUCCESS; ELN$CREATE_MUTEX(*mp, &sts); return sts; #elif defined OS_LYNX && defined PWR_LYNX_30 return errno_Pstatus(pthread_mutex_init(mp, NULL)); #elif defined OS_POSIX return errno_Status(pthread_mutex_init(mp, NULL)); #elif defined OS_VMS return errno_Status(tis_mutex_init(mp)); #else # error Not defined for this platform ! #endif }