int tMPI_Thread_mutex_lock(tMPI_Thread_mutex_t *mtx) { /* check whether the mutex is initialized */ if (tMPI_Atomic_get( &(mtx->initialized) ) == 0) { tMPI_Thread_mutex_init_once(mtx); } /* The mutex is now guaranteed to be valid. */ EnterCriticalSection( &(mtx->mutex->cs) ); return 0; }
int tMPI_Thread_mutex_unlock(tMPI_Thread_mutex_t *mtx) { int ret; /* check whether the mutex is initialized */ if (tMPI_Atomic_get( &(mtx->initialized) ) == 0) { ret=tMPI_Thread_mutex_init_once(mtx); if (ret) return ret; } ret = pthread_mutex_unlock(&(mtx->mutex->mtx)); return ret; }