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


C++ semaphore_wait函数代码示例

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


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

示例1: vlc_sem_wait

/**
 * Atomically wait for the semaphore to become non-zero (if needed),
 * then decrements it.
 */
void vlc_sem_wait (vlc_sem_t *sem)
{
    int val;

#if defined(__APPLE__)
    if (likely(semaphore_wait(*sem) == KERN_SUCCESS))
        return;

    val = EINVAL;
#else
    do
        if (likely(sem_wait (sem) == 0))
            return;
    while ((val = errno) == EINTR);
#endif

    VLC_THREAD_ASSERT ("locking semaphore");
}
开发者ID:cmassiot,项目名称:vlc-broadcast,代码行数:22,代码来源:pthread.c

示例2: _dispatch_thread_semaphore_wait

void
_dispatch_thread_semaphore_wait(_dispatch_thread_semaphore_t sema)
{
#if USE_MACH_SEM
    semaphore_t s4 = (semaphore_t)sema;
    kern_return_t kr;
    do {
        kr = semaphore_wait(s4);
    } while (slowpath(kr == KERN_ABORTED));
    DISPATCH_SEMAPHORE_VERIFY_KR(kr);
#elif USE_POSIX_SEM
    sem_t s4 = (sem_t)sema;
    int ret;
    do {
        ret = sem_wait(&s4);
    } while (slowpath(ret != 0));
    DISPATCH_SEMAPHORE_VERIFY_RET(ret);
#endif
}
开发者ID:deepvision,项目名称:libdispatch,代码行数:19,代码来源:semaphore.c

示例3: assert

thread_t *thread_new_sized(const char *name, size_t work_queue_capacity) {
  assert(name != NULL);
  assert(work_queue_capacity != 0);

  thread_t *ret = osi_calloc(sizeof(thread_t));
  if (!ret)
    goto error;

  ret->reactor = reactor_new();
  if (!ret->reactor)
    goto error;

  ret->work_queue = fixed_queue_new(work_queue_capacity);
  if (!ret->work_queue)
    goto error;

  // Start is on the stack, but we use a semaphore, so it's safe
  struct start_arg start;
  start.start_sem = semaphore_new(0);
  if (!start.start_sem)
    goto error;

  strncpy(ret->name, name, THREAD_NAME_MAX);
  start.thread = ret;
  start.error = 0;
  pthread_create(&ret->pthread, NULL, run_thread, &start);
  semaphore_wait(start.start_sem);
  semaphore_free(start.start_sem);

  if (start.error)
    goto error;

  return ret;

error:;
  if (ret) {
    fixed_queue_free(ret->work_queue, osi_free);
    reactor_free(ret->reactor);
  }
  osi_free(ret);
  return NULL;
}
开发者ID:ghostrider96,项目名称:platform_system_bt,代码行数:42,代码来源:thread.c

示例4: fast_sendrecv_m

inline int
fast_sendrecv_m (task_id dst_id, u32 arg1, u32 arg2, u32 *r_arg1, u32 *r_arg2)
{
  quest_tss *src = lookup_TSS (str ());
  quest_tss *dst = lookup_TSS (dst_id);

  semaphore_wait (&dst->Msem, 1, -1);
  dst->M[0] = arg1;
  dst->M[1] = arg2;
  semaphore_signal (&src->Msem, 1);
  ltr (dst_id);
  asm volatile ("call _sw_ipc"
                :"+S" (src), "+D" (dst)
                :
                :"eax", "ebx", "ecx", "edx", "cc", "memory");
  /* after _sw_ipc dst and src are swapped */
  *r_arg1 = dst->M[0];
  *r_arg2 = dst->M[1];
  return 0;
}
开发者ID:Quest-V,项目名称:quest,代码行数:20,代码来源:ipc.c

示例5: fprintf

int
fprintf(FILE *fp, const char *fmt, ...)
{
	kern_return_t kern_res;
	va_list ap;
	if (!_init)
	{
		_init++;
		MACH_CALL(semaphore_create(mach_task_self(), 
					   &lock, 
					   SYNC_POLICY_FIFO,
					   1),
			  kern_res);
	}
	MACH_CALL(semaphore_wait(lock), kern_res);
	va_start(ap, fmt);
	vfprintf(fp, fmt, ap);
	va_end(ap);
	MACH_CALL(semaphore_signal(lock), kern_res);
}
开发者ID:rohsaini,项目名称:mkunity,代码行数:20,代码来源:fprintf.c

示例6: proc_ctrl_get_curr_pid

message_t *msg_receive(void)
{
    message_t *msg = NULL;
    const uint32_t pid = proc_ctrl_get_curr_pid();


    if (0 < msg_list[pid].nbr_in_que) {
        // Critical region starts...
        semaphore_wait(&g_mutex_msg_list);
        
        msg = msg_list[pid].next_msg;
        msg_list[pid].next_msg = msg_list[pid].next_msg->next_msg;
        msg_list[pid].nbr_in_que -= 1;
        
        // Critical regions ends...
        semaphore_signal(&g_mutex_msg_list);    
    }
    
    return msg;
}
开发者ID:ejanjoh,项目名称:bOS,代码行数:20,代码来源:message.c

示例7: DECLARE_TEST

DECLARE_TEST( semaphore, initialize )
{
	semaphore_t sem;

	semaphore_initialize( &sem, 0 );
	EXPECT_FALSE( semaphore_try_wait( &sem, 100 ) );
	semaphore_destroy( &sem );

	semaphore_initialize( &sem, 1 );
	EXPECT_TRUE( semaphore_try_wait( &sem, 100 ) );
	semaphore_destroy( &sem );

	semaphore_initialize( &sem, 2 );
	EXPECT_TRUE( semaphore_wait( &sem ) );
	EXPECT_TRUE( semaphore_try_wait( &sem, 100 ) );
	EXPECT_FALSE( semaphore_try_wait( &sem, 100 ) );
	semaphore_destroy( &sem );
	
	return 0;
}
开发者ID:DanielTillett,项目名称:foundation_lib,代码行数:20,代码来源:main.c

示例8: imx233_i2c_end

enum imx233_i2c_error_t imx233_i2c_end(unsigned timeout)
{
    if(i2c_nr_stages == 0)
        return I2C_ERROR;
    i2c_stage[i2c_nr_stages - 1].dma.cmd |= BM_APB_CHx_CMD_SEMAPHORE | BM_APB_CHx_CMD_IRQONCMPLT;

    BF_CLR(I2C_CTRL1, ALL_IRQ);
    imx233_dma_reset_channel(APB_I2C);
    imx233_icoll_enable_interrupt(INT_SRC_I2C_DMA, true);
    imx233_icoll_enable_interrupt(INT_SRC_I2C_ERROR, true);
    imx233_dma_enable_channel_interrupt(APB_I2C, true);
    imx233_dma_start_command(APB_I2C, &i2c_stage[0].dma);

    enum imx233_i2c_error_t ret;
    if(semaphore_wait(&i2c_sema, timeout) == OBJ_WAIT_TIMEDOUT)
    {
        imx233_dma_reset_channel(APB_I2C);
        imx233_i2c_reset();
        ret = I2C_TIMEOUT;
    }
    else if(BF_RD(I2C_CTRL1, MASTER_LOSS_IRQ))
        ret = I2C_MASTER_LOSS;
    else if(BF_RD(I2C_CTRL1, NO_SLAVE_ACK_IRQ))
    {
        /* the core doesn't like this error, this is a workaround to prevent lock up */
#if IMX233_SUBTARGET >= 3780
        BF_SET(I2C_CTRL1, CLR_GOT_A_NAK);
#endif
        imx233_dma_reset_channel(APB_I2C);
        imx233_i2c_reset();
        ret = I2C_NO_SLAVE_ACK;
    }
    else if(BF_RD(I2C_CTRL1, EARLY_TERM_IRQ))
        ret = I2C_SLAVE_NAK;
    else
        ret = imx233_i2c_finalize();
    /* sleep */
    BF_SET(I2C_CTRL0, CLKGATE);
    mutex_unlock(&i2c_mutex);
    return ret;
}
开发者ID:Brandon7357,项目名称:rockbox,代码行数:41,代码来源:i2c-imx233.c

示例9: usb_drv_send

int usb_drv_send(int ep, void *ptr, int len)
{
    logf("usb_drv_send(%d,%x,%d): ", ep, (int)ptr, len);

    ep &= 0x7f;

    if (ep == 0 && got_set_configuration) {
        got_set_configuration = 0;
        if (len != 0)
            panicf("usb_drv_send: GSC, but len!=0");
        /* Tell the HW we handled the request */
        USB_DEV_CTRL |= USB_DEV_CTRL_APCSR_DONE;
        return 0;
    }

    ep_send(ep, ptr, len);
    if (semaphore_wait(&endpoints[ep][0].complete, HZ) == OBJ_WAIT_TIMEDOUT)
        logf("send timed out!\n");

    return endpoints[ep][0].rc;
}
开发者ID:victor2002,项目名称:rockbox_victor_clipplus,代码行数:21,代码来源:usb-drv-as3525.c

示例10: mach_thread_self

static void *timer_func(void *arg)
{
	timer_thread = mach_thread_self();
	timer_thread_active = true;
	
	while (timer_thread_active) {
		clock_sleep(system_clock, TIME_ABSOLUTE, wakeup_time, NULL);
		semaphore_wait(wakeup_time_sem);
	   
		tm_time_t system_time;
		
		timer_current_time(system_time);
		if (timer_cmp_time(wakeup_time, system_time) < 0) {
			wakeup_time = wakeup_time_max;
			SetInterruptFlag(INTFLAG_TIMER);
			TriggerInterrupt();
		}
		semaphore_signal(wakeup_time_sem);
	}
    return NULL;
}
开发者ID:amade,项目名称:SheepShaver_oldstuff,代码行数:21,代码来源:timer.cpp

示例11: EnterCriticalSection

/*******************************************************************************
Name        : EnterCriticalSection
Description : Used to protect critical sections of Init/Open/Close/Term
Parameters  : None
Assumptions :
Limitations :
Returns     : Nothing
*******************************************************************************/
static void EnterCriticalSection(void)
{
    static BOOL InstancesAccessControlInitialized = FALSE;

#if !defined(ST_OSLINUX)
    task_lock();
#endif

    if (!InstancesAccessControlInitialized)
    {

        InstancesAccessControlInitialized = TRUE;
        InstancesAccessControl_p = semaphore_create_fifo(1);

    }
#if !defined(ST_OSLINUX)
    task_unlock();
#endif


    semaphore_wait(InstancesAccessControl_p);
}
开发者ID:henrryhe,项目名称:beijing-7101,代码行数:30,代码来源:stccinit.c

示例12: handler

void handler()
{
    int i;
    for(i=0; i < 5; i++)
    {
        /* If you remove this protection, you should be able to see different
         * out of every time you run this program.  With this protection, you
         * should always be able to see result to be 151402.656521 */
        semaphore_wait(counter_mutex);       /* down semaphore */

        /* START CRITICAL REGION */
        int j;
        for (j = 0; j < 1000; j++) {
            result = result + sin(counter) * tan(counter);
        }
        counter++;
        /* END CRITICAL REGION */    

        semaphore_signal(counter_mutex);       /* up semaphore */
    }
    mythread_exit(); /* exit thread */
}
开发者ID:dj007,项目名称:Kernel-UserThreadPackage,代码行数:22,代码来源:my-test.c

示例13: msg_send

uint32_t msg_send(message_t *msg)
{
    uint32_t ret = 0;


    ASSERT(NULL != msg);
    // ASSERT if the msg not pointing on the heap

    ASSERT(PID_IDLE != msg->receiver);
    ASSERT(HIGH_PID >= msg->receiver);
    ASSERT(msg_none_1 < msg->id && msg->id < msg_none_2);
    ret = msg->receiver;

    // Critical region starts...
    semaphore_wait(&g_mutex_msg_list);
    if (0 == msg_list[msg->receiver].nbr_in_que) {
        msg_list[msg->receiver].next_msg = msg;
        msg_list[msg->receiver].last_msg = msg;
    }
    else {
        msg_list[msg->receiver].last_msg->next_msg = msg;
        msg_list[msg->receiver].last_msg = msg;
    }
    
    msg_list[msg->receiver].nbr_in_que += 1;
    msg->next_msg = NULL;

    // semaphore_signal will generate a context switch. Make sure that the
    // receiving process is in state ready.
    if (msg->receiver != proc_ctrl_get_curr_pid()) {
        proc_ctrl_change_state(msg->receiver, ready);
    }
    
    // Critical regions ends...
    semaphore_signal(&g_mutex_msg_list);
    
    msg = NULL;
    return ret;
}
开发者ID:ejanjoh,项目名称:bOS,代码行数:39,代码来源:message.c

示例14: assert

thread_t *thread_new(const char *name) {
  assert(name != NULL);

  // Start is on the stack, but we use a semaphore, so it's safe
  thread_t *ret = calloc(1, sizeof(thread_t));
  if (!ret)
    goto error;

  ret->reactor = reactor_new();
  if (!ret->reactor)
    goto error;

  ret->work_queue = fixed_queue_new(WORK_QUEUE_CAPACITY);
  if (!ret->work_queue)
    goto error;

  struct start_arg start;
  start.start_sem = semaphore_new(0);
  if (!start.start_sem)
    goto error;

  strncpy(ret->name, name, THREAD_NAME_MAX);
  start.thread = ret;
  start.error = 0;
  pthread_create(&ret->pthread, NULL, run_thread, &start);
  semaphore_wait(start.start_sem);
  semaphore_free(start.start_sem);
  if (start.error)
    goto error;
  return ret;

error:;
  if (ret) {
    fixed_queue_free(ret->work_queue, free);
    reactor_free(ret->reactor);
  }
  free(ret);
  return NULL;
}
开发者ID:AOSP-JF,项目名称:platform_external_bluetooth_bluedroid,代码行数:39,代码来源:thread.c

示例15: file_queue_get

char* file_queue_get()
{
  char* result;

  semaphore_wait(&used_slots);
  mutex_lock(&queue_mutex);

  if (queue_head == queue_tail) // queue is empty
  {
    result = NULL;
  }
  else
  {
    result = file_queue[queue_head].path;
    queue_head = (queue_head + 1) % (MAX_QUEUED_FILES + 1);
  }

  mutex_unlock(&queue_mutex);
  semaphore_release(&unused_slots);

  return result;
}
开发者ID:mianskulls,项目名称:yara-project,代码行数:22,代码来源:yara.c


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