• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ create_sem函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: tr_lockNew

tr_lock*
tr_lockNew( void )
{
    tr_lock *           l = tr_new0( tr_lock, 1 );

#ifdef __BEOS__
    l->lock = create_sem( 1, "" );
#elif defined( WIN32 )
    InitializeCriticalSection( &l->lock ); /* supports recursion */
#else
    pthread_mutexattr_t attr;
    pthread_mutexattr_init( &attr );
    pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
    pthread_mutex_init( &l->lock, &attr );
#endif

    return l;
}
开发者ID:fangang190,项目名称:canary,代码行数:18,代码来源:platform.c


示例17: BWindow

CreateParamsPanel::CreateParamsPanel(BWindow* window, BPartition* partition,
	off_t offset, off_t size)
	: BWindow(BRect(300.0, 200.0, 600.0, 300.0), 0, B_MODAL_WINDOW_LOOK,
		B_MODAL_SUBSET_WINDOW_FEEL,
		B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
	fEscapeFilter(new EscapeFilter(this)),
	fExitSemaphore(create_sem(0, "CreateParamsPanel exit")),
	fWindow(window),
	fReturnValue(GO_CANCELED)
{
	AddCommonFilter(fEscapeFilter);

	// Scale offset, and size from bytes to megabytes (2^20)
	// so that we do not run over a signed int32.
	offset /= kMegaByte;
	size /= kMegaByte;
	_CreateViewControls(partition, offset, size);
}
开发者ID:mmanley,项目名称:Antares,代码行数:18,代码来源:CreateParamsPanel.cpp


示例18: create_sem

int32 TextEntryAlert::Go(BmString& text_entry_buffer)
{
	int32 button_pressed = -1;
	m_text_entry_buffer = &text_entry_buffer;
	m_button_pressed = &button_pressed;
	sem_id done_mutex = create_sem(0,"text_entry_alert_done");
	m_done_mutex = done_mutex;
	if(done_mutex < B_NO_ERROR)
	{
		Quit();
		return -1;
	}
	m_text_entry_view->MakeFocus(true);
	Show();
	acquire_sem(done_mutex);
	delete_sem(done_mutex);
	return button_pressed;
}
开发者ID:HaikuArchives,项目名称:Beam,代码行数:18,代码来源:TextEntryAlert.cpp


示例19: FUNCTION

status_t
TVideoPreviewView::Connected(
	const media_source & producer,
	const media_destination & where,
	const media_format & with_format,
	media_input* out_input)
{
	FUNCTION("TVideoPreviewView::Connected()\n");

	out_input->node = Node();
	out_input->source = mProducer = producer;
	out_input->destination = mDestination;
	out_input->format = with_format;
	sprintf(out_input->name, "TVideoPreviewView");

	mXSize          = with_format.u.raw_video.display.line_width;
	mYSize          = with_format.u.raw_video.display.line_count;
	mRowBytes       = with_format.u.raw_video.display.bytes_per_row;
	mColorspace = with_format.u.raw_video.display.format;

	mBufferAvailable = create_sem (0, "Video buffer available");
	if (mBufferAvailable < B_NO_ERROR) {
		ERROR("TVideoPreviewView: couldn't create semaphore\n");
		return B_ERROR;
	}

	mBufferQueue = new BTimedBufferQueue();

	//	Create offscreen
	if (m_Bitmap == NULL) {
		m_Bitmap = new BBitmap(BRect(0, 0, (mXSize-1), (mYSize - 1)), mColorspace, false, false);
	}

	if (vThread == 0) {
		mDisplayQuit = false;
		int drawPrio = suggest_thread_priority(B_VIDEO_PLAYBACK, 30, 1000, 5000);
		PROGRESS("Suggested draw thread priority: %d\n", drawPrio);
		vThread = spawn_thread(vRun, "TVideoPreviewView:draw", drawPrio, this);
		resume_thread(vThread);
	}

	mConnected = true;
	return B_OK;
}
开发者ID:Barrett17,项目名称:UltraDV,代码行数:44,代码来源:TVideoPreviewView.cpp


示例20: system_time

void
MixerSettings::StartDeferredSave()
{
	fLocker->Lock();

	// if we don't have a settings file, don't save the settings
	if (!fSettingsFile) {
		fLocker->Unlock();
		return;
	}

	fSettingsDirty = true;
	fSettingsLastChange = system_time();

	if (fSaveThreadRunning) {
		fLocker->Unlock();
		return;
	}

	StopDeferredSave();

	ASSERT(fSaveThreadWaitSem < 0);
	fSaveThreadWaitSem = create_sem(0, "save thread wait");
	if (fSaveThreadWaitSem < B_OK) {
		ERROR("MixerSettings: can't create semaphore\n");
		Save();
		fLocker->Unlock();
		return;
	}
	ASSERT(fSaveThread < 0);
	fSaveThread = spawn_thread(_save_thread_, "Attack of the Killer Tomatoes", 7, this);
	if (fSaveThread < B_OK) {
		ERROR("MixerSettings: can't spawn thread\n");
		delete_sem(fSaveThreadWaitSem);
		fSaveThreadWaitSem = -1;
		Save();
		fLocker->Unlock();
		return;
	}
	resume_thread(fSaveThread);

	fSaveThreadRunning = true;
	fLocker->Unlock();
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:44,代码来源:MixerSettings.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ create_server函数代码示例发布时间:2022-05-30
下一篇:
C++ create_request函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap