Esempio n. 1
0
bool vrpn_Semaphore::init()
{
    if (vrpn_Semaphore::ppaArena == NULL) {
        vrpn_Semaphore::allocArena();
    }
    if (cResources == 1) {
        fUsingLock = true;
        ps = NULL;
        // use lock instead of semaphore
        if ((l = usnewlock(vrpn_Semaphore::ppaArena)) == NULL) {
            fprintf(stderr, "vrpn_Semaphore::vrpn_Semaphore: error allocating "
                "lock from arena.\n");
            return false;
        }
    }
    else {
        fUsingLock = false;
        l = NULL;
        if ((ps = usnewsema(vrpn_Semaphore::ppaArena, cResources)) == NULL) {
            fprintf(stderr, "vrpn_Semaphore::vrpn_Semaphore: error allocating "
                "semaphore from arena.\n");
            return false;
        }
    }
    return true;
}
Esempio n. 2
0
void CRYPTO_thread_setup(void)
{
    int i;
    char filename[20];

    lock_cs = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(usema_t *));
    if(!lock_cs) {
        /* Nothing we can do about this...void function! */
        return;
    }

    strlcpy(filename,"/tmp/mttest.XXXXXX", sizeof(filename));
    mktemp(filename);

    usconfig(CONF_STHREADIOOFF);
    usconfig(CONF_STHREADMALLOCOFF);
    usconfig(CONF_INITUSERS, 100);
    usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);
    arena = usinit(filename);
    unlink(filename);

    for (i = 0; i < CRYPTO_num_locks(); i++) {
        lock_cs[i] = usnewsema(arena, 1);
    }

    CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id);
    CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
}
Esempio n. 3
0
thread_control *
thread_control_init(thread_control *mask, int num_threads)
{
	if ((mask->mutex = usnewsema(arena, 1)) == NULL)
		return(NULL);

	mask->num_working = 0;

	return(mask);
}
Esempio n. 4
0
void* XMLPlatformUtils::makeMutex(MemoryManager*)
{
    if (arena) {
        usema_t* sema = usnewsema (arena, 1);
        if (sema && (usctlsema (sema, CS_RECURSIVEON) != -1)) {
            return (void*)sema;
        }
        else
            panic(PanicHandler::Panic_MutexErr);
    }
    else {
        // arena==0; therefore platformInit hasn't been called.
        // it's important that we fail quietly here so that we don't
        // throw an exception when trying to initizlize the
        // atomicOpsMutex, which we re-initizlize in platformInit anyay.
        return 0;
    }
}
Esempio n. 5
0
qsemh_t
qsem_alloc( ix_t cnt )
{
#ifdef HIDDEN
    usema_t *usemap;

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

    /* allocate a us semaphore
     */
    usemap = usnewsema( qlock_usp, ( intgen_t )cnt );
    ASSERT( usemap );

    return ( qsemh_t )usemap;
#else
    return 0;
#endif /* HIDDEN */
}
Esempio n. 6
0
void thread_setup(void)
{
    int i;
    char filename[20];

    sgx_strcpy(filename, "/tmp/mttest.XXXXXX");
    mktemp(filename);

    usconfig(CONF_STHREADIOOFF);
    usconfig(CONF_STHREADMALLOCOFF);
    usconfig(CONF_INITUSERS, 100);
    usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);
    arena = usinit(filename);
    unlink(filename);

    lock_cs = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(usema_t *));
    for (i = 0; i < CRYPTO_num_locks(); i++) {
        lock_cs[i] = usnewsema(arena, 1);
    }

    CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id);
    CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
}
Esempio n. 7
0
bool vrpn_Semaphore::init() {
#ifdef sgi
  if (vrpn_Semaphore::ppaArena==NULL) {
    vrpn_Semaphore::allocArena();
  }
  if (cResources==1) {
    fUsingLock=true;
    ps=NULL;
    // use lock instead of semaphore
    if ((l = usnewlock(vrpn_Semaphore::ppaArena)) == NULL) {
      fprintf(stderr,"vrpn_Semaphore::vrpn_Semaphore: error allocating lock from arena.\n");
      return false;
    }
  } else {
    fUsingLock=false;
    l=NULL;
    if ((ps = usnewsema(vrpn_Semaphore::ppaArena, cResources)) == NULL) {
      fprintf(stderr,"vrpn_Semaphore::vrpn_Semaphore: error allocating semaphore from arena.\n");
      return false;
    }
  }
#elif defined(_WIN32)
  // args are security, initial count, max count, and name
  // TCH 20 Feb 2001 - Make the PC behavior closer to the SGI behavior.
  int numMax = cResources;
  if (numMax < 1) {
    numMax = 1;
  }
  hSemaphore = CreateSemaphore(NULL, cResources, numMax, NULL);
  if (!hSemaphore) {
    // 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::vrpn_Semaphore: error creating semaphore, "
      "WIN32 CreateSemaphore call caused the following error: %s\n", (LPTSTR) lpMsgBuf);
    // Free the buffer.
    LocalFree( lpMsgBuf );
    return false;
  }
#elif defined(__APPLE__)
  // We need to use sem_open on the mac because sem_init is not implemented
    int numMax = cResources;
    if (numMax < 1) {
      numMax = 1;
    }
    char *tempname = new char[100];
    sprintf(tempname, "/tmp/vrpn_sem.XXXXXXX");
    semaphore = sem_open(mktemp(tempname), O_CREAT, 0600, numMax);
    if (semaphore == SEM_FAILED) {
        perror("vrpn_Semaphore::vrpn_Semaphore: error opening semaphore");
	delete [] tempname;
        return false;
    }
    delete [] tempname;
#else
  // Posix threads are the default.
  // We use sem_init on linux (instead of sem_open).
    int numMax = cResources;
    if (numMax < 1) {
      numMax = 1;
    }
    semaphore = new sem_t;
    if (sem_init(semaphore, 0, numMax) != 0) {
        perror("vrpn_Semaphore::vrpn_Semaphore: error initializing semaphore");
        return false;
    }
#endif

    return true;
}
Esempio n. 8
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 */