Exemplo n.º 1
0
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 */
Exemplo n.º 2
0
void
qsemP( qsemh_t qsemh )
{
#ifdef HIDDEN
    usema_t *usemap = ( usema_t * )qsemh;
    intgen_t rval;

    /* sanity checks
     */
    ASSERT( qlock_inited );
    ASSERT( qlock_usp );

    /* "P" the semaphore
     */
    rval = uspsema( usemap );
    if ( rval != 1 ) {
        mlog( MLOG_NORMAL | MLOG_ERROR | MLOG_NOLOCK,
              _("unable to \"P\" semaphore: "
                "rval == %d, errno == %d (%s)\n"),
              rval,
              errno,
              strerror( errno ));
    }
    ASSERT( rval == 1 );
#endif /* HIDDEN */
}
Exemplo n.º 3
0
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]);
    }
}
Exemplo n.º 4
0
// routines to use it (p blocks, cond p does not)
// 1 on success, -1 fail
int vrpn_Semaphore::p()
{
#ifdef sgi
    if (fUsingLock) {
        if (ussetlock(l) != 1) {
            perror("vrpn_Semaphore::p: ussetlock:");
            return -1;
        }
    }
    else {
        if (uspsema(ps) != 1) {
            perror("vrpn_Semaphore::p: uspsema:");
            return -1;
        }
    }
#elif defined(_WIN32)
    switch (WaitForSingleObject(hSemaphore, INFINITE)) {
    case WAIT_OBJECT_0:
        // got the resource
        break;
    case WAIT_TIMEOUT:
        ALL_ASSERT(0, "vrpn_Semaphore::p: infinite wait time timed out!");
        return -1;
        break;
    case WAIT_ABANDONED:
        ALL_ASSERT(0, "vrpn_Semaphore::p: thread holding resource died");
        return -1;
        break;
    case WAIT_FAILED:
        // 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::p: error waiting for resource, "
            "WIN32 WaitForSingleObject call caused the following error: %s",
            (LPTSTR)lpMsgBuf);
        // Free the buffer.
        LocalFree(lpMsgBuf);
        return -1;
        break;
    default:
        ALL_ASSERT(0, "vrpn_Semaphore::p: unknown return code");
        return -1;
    }
#else
    // Posix by default
    if (sem_wait(semaphore) != 0) {
        perror("vrpn_Semaphore::p: ");
        return -1;
    }
#endif
    return 1;
}
Exemplo n.º 5
0
void XMLPlatformUtils::lockMutex(void* const mtxHandle)
{

    if (mtxHandle != NULL) {
        if (uspsema (mtxHandle) != 1)
            panic(PanicHandler::Panic_MutexErr);
    }

}
Exemplo n.º 6
0
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]);
    }
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
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);

}
Exemplo n.º 9
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 */