⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cond.c

📁 xenomai 很好的linux实时补丁
💻 C
📖 第 1 页 / 共 2 页
字号:
	} unlock_and_exit:    xnlock_put_irqrestore(&nklock,s);    return err;}/** * @fn int rt_cond_broadcast(RT_COND *cond) * @brief Broadcast a condition variable. * * If the condition variable is pended, all tasks currently waiting on * it are immediately unblocked. * * @param cond The descriptor address of the affected condition * variable. * * @return 0 is returned upon success. Otherwise: * * - -EINVAL is returned if @a cond is not a condition variable * descriptor. * * - -EIDRM is returned if @a cond is a deleted condition variable * descriptor. * * Environments: * * This service can be called from: * * - Kernel module initialization/cleanup code * - Interrupt service routine * - Kernel-based task * - User-space task * * Rescheduling: possible. */int rt_cond_broadcast (RT_COND *cond){    int err = 0;    spl_t s;    xnlock_get_irqsave(&nklock,s);    cond = xeno_h2obj_validate(cond,XENO_COND_MAGIC,RT_COND);    if (!cond)        {        err = xeno_handle_error(cond,XENO_COND_MAGIC,RT_COND);        goto unlock_and_exit;        }    if (xnsynch_flush(&cond->synch_base,0) == XNSYNCH_RESCHED)	xnpod_schedule(); unlock_and_exit:    xnlock_put_irqrestore(&nklock,s);    return err;}/** * @fn int rt_cond_wait(RT_COND *cond, RT_MUTEX *mutex, RTIME timeout) * @brief Wait on a condition. * * This service atomically release the mutex and causes the calling * task to block on the specified condition variable. The caller will * be unblocked when the variable is signaled, and the mutex * re-acquired before returning from this service. * Tasks pend on condition variables by priority order. * * @param cond The descriptor address of the affected condition * variable. * * @param mutex The descriptor address of the mutex protecting the * condition variable. * * @param timeout The number of clock ticks to wait for the condition * variable to be signaled (see note). Passing TM_INFINITE causes the * caller to block indefinitely until the condition variable is * signaled. * * @return 0 is returned upon success. Otherwise: * * - -EINVAL is returned if @a mutex is not a mutex descriptor, or @a * cond is not a condition variable descriptor. * * - -EIDRM is returned if @a mutex or @a cond is a deleted object * descriptor, including if the deletion occurred while the caller was * sleeping on the variable. * * - -EINTR is returned if rt_task_unblock() has been called for the * waiting task before the condition variable has been signaled. * * - -EWOULDBLOCK is returned if @a timeout equals TM_NONBLOCK. * * Environments: * * This service can be called from: * * - Kernel-based task * - User-space task (switches to primary mode) * * Rescheduling: always unless the request is immediately satisfied or * @a timeout specifies a non-blocking operation. * * @note This service is sensitive to the current operation mode of * the system timer, as defined by the rt_timer_start() service. In * periodic mode, clock ticks are interpreted as periodic jiffies. In * oneshot mode, clock ticks are interpreted as nanoseconds. */int rt_cond_wait (RT_COND *cond,		  RT_MUTEX *mutex,		  RTIME timeout){    RT_TASK *task;    int err;    spl_t s;    if (timeout == TM_NONBLOCK)	return -EWOULDBLOCK;        xnlock_get_irqsave(&nklock,s);    cond = xeno_h2obj_validate(cond,XENO_COND_MAGIC,RT_COND);    if (!cond)        {        err = xeno_handle_error(cond,XENO_COND_MAGIC,RT_COND);        goto unlock_and_exit;        }    err = rt_mutex_unlock(mutex);    if (err)	goto unlock_and_exit;    task = xeno_current_task();    xnsynch_sleep_on(&cond->synch_base,timeout);            if (xnthread_test_flags(&task->thread_base,XNRMID))	err = -EIDRM; /* Condvar deleted while pending. */    else if (xnthread_test_flags(&task->thread_base,XNTIMEO))	err = -ETIMEDOUT; /* Timeout.*/    else if (xnthread_test_flags(&task->thread_base,XNBREAK))	err = -EINTR; /* Unblocked.*/    rt_mutex_lock(mutex,TM_INFINITE); unlock_and_exit:    xnlock_put_irqrestore(&nklock,s);    return err;}/** * @fn int rt_cond_inquire(RT_COND *cond, RT_COND_INFO *info) * @brief Inquire about a condition variable. * * Return various information about the status of a given condition * variable. * * @param cond The descriptor address of the inquired condition * variable. * * @param info The address of a structure the condition variable * information will be written to. * @return 0 is returned and status information is written to the * structure pointed at by @a info upon success. Otherwise: * * - -EINVAL is returned if @a cond is not a condition variable * descriptor. * * - -EIDRM is returned if @a cond is a deleted condition variable * descriptor. * * Environments: * * This service can be called from: * * - Kernel module initialization/cleanup code * - Interrupt service routine * - Kernel-based task * - User-space task * * Rescheduling: never. */int rt_cond_inquire (RT_COND *cond,		     RT_COND_INFO *info){    int err = 0;    spl_t s;    xnlock_get_irqsave(&nklock,s);    cond = xeno_h2obj_validate(cond,XENO_COND_MAGIC,RT_COND);    if (!cond)        {        err = xeno_handle_error(cond,XENO_COND_MAGIC,RT_COND);        goto unlock_and_exit;        }        strcpy(info->name,cond->name);    info->nwaiters = xnsynch_nsleepers(&cond->synch_base); unlock_and_exit:    xnlock_put_irqrestore(&nklock,s);    return err;}/** * @fn int rt_cond_bind(RT_COND *cond, const char *name, RTIME timeout) * @brief Bind to a condition variable. * * This user-space only service retrieves the uniform descriptor of a * given Xenomai condition variable identified by its symbolic name. If * the condition variable does not exist on entry, this service blocks * the caller until a condition variable of the given name is created. * * @param name A valid NULL-terminated name which identifies the * condition variable to bind to. * * @param cond The address of a condition variable descriptor * retrieved by the operation. Contents of this memory is undefined * upon failure. * * @param timeout The number of clock ticks to wait for the * registration to occur (see note). Passing TM_INFINITE causes the * caller to block indefinitely until the object is * registered. Passing TM_NONBLOCK causes the service to return * immediately without waiting if the object is not registered on * entry. * * @return 0 is returned upon success. Otherwise: * * - -EFAULT is returned if @a cond or @a name is referencing invalid * memory. * * - -EINTR is returned if rt_task_unblock() has been called for the * waiting task before the retrieval has completed. * * - -EWOULDBLOCK is returned if @a timeout is equal to TM_NONBLOCK * and the searched object is not registered on entry. * * - -ETIMEDOUT is returned if the object cannot be retrieved within * the specified amount of time. * * - -EPERM is returned if this service should block, but was called * from a context which cannot sleep (e.g. interrupt, non-realtime or * scheduler locked). * * Environments: * * This service can be called from: * * - User-space task (switches to primary mode) * * Rescheduling: always unless the request is immediately satisfied or * @a timeout specifies a non-blocking operation. * * @note This service is sensitive to the current operation mode of * the system timer, as defined by the rt_timer_start() service. In * periodic mode, clock ticks are interpreted as periodic jiffies. In * oneshot mode, clock ticks are interpreted as nanoseconds. *//** * @fn int rt_cond_unbind(RT_COND *cond) * * @brief Unbind from a condition variable. * * This user-space only service unbinds the calling task from the * condition variable object previously retrieved by a call to * rt_cond_bind(). * * @param cond The address of a condition variable descriptor to * unbind from. * * @return 0 is always returned. * * This service can be called from: * * - User-space task. * * Rescheduling: never. */int __native_cond_pkg_init (void){    return 0;}void __native_cond_pkg_cleanup (void){}/*@}*/EXPORT_SYMBOL(rt_cond_create);EXPORT_SYMBOL(rt_cond_delete);EXPORT_SYMBOL(rt_cond_signal);EXPORT_SYMBOL(rt_cond_broadcast);EXPORT_SYMBOL(rt_cond_wait);EXPORT_SYMBOL(rt_cond_inquire);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -