int DXcreate_lock(lock_type *l, char *name) { static int been_here = 0; if (!been_here) { been_here = 1; if (!_dxf_initlocks()) return NULL; } if(!msem_init(l, MSEM_UNLOCKED)) DXErrorReturn(ERROR_INTERNAL, "Error creating lock"); return OK; }
static void clean_initialize(mutex_struct_ptr_t addr, int n, bool crash) { mutex_que_entry_ptr_t q_free_entry; # if defined(MUTEX_MSEM_WAKE) && !defined(POSIX_MSEM) msemaphore *status; # endif assert(n > 0); addr->queslots = n; /* Initialize the waiting process queue to be empty */ addr->prochead.que.fl = addr->prochead.que.bl = 0; SET_LATCH_GLOBAL(&addr->prochead.latch, LOCK_AVAILABLE); /* Initialize the free queue to be empty */ addr->freehead.que.fl = addr->freehead.que.bl = 0; SET_LATCH_GLOBAL(&addr->freehead.latch, LOCK_AVAILABLE); /* Clear the first free entry */ q_free_entry = (mutex_que_entry_ptr_t)((sm_uc_ptr_t)&addr->freehead + SIZEOF(mutex_que_head)); q_free_entry->que.fl = q_free_entry->que.bl = 0; q_free_entry->pid = 0; q_free_entry->super_crit = (void *)NULL; q_free_entry->mutex_wake_instance = 0; while (n--) { # ifdef MUTEX_MSEM_WAKE # ifdef POSIX_MSEM if (-1 == sem_init(&q_free_entry->mutex_wake_msem, TRUE, 0)) /* Shared lock with no initial resources (locked) */ # else if ((NULL == (status = msem_init(&q_free_entry->mutex_wake_msem, MSEM_LOCKED))) || ((msemaphore *)-1 == status)) # endif rts_error_csa(CSA_ARG(NULL) VARLSTCNT(7) ERR_MUTEXERR, 0, ERR_TEXT, 2, RTS_ERROR_TEXT("Error with mutex wait memory semaphore initialization"), errno); # endif /* Initialize fl,bl links to 0 before INSQTI as it (gtm_insqti in relqueopi.c) asserts this */ DEBUG_ONLY(((que_ent_ptr_t)q_free_entry)->fl = 0;) DEBUG_ONLY(((que_ent_ptr_t)q_free_entry)->bl = 0;) if (INTERLOCK_FAIL == INSQTI((que_ent_ptr_t)q_free_entry++, (que_head_ptr_t)&addr->freehead))