Example #1
0
main()
{
	SEMAPHOREP sem ;
	int rc ;
	int i ;

	sem = semaphore_open(1234) ;

	if (!sem) {
		printf("semaphore_open() failed\n") ;
		exit(1) ;
	}

	for (i = 0; i < 10; i++) {
		printf("Releasing semaphore iteration %d\n", i) ;
		rc = semaphore_increment(sem) ;
		if (! rc) {
			printf("semaphore_increment() failed\n") ;
			exit(1) ;
		}
		sleep(1) ;
	}

	rc = semaphore_destroy(sem, 0) ;
	if (! rc) {
		printf("semaphore_destroy(sem, 0) failed\n") ;
		exit(1) ;
	}

	exit(0) ;
}
Example #2
0
int
main(int argc, const char** argv)
{
    semaphore_t *semap;

    semap = semaphore_open("/tmp/semaphore");
    if (semap == NULL) return 1;
    semaphore_post(semap);
    semaphore_close(semap);
    return 0;
}
Example #3
0
int semaphore_create()
{
	int flag_sem = O_CREAT|O_RDWR;
	int init_value = 1;

	semaphore_unlink(SEM_NAME);
	
	if (semaphore_open(SEM_NAME, flag_sem, FILE_MODE, init_value) == -1)
	{
		perror("semaphore_create fail");
		return -1;
	}

	return 0;
}
Example #4
0
void
netcmd_semaphore_init (void)
{
  semaphore_open (&netcmd_semaphore, PACKAGE "_netcmd");
}
Example #5
0
 named_semaphore_wrapper
    (detail::create_enum_t type, const char *name, mode_t mode, unsigned int count)
 {  semaphore_open(mp_sem, type, name, mode, count);   }
Example #6
0
 named_semaphore_wrapper
    (ipcdetail::create_enum_t type, const char *name, unsigned int count, const permissions &perm = permissions())
 {  semaphore_open(mp_sem, type, name, count, perm);   }
Example #7
0
BLOCKDEVICEP 
blockdevice_open(char *name)
{
	BLOCKDEVICEP devp ;
	int rc ;

	/*
	** Shared memory has only been setup for 1 block device (currently).
	** This makes open really easy. We just attach to the shared memory
	** segment, suck the header information out, fill up our structure,
	** and away we go. Of course, there is absolutely no error checking
	** here (yet), we could run into the case where the shared memory
	** has not been created yet. We'll worry about this later. Iterate,
	** iterate, iterate.
	*/

	devp = malloc(sizeof(BLOCKDEVICE)) ;

	if (NULL == devp) {
		return NULL ;
	}

	devp->name = malloc(strlen(name)+1) ;

	if (NULL == devp->name) {
		free(devp) ;
		return NULL ;
	}

	devp->sem = semaphore_open(1234) ;

	if (! devp->sem) {
		free(devp) ;
		return NULL ;
	}

	devp->dirtysem = semaphore_open(1235) ;

	if (! devp->dirtysem) {
		free(devp) ;
		return NULL ;
	}

	rc = shmem_open() ;

	if (0 == rc) {
		semaphore_destroy(devp->sem, 0) ;
		semaphore_destroy(devp->dirtysem, 0) ;
		free(devp->name) ;
		free(devp) ;
		return NULL ;
	}

	devp->bd = (struct SHMEM_BLOCK_OVERLAY *) shmem_get_memptr() ;

	strcpy(devp->name, name) ;
	devp->blocksize = devp->bd->header.blocksize ;
	devp->numblocks = devp->bd->header.numblocks ;

	return devp ;
}
 posix_named_semaphore(open_only_t, const char *name)
 {
     semaphore_open(mp_sem, DoOpen, name);
 }
 posix_named_semaphore(open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm = permissions())
 {
     semaphore_open(mp_sem, DoOpenOrCreate, name, initialCount, perm);
 }