TVeosErr ShMem_Close() { TVeosErr iErr; boolean bLast = FALSE; THSharedRec hFinger; TPSharedRec pSaveLink; TPSemaphor pSaveSem; iErr = VEOS_SUCCESS; #ifdef _SG_ /** stop others from looking at the channel chain **/ uspsema(SHMEM_DOMAIN->pChainSem); /** this channel is about to vanish ** wait for others to finish looking at this channel **/ pSaveSem = SHMEM_CHANNEL->pSem; uspsema(pSaveSem); /** find our channel in the domain channel chain, ** remove it, recoupling the links, and free the memory **/ hFinger = &SHMEM_DOMAIN->pChannelChain; while (*hFinger) { if (*hFinger == SHMEM_CHANNEL) { pSaveLink = (*hFinger)->pNext; usfree(*hFinger, SHMEM_ARENA); *hFinger = pSaveLink; break; } hFinger = &(*hFinger)->pNext; } /** release and remove the channel semaphore **/ usvsema(pSaveSem); usfreesema(pSaveSem, SHMEM_ARENA); if (SHMEM_DOMAIN->pChannelChain == nil) bLast = TRUE; /** allow others to cleanly find no channel **/ usvsema(SHMEM_DOMAIN->pChainSem); if (bLast) { usfreesema(SHMEM_DOMAIN->pChainSem, SHMEM_ARENA); usfree(SHMEM_DOMAIN, SHMEM_ARENA); unlink(SHMEM_ARENA_FILE); } #endif return(iErr); } /* ShMem_Close */
void buf_read_end(thread_control *tmask, usema_t *mainwait) { uspsema(tmask->mutex); tmask->num_working--; if (tmask->num_working == 0) { usvsema(mainwait); } usvsema(tmask->mutex); }
void buf_read_error(thread_control *tmask, usema_t *mainwait, thread_id id) { uspsema(tmask->mutex); tmask->num_working--; target_states[id] = INACTIVE; if (tmask->num_working == 0) { usvsema(mainwait); } usvsema(tmask->mutex); }
void qsemV( qsemh_t qsemh ) { #ifdef HIDDEN usema_t *usemap = ( usema_t * )qsemh; intgen_t rval; /* sanity checks */ ASSERT( qlock_inited ); ASSERT( qlock_usp ); /* "V" the semaphore */ rval = usvsema( usemap ); if ( rval != 0 ) { mlog( MLOG_NORMAL | MLOG_ERROR | MLOG_NOLOCK, _("unable to \"V\" semaphore: " "rval == %d, errno == %d (%s)\n"), rval, errno, strerror( errno )); } ASSERT( rval == 0 ); #endif /* HIDDEN */ }
void irix_locking_callback(int mode, int type, char *file, int line) { if (mode & CRYPTO_LOCK) { uspsema(lock_cs[type]); } else { usvsema(lock_cs[type]); } }
void irix_locking_callback(int mode, int type, char *file, int line) { if (mode & CRYPTO_LOCK) { printf("lock %d\n", type); uspsema(lock_cs[type]); } else { printf("unlock %d\n", type); usvsema(lock_cs[type]); } }
void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { if (usvsema(mtxHandle) == -1) { panic(PanicHandler::Panic_MutexErr); } } }
// 0 on success, -1 fail int vrpn_Semaphore::v() { #ifdef sgi if (fUsingLock) { if (usunsetlock(l)) { perror("vrpn_Semaphore::v: usunsetlock:"); return -1; } } else { if (usvsema(ps)) { perror("vrpn_Semaphore::v: uspsema:"); return -1; } } #elif defined(_WIN32) if (!ReleaseSemaphore(hSemaphore, 1, NULL)) { // get error info from windows (from FormatMessage help page) LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR)&lpMsgBuf, 0, NULL); fprintf(stderr, "vrpn_Semaphore::v: error v'ing semaphore, " "WIN32 ReleaseSemaphore call caused the following error: %s", (LPTSTR)lpMsgBuf); // Free the buffer. LocalFree(lpMsgBuf); return -1; } #else // Posix by default if (sem_post(semaphore) != 0) { perror("vrpn_Semaphore::p: "); return -1; } #endif return 0; }
TVeosErr ShMem_Init() { TVeosErr iErr; boolean bTrap; str255 sSave; iErr = VEOS_SUCCESS; #ifdef _SG_ usconfig(CONF_INITSIZE, SHMEM_SHARED_BUF_SIZE); iErr = SHMEM_INIT_ERR; SHMEM_ARENA = usinit(SHMEM_ARENA_FILE); CATCH_TRAP(SIGBUS, bTrap); if (bTrap || (SHMEM_ARENA == nil)) { strcpy(sSave, "/bin/rm/ -f "); strcat(sSave, SHMEM_ARENA_FILE); system(sSave); SHMEM_ARENA = usinit(SHMEM_ARENA_FILE); } if (TALK_BUGS) fprintf(stderr, "talk %s: attaching to shared memory arena %s\n", WHOAMI, SHMEM_ARENA ? "was successful" : "failed"); if (SHMEM_ARENA) { SHMEM_DOMAIN = usgetinfo(SHMEM_ARENA); if (TALK_BUGS) fprintf(stderr, "talk %s: veos communication domain %s\n", WHOAMI, SHMEM_DOMAIN ? "found" : "not found, creating one..."); if (SHMEM_DOMAIN == nil) { /** first entity on this machine, ** initialize the shmem domain **/ chmod(SHMEM_ARENA_FILE, 0777); iErr = VEOS_MEM_ERR; SHMEM_DOMAIN = usmalloc(sizeof(TShDomainRec), SHMEM_ARENA); if (SHMEM_DOMAIN) { SHMEM_DOMAIN->pChainSem = usnewsema(SHMEM_ARENA, 1); SHMEM_DOMAIN->pChannelChain = nil; usputinfo(SHMEM_ARENA, SHMEM_DOMAIN); } } if (SHMEM_DOMAIN) { if (TALK_BUGS) fprintf(stderr, "talk %s: creating memory listen channel...\n", WHOAMI); iErr = VEOS_MEM_ERR; SHMEM_CHANNEL = usmalloc(sizeof(TSharedRec), SHMEM_ARENA); if (SHMEM_CHANNEL) { SHMEM_CHANNEL->iPort = IDENT_ADDR.iPort; SHMEM_CHANNEL->pSem = usnewsema(SHMEM_ARENA, 1); SHMEM_CHANNEL->pAvail = &SHMEM_CHANNEL->pBuffer[0]; SHMEM_CHANNEL->pEnd = &SHMEM_CHANNEL->pBuffer[0] + SHMEM_RW_BUF_SIZE; /** link new entity channel into shared domain record **/ uspsema(SHMEM_DOMAIN->pChainSem); SHMEM_CHANNEL->pNext = SHMEM_DOMAIN->pChannelChain; SHMEM_DOMAIN->pChannelChain = SHMEM_CHANNEL; usvsema(SHMEM_DOMAIN->pChainSem); iErr = VEOS_SUCCESS; } } } #endif return(iErr); } /* ShMem_Init */