当前位置: 首页>>代码示例>>C++>>正文


C++ create_sem函数代码示例

本文整理汇总了C++中create_sem函数的典型用法代码示例。如果您正苦于以下问题:C++ create_sem函数的具体用法?C++ create_sem怎么用?C++ create_sem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_sem函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: create_sem

AudioOutput::AudioOutput(BMediaTrack *new_track, const char *name) {
	media_format	format;

	lock_count = 0;
	lock_sem = create_sem(0, "audio_output ben");
	track = new_track;
	isPlaying = false;
	perfTime = -1;
	perfTime = -1;
	trackTime = 0;
	
	track->DecodedFormat(&format);
	switch (format.u.raw_audio.format) {
	case media_raw_audio_format::B_AUDIO_UCHAR :
		default_data = 0x80;
		frame_size = 1;
		break;
	case media_raw_audio_format::B_AUDIO_SHORT :
		default_data = 0;
		frame_size = 2;
		break;
	case media_raw_audio_format::B_AUDIO_INT :
		default_data = 0;
		frame_size = 4;
		break;
	case media_raw_audio_format::B_AUDIO_FLOAT :
		default_data = 0;
		frame_size = 4;
		break;
	default :
		player = NULL;
		return;
	}
	channelCount = format.u.raw_audio.channel_count;
	frame_size *= channelCount;
	buffer_size = format.u.raw_audio.buffer_size;
	frame_rate = format.u.raw_audio.frame_rate;

	player = new BSoundPlayer(&format.u.raw_audio, name, AudioPlay);
	if (player->InitCheck() != B_OK) {
		delete player;
		player = NULL;
	} else {
		player->SetCookie(this);
		player->Start();
		player->SetHasData(true);
	}
}
开发者ID:HaikuArchives,项目名称:VirtualBeLive,代码行数:48,代码来源:AudioOutput.cpp

示例2: keyboard_open

static status_t
keyboard_open(const char *name, uint32 flags, void **_cookie)
{
	status_t status;

	TRACE("ps2: keyboard_open %s\n", name);

	if (atomic_or(&sKeyboardOpenMask, 1) != 0)
		return B_BUSY;

	status = probe_keyboard();
	if (status != B_OK) {
		INFO("ps2: keyboard probing failed\n");
		ps2_service_notify_device_removed(&ps2_device[PS2_DEVICE_KEYB]);
		goto err1;
	}

	INFO("ps2: keyboard found\n");

	sKeyboardSem = create_sem(0, "keyboard_sem");
	if (sKeyboardSem < 0) {
		status = sKeyboardSem;
		goto err1;
	}

	sKeyBuffer = create_packet_buffer(KEY_BUFFER_SIZE * sizeof(at_kbd_io));
	if (sKeyBuffer == NULL) {
		status = B_NO_MEMORY;
		goto err2;
	}

	*_cookie = NULL;
	ps2_device[PS2_DEVICE_KEYB].disconnect = &ps2_keyboard_disconnect;
	ps2_device[PS2_DEVICE_KEYB].handle_int = &keyboard_handle_int;

	atomic_or(&ps2_device[PS2_DEVICE_KEYB].flags, PS2_FLAG_ENABLED);

	TRACE("ps2: keyboard_open %s success\n", name);
	return B_OK;

err2:
	delete_sem(sKeyboardSem);
err1:
	atomic_and(&sKeyboardOpenMask, 0);

	TRACE("ps2: keyboard_open %s failed\n", name);
	return status;
}
开发者ID:mmanley,项目名称:Antares,代码行数:48,代码来源:ps2_keyboard.c

示例3: be_mouse_init

extern "C" int be_mouse_init(void)
{
   sem_id mouse_started;
   int32  num_buttons;

   mouse_started = create_sem(0, "starting mouse driver...");

   if (mouse_started < 0) {
      goto cleanup;
   }

   mouse_thread_id = spawn_thread(mouse_thread, MOUSE_THREAD_NAME,
                        MOUSE_THREAD_PRIORITY, &mouse_started); 

   if (mouse_thread_id < 0) {
      goto cleanup;
   }

   mouse_thread_running = true;
   resume_thread(mouse_thread_id);
   acquire_sem(mouse_started);
   delete_sem(mouse_started);

   be_mickey_x = 0;
   be_mickey_y = 0;

   be_mouse_x = 0;
   be_mouse_y = 0;
   be_mouse_b = 0;

   limit_up     = 0;
   limit_down   = 0;
   limit_left   = 0;
   limit_right  = 0;

   get_mouse_type(&num_buttons);

   return num_buttons;

   cleanup: {
      if (mouse_started > 0) {
         delete_sem(mouse_started);
      }

      be_mouse_exit();
      return 0;
   }
}
开发者ID:dodamn,项目名称:pkg-allegro4.2,代码行数:48,代码来源:bmousapi.cpp

示例4: mutex_lock

static status_t
mutex_lock(pthread_mutex_t *mutex, bigtime_t timeout)
{
	thread_id thisThread = find_thread(NULL);
	status_t status = B_OK;

	if (mutex == NULL)
		return B_BAD_VALUE;

	// If statically initialized, we need to create the semaphore, now.
	if (mutex->sem == -42) {
		sem_id sem = create_sem(0, "pthread_mutex");
		if (sem < 0)
			return EAGAIN;

		if (atomic_test_and_set((vint32*)&mutex->sem, sem, -42) != -42)
			delete_sem(sem);
	}

	if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_ERRORCHECK
		&& mutex->owner == thisThread) {
		// we detect this kind of deadlock and return an error
		return EDEADLK;
	}

	if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_RECURSIVE
		&& mutex->owner == thisThread) {
		// if we already hold the mutex, we don't need to grab it again
		mutex->owner_count++;
		return B_OK;
	}

	if (atomic_add((vint32*)&mutex->count, 1) > 0) {
		// this mutex is already locked by someone else, so we need
		// to wait
		status = acquire_sem_etc(mutex->sem, 1,
			timeout == B_INFINITE_TIMEOUT ? 0 : B_ABSOLUTE_REAL_TIME_TIMEOUT,
			timeout);
	}

	if (status == B_OK) {
		// we have locked the mutex for the first time
		mutex->owner = thisThread;
		mutex->owner_count = 1;
	}

	return status;
}
开发者ID:mmanley,项目名称:Antares,代码行数:48,代码来源:pthread_mutex.c

示例5: PointToTime

void
_MediaSlider_::MouseDown(
	BPoint	where)
{
	fOwner->fScrubTime = PointToTime(where);
	fOwner->fScrubSem = create_sem(1, "MediaView::fScrubSem");

	if (!fOwner->fPlaying) {
		release_sem(fOwner->fPlaySem);
		acquire_sem(fOwner->fPlaySem);
	}

	SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);

	fMouseDown = true;
}
开发者ID:HaikuArchives,项目名称:VirtualBeLive,代码行数:16,代码来源:MediaSlider.cpp

示例6: _LoadBackgroundInfo

void
ActivityView::AttachedToWindow()
{
	if (Parent() && (Parent()->Flags() & B_DRAW_ON_CHILDREN) != 0)
		_LoadBackgroundInfo(true);

	Looper()->AddHandler(fSystemInfoHandler);
	fSystemInfoHandler->StartWatching();

	fRefreshSem = create_sem(0, "refresh sem");
	fRefreshThread = spawn_thread(&_RefreshThread, "source refresh",
		B_URGENT_DISPLAY_PRIORITY, this);
	resume_thread(fRefreshThread);

	FrameResized(Bounds().Width(), Bounds().Height());
}
开发者ID:mariuz,项目名称:haiku,代码行数:16,代码来源:ActivityView.cpp

示例7: setup_context

void
setup_context(struct context& context, bool server)
{
	list_init(&context.list);
	context.route.interface = &gInterface;
	context.route.gateway = (sockaddr *)&context;
		// backpointer to the context
	context.route.mtu = 1500;
	context.server = server;
	context.wait_sem = create_sem(0, "receive wait");

	context.thread = spawn_thread(receiving_thread,
		server ? "server receiver" : "client receiver", B_NORMAL_PRIORITY,
		&context);
	resume_thread(context.thread);
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:16,代码来源:tcp_shell.cpp

示例8: _RegisterCommands

status_t
CommandLineUserInterface::Init(Team* team, UserInterfaceListener* listener)
{
	fTeam = team;
	fListener = listener;

	status_t error = _RegisterCommands();
	if (error != B_OK)
		return error;

	fShowSemaphore = create_sem(0, "show CLI");
	if (fShowSemaphore < 0)
		return fShowSemaphore;

	return B_OK;
}
开发者ID:mmadia,项目名称:haiku,代码行数:16,代码来源:CommandLineUserInterface.cpp

示例9: fInit

MultiLocker::MultiLocker(const char* semaphoreBaseName)
	:	fInit(B_NO_INIT),
		fReadCount(0),
		fReadSem(-1),
		fWriteCount(0),
		fWriteSem(-1),
		fLockCount(0),
		fWriterLock(-1),
		fWriterNest(0),
		fWriterThread(-1),
		fWriterStackBase(0),
		fDebugArray(NULL),
		fMaxThreads(0)
{
	//build the semaphores
	if (semaphoreBaseName) {
		char name[128];
		sprintf(name, "%s-%s", semaphoreBaseName, "ReadSem");
		fReadSem = create_sem(0, name);
		sprintf(name, "%s-%s", semaphoreBaseName, "WriteSem");
		fWriteSem = create_sem(0, name);
		sprintf(name, "%s-%s", semaphoreBaseName, "WriterLock");
		fWriterLock = create_sem(0, name);
	} else {
		fReadSem = create_sem(0, "MultiLocker_ReadSem");
		fWriteSem = create_sem(0, "MultiLocker_WriteSem");
		fWriterLock = create_sem(0, "MultiLocker_WriterLock");
	}

	if (fReadSem >= 0 && fWriteSem >=0 && fWriterLock >= 0)
		fInit = B_OK;
		
	#if DEBUG
		//we are in debug mode!
		//create the reader tracking list
		//the array needs to be large enough to hold all possible threads
		system_info sys;
		get_system_info(&sys);
		fMaxThreads = sys.max_threads;
		fDebugArray = (int32 *) malloc(fMaxThreads * sizeof(int32));
		for (int32 i = 0; i < fMaxThreads; i++) {
			fDebugArray[i] = 0;
		}
		
	#endif
	#if TIMING
		//initialize the counter variables
		rl_count = ru_count = wl_count = wu_count = islock_count = 0;
		rl_time = ru_time = wl_time = wu_time = islock_time = 0;
		#if DEBUG
			reg_count = unreg_count = 0;
			reg_time = unreg_time = 0;
		#endif
	#endif
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:55,代码来源:MultiLocker.cpp

示例10: create_sem

status_t
RemoteDrawingEngine::_AddCallback()
{
	if (fCallbackAdded)
		return B_OK;

	if (fResultNotify < 0)
		fResultNotify = create_sem(0, "drawing engine result");
	if (fResultNotify < 0)
		return fResultNotify;

	status_t result = fHWInterface->AddCallback(fToken, &_DrawingEngineResult,
		this);

	fCallbackAdded = result == B_OK;
	return result;
}
开发者ID:mariuz,项目名称:haiku,代码行数:17,代码来源:RemoteDrawingEngine.cpp

示例11: create_sem

/* Create a counting semaphore */
SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
{
	SDL_sem *sem;

	sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
	if ( sem ) {
		sem->id = create_sem(initial_value, "SDL semaphore");
		if ( sem->id < B_NO_ERROR ) {
			SDL_SetError("create_sem() failed");
			SDL_free(sem);
			sem = NULL;
		}
	} else {
		SDL_OutOfMemory();
	}
	return(sem);
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:18,代码来源:SDL_syssem.c

示例12: create_sem

status_t
DebugReportGenerator::Init()
{
	fTeamDataSem = create_sem(0, "debug_controller_data_wait");
	if (fTeamDataSem < B_OK)
		return fTeamDataSem;

	fNodeManager = new(std::nothrow) ValueNodeManager();
	if (fNodeManager == NULL)
		return B_NO_MEMORY;

	fNodeManager->AddListener(this);

	Run();

	return B_OK;
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:17,代码来源:DebugReportGenerator.cpp

示例13: main

int main()
{
	void *shm_area;
	struct region *rptr;
	int fd;

	/* Create shared memory object and set its size */
	fd = shm_open("./myshm", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
	if (fd == -1)
	    printf("\n Failed to open shared memory object\n");


	if (ftruncate(fd,  MAX_LEN) == -1)
	    printf("\n Failed to set the size of the shared memory object\n");

	/* Map shared memory object */
	shm_area = mmap(NULL,  MAX_LEN,PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	if (rptr == MAP_FAILED)
	    printf("\n Failed to map the shared memory\n");
	getchar();
	create_sem();	
	getchar();		
	if (sem_wait (mysem))
	{
            printf("\n Failed to Lock Semaphore\n");
	    exit(1);
        }	// Entering critical section 
		rptr = (struct region *)shm_area;	
		strcpy(rptr->buf,"Message One");
		rptr->len=strlen("Message One");
		rptr++;
		strcpy(rptr->buf,"Message Two");
		rptr->len=strlen("Message Two");
		getchar();
		rptr++;
		strcpy(rptr->buf,"Message Three");
		rptr->len=strlen("Message Three");
	sem_post (mysem);
        // Leaving critical section 
	if (munmap (shm_area, MAX_LEN))
       	    printf("\n Failed to map the shared memory\n");
	printf("\n %d \n",sem_close (mysem));
	close(fd);

}
开发者ID:coder03,项目名称:ldd,代码行数:45,代码来源:process1.c

示例14: create_sem

int32
BAlert::Go()
{
	fAlertSem = create_sem(0, "AlertSem");
	if (fAlertSem < B_OK) {
		Quit();
		return -1;
	}

	// Get the originating window, if it exists
	BWindow* window =
		dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL)));

	Show();

	// Heavily modified from TextEntryAlert code; the original didn't let the
	// blocked window ever draw.
	if (window) {
		status_t err;
		for (;;) {
			do {
				err = acquire_sem_etc(fAlertSem, 1, B_RELATIVE_TIMEOUT,
									  kSemTimeOut);
				// We've (probably) had our time slice taken away from us
			} while (err == B_INTERRUPTED);

			if (err == B_BAD_SEM_ID) {
				// Semaphore was finally nuked in MessageReceived
				break;
			}
			window->UpdateIfNeeded();
		}
	} else {
		// No window to update, so just hang out until we're done.
		while (acquire_sem(fAlertSem) == B_INTERRUPTED) {
		}
	}

	// Have to cache the value since we delete on Quit()
	int32 value = fAlertValue;
	if (Lock())
		Quit();

	return value;
}
开发者ID:mmanley,项目名称:Antares,代码行数:45,代码来源:Alert.cpp

示例15: main

int main()
{
	int sem_id = create_sem(1);
	init_sem(sem_id, 0, 1);

	pid_t id = fork();
	if(id < 0)
	{
		perror("fork");
		return -1;
	}
	else if(id == 0)
	{//child
		while(1)
		{
			sem_P(sem_id);

			printf("A");
			fflush(stdout);
			usleep(20000);
			usleep(23456);
			printf("A");

			sem_V(sem_id);
		}
	}
	else
	{//father
		while(1)
		{
			sem_P(sem_id);

			printf("B");
			fflush(stdout);
			usleep(29633);
			usleep(23456);
			printf("B");

			sem_V(sem_id);
		}
	}

	destroy_sem(sem_id);
	return 0;
}
开发者ID:jaeee,项目名称:jaee-Demo,代码行数:45,代码来源:semtest.c


注:本文中的create_sem函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。