本文整理汇总了C++中pthread_condattr_init函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_condattr_init函数的具体用法?C++ pthread_condattr_init怎么用?C++ pthread_condattr_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_condattr_init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: vlc_cond_init
/**
* Initializes a condition variable.
*/
void vlc_cond_init (vlc_cond_t *p_condvar)
{
pthread_condattr_t attr;
if (unlikely(pthread_condattr_init (&attr)))
abort ();
#if !defined (_POSIX_CLOCK_SELECTION)
/* Fairly outdated POSIX support (that was defined in 2001) */
# define _POSIX_CLOCK_SELECTION (-1)
#endif
#if (_POSIX_CLOCK_SELECTION >= 0)
/* NOTE: This must be the same clock as the one in mtime.c */
pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
#endif
if (unlikely(pthread_cond_init (p_condvar, &attr)))
abort ();
pthread_condattr_destroy (&attr);
}
开发者ID:cmassiot,项目名称:vlc-broadcast,代码行数:22,代码来源:pthread.c
示例2: r_cond_init
void
r_cond_init (RCond * cond)
{
#if defined (R_OS_WIN32)
PCONDITION_VARIABLE pc = *cond = r_mem_new (CONDITION_VARIABLE);
InitializeConditionVariable (pc);
#elif defined (HAVE_PTHREAD_H)
pthread_condattr_t attr;
pthread_cond_t * pc;
pthread_condattr_init (&attr);
pc = *cond = r_mem_new (pthread_cond_t);
pthread_cond_init (pc, &attr);
pthread_condattr_destroy (&attr);
#else
(void) cond;
#endif
}
开发者ID:ieei,项目名称:rlib,代码行数:19,代码来源:rthreads.c
示例3: traceobj_init
int traceobj_init(struct traceobj *trobj, const char *label, int nr_marks)
{
pthread_mutexattr_t mattr;
pthread_condattr_t cattr;
int ret;
pthread_mutexattr_init(&mattr);
pthread_mutexattr_settype(&mattr, mutex_type_attribute);
pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);
pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_PRIVATE);
ret = __bt(-__RT(pthread_mutex_init(&trobj->lock, &mattr)));
pthread_mutexattr_destroy(&mattr);
if (ret)
return ret;
pthread_condattr_init(&cattr);
pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_PRIVATE);
ret = __bt(-__RT(pthread_cond_init(&trobj->join, &cattr)));
pthread_condattr_destroy(&cattr);
if (ret) {
__RT(pthread_mutex_destroy(&trobj->lock));
return ret;
}
/*
* We make sure not to unblock from threadobj_join() until at
* least one thread has called trace_enter() for this trace
* object.
*/
trobj->nr_threads = -1;
trobj->label = label;
trobj->nr_marks = nr_marks;
trobj->cur_mark = 0;
if (nr_marks > 0) {
trobj->marks = pvmalloc(sizeof(struct tracemark) * nr_marks);
if (trobj->marks == NULL)
panic("cannot allocate mark table for tracing");
}
return 0;
}
开发者ID:rcn-ee,项目名称:xenomai-3,代码行数:43,代码来源:traceobj.c
示例4: main
int main()
{
/* Make sure there is process-shared capability. */
#ifndef PTHREAD_PROCESS_SHARED
fprintf(stderr,
"process-shared attribute is not available for testing\n");
return PTS_UNRESOLVED;
#endif
pthread_condattr_t attr;
int ret;
/* Initialize a cond attributes object */
if (pthread_condattr_init(&attr) != 0) {
perror("Error at pthread_condattr_init()\n");
return PTS_UNRESOLVED;
}
/* Set 'pshared' to INVALID_PSHARED_VALUE. */
ret = pthread_condattr_setpshared(&attr, INVALID_PSHARED_VALUE);
if (ret != 0) {
if (ret == EINVAL) {
printf("Test PASSED\n");
return PTS_PASS;
}
printf
("Test FAILED: Invalid return code, expected 0 or EINVAL, but got: %d\n",
ret);
return PTS_FAIL;
}
/* Destory the cond attributes object */
if (pthread_condattr_destroy(&attr) != 0) {
perror("Error at pthread_condattr_destroy()\n");
return PTS_UNRESOLVED;
}
printf
("Test PASSED: NOTE*: Returned 0 when passed an invalid 'pshared', but standard says 'may' fail.\n");
return PTS_PASS;
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:43,代码来源:2-1.c
示例5: xsim_barrier_init
int
xsim_barrier_init(xsim_barrier_t *barrier, int needed) {
pthread_mutexattr_t mattr;
pthread_condattr_t cattr;
barrier->count = needed;
barrier->current = 0;
pthread_mutexattr_init(&mattr);
pthread_mutexattr_setpshared(&mattr, 1);
pthread_mutex_init(&barrier->lock, &mattr);
pthread_condattr_init(&cattr);
pthread_condattr_setpshared(&cattr, 1);
pthread_cond_init(&barrier->cond, &cattr);
return XSIM_SUCCESS;
}
开发者ID:jihednasr,项目名称:xsim,代码行数:19,代码来源:xsim_sync.c
示例6: pthread_condattr_init
inline interprocess_condition::interprocess_condition()
{
int res;
pthread_condattr_t cond_attr;
res = pthread_condattr_init(&cond_attr);
if(res != 0){
throw interprocess_exception();
}
res = pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED);
if(res != 0){
pthread_condattr_destroy(&cond_attr);
throw interprocess_exception(res);
}
res = pthread_cond_init(&m_condition, &cond_attr);
pthread_condattr_destroy(&cond_attr);
if(res != 0){
throw interprocess_exception(res);
}
}
开发者ID:Skovpin,项目名称:CodeBlocks-RG,代码行数:19,代码来源:interprocess_condition.hpp
示例7: ca_cond_new
ca_cond ca_cond_new(void)
{
ca_cond retVal = NULL;
ca_cond_internal *eventInfo = (ca_cond_internal*) OICMalloc(sizeof(ca_cond_internal));
if (NULL != eventInfo)
{
int ret = pthread_condattr_init(&(eventInfo->condattr));
if(0 != ret)
{
OIC_LOG_V(ERROR, TAG, "%s: Failed to initialize condition variable attribute %d!",
__func__, ret);
OICFree(eventInfo);
return retVal;
}
#if defined(__ANDROID__) || _POSIX_TIMERS > 0
ret = pthread_condattr_setclock(&(eventInfo->condattr), CLOCK_MONOTONIC);
if(0 != ret)
{
OIC_LOG_V(ERROR, TAG, "%s: Failed to set condition variable clock %d!",
__func__, ret);
pthread_condattr_destroy(&(eventInfo->condattr));
OICFree(eventInfo);
return retVal;
}
#endif
ret = pthread_cond_init(&(eventInfo->cond), &(eventInfo->condattr));
if (0 == ret)
{
retVal = (ca_cond) eventInfo;
}
else
{
OIC_LOG_V(ERROR, TAG, "%s: Failed to initialize condition variable %d!", __func__, ret);
pthread_condattr_destroy(&(eventInfo->condattr));
OICFree(eventInfo);
}
}
return retVal;
}
开发者ID:WojciechLuczkow,项目名称:iotivity,代码行数:42,代码来源:camutex_pthreads.c
示例8: _n
SemaphoreImpl::SemaphoreImpl(int n, int max): _n(n), _max(max)
{
poco_assert (n >= 0 && max > 0 && n <= max);
#if defined(POCO_VXWORKS)
// This workaround is for VxWorks 5.x where
// pthread_mutex_init() won't properly initialize the mutex
// resulting in a subsequent freeze in pthread_mutex_destroy()
// if the mutex has never been used.
std::memset(&_mutex, 0, sizeof(_mutex));
#endif
if (pthread_mutex_init(&_mutex, NULL))
throw SystemException("cannot create semaphore (mutex)");
#if defined(POCO_HAVE_MONOTONIC_PTHREAD_COND_TIMEDWAIT)
pthread_condattr_t attr;
if (pthread_condattr_init(&attr))
{
pthread_mutex_destroy(&_mutex);
throw SystemException("cannot create semaphore (condition attribute)");
}
if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
{
pthread_condattr_destroy(&attr);
pthread_mutex_destroy(&_mutex);
throw SystemException("cannot create semaphore (condition attribute clock)");
}
if (pthread_cond_init(&_cond, &attr))
{
pthread_condattr_destroy(&attr);
pthread_mutex_destroy(&_mutex);
throw SystemException("cannot create semaphore (condition)");
}
pthread_condattr_destroy(&attr);
#else
if (pthread_cond_init(&_cond, NULL))
{
pthread_mutex_destroy(&_mutex);
throw SystemException("cannot create semaphore (condition)");
}
#endif
}
开发者ID:Bjoe,项目名称:poco,代码行数:42,代码来源:Semaphore_POSIX.cpp
示例9: os_cond_create
struct OsCond * os_cond_create(void) {
struct OsCond *cond = allocate_zero<OsCond>(1);
if (!cond) {
os_cond_destroy(cond);
return NULL;
}
#if defined(GENESIS_OS_WINDOWS)
InitializeConditionVariable(&cond->id);
InitializeCriticalSection(&cond->default_cs_id);
#elif defined(GENESIS_OS_KQUEUE)
cond->kq_id = kqueue();
if (cond->kq_id == -1)
return NULL;
#else
if (pthread_condattr_init(&cond->attr)) {
os_cond_destroy(cond);
return NULL;
}
cond->attr_init = true;
if (pthread_condattr_setclock(&cond->attr, CLOCK_MONOTONIC)) {
os_cond_destroy(cond);
return NULL;
}
if (pthread_cond_init(&cond->id, &cond->attr)) {
os_cond_destroy(cond);
return NULL;
}
cond->id_init = true;
if ((pthread_mutex_init(&cond->default_mutex_id, NULL))) {
os_cond_destroy(cond);
return NULL;
}
cond->default_mutex_init = true;
#endif
return cond;
}
开发者ID:JamesLinus,项目名称:genesis,代码行数:42,代码来源:os.cpp
示例10: soundio_os_cond_create
struct SoundIoOsCond * soundio_os_cond_create(void) {
struct SoundIoOsCond *cond = ALLOCATE(struct SoundIoOsCond, 1);
if (!cond) {
soundio_os_cond_destroy(cond);
return NULL;
}
#if defined(SOUNDIO_OS_WINDOWS)
InitializeConditionVariable(&cond->id);
InitializeCriticalSection(&cond->default_cs_id);
#elif defined(SOUNDIO_OS_KQUEUE)
cond->kq_id = kqueue();
if (cond->kq_id == -1)
return NULL;
#else
if (pthread_condattr_init(&cond->attr)) {
soundio_os_cond_destroy(cond);
return NULL;
}
cond->attr_init = true;
if (pthread_condattr_setclock(&cond->attr, CLOCK_MONOTONIC)) {
soundio_os_cond_destroy(cond);
return NULL;
}
if (pthread_cond_init(&cond->id, &cond->attr)) {
soundio_os_cond_destroy(cond);
return NULL;
}
cond->id_init = true;
if ((pthread_mutex_init(&cond->default_mutex_id, NULL))) {
soundio_os_cond_destroy(cond);
return NULL;
}
cond->default_mutex_init = true;
#endif
return cond;
}
开发者ID:clehner,项目名称:libsoundio,代码行数:42,代码来源:os.c
示例11: ipc_condattr
/*
* On first invocation, allocates a condition variable attributes
* structure and initializes it with appropriate attributes. In
* all cases, returns a pointer to the structure.
*/
pthread_condattr_t *
ipc_condattr(void)
{
if (condattr == NULL) {
if ((condattr = malloc(sizeof (pthread_condattr_t))) == NULL) {
filebench_log(LOG_ERROR, "cannot alloc cond attr");
filebench_shutdown(1);
}
(void) pthread_condattr_init(condattr);
#ifdef HAVE_PTHREAD_MUTEXATTR_SETPSHARED
if (pthread_condattr_setpshared(condattr,
PTHREAD_PROCESS_SHARED) != 0) {
filebench_log(LOG_ERROR,
"cannot set cond attr PROCESS_SHARED");
// filebench_shutdown(1);
}
#endif /* HAVE_PTHREAD_MUTEXATTR_SETPSHARED */
}
return (condattr);
}
开发者ID:auristor,项目名称:filebench,代码行数:25,代码来源:ipc.c
示例12: thread_pool_create
int thread_pool_create(thread_pool *new_pool, long max_running_threads)
{
thread_id i;
if((new_pool->threads = (pthread_t *) calloc((size_t) max_running_threads,
sizeof(pthread_t))) == NULL)
return -1;
if((new_pool->working = (bool *) calloc((size_t) max_running_threads,
sizeof(bool))) == NULL)
return -1;
if(pthread_condattr_init(&(new_pool->cond_attr)) != 0)
return -1;
if(pthread_cond_init(&new_pool->sleeping, &(new_pool->cond_attr)) != 0)
return -1;
new_pool->running_threads = 0;
new_pool->max_running_threads = max_running_threads;
new_pool->unused = NULL;
for(i = 0; i < max_running_threads; i ++)
new_pool->unused = stack_push(new_pool->unused, i);
new_pool->sleeping_quantity = 0;
return 0;
}
开发者ID:cbart,项目名称:sop-lab-2009,代码行数:21,代码来源:thread_pool.c
示例13: fWaitCount
OSCond::OSCond()
: fWaitCount(0)
{
#ifdef __Win32__
fCondition = ::CreateEvent(NULL, FALSE, FALSE, NULL);
Assert(fCondition != NULL);
#elif __PTHREADS_MUTEXES__
#if __MacOSX__
int ret = pthread_cond_init(&fCondition, NULL);
Assert(ret == 0);
#else
pthread_condattr_t cond_attr;
pthread_condattr_init(&cond_attr);
int ret = pthread_cond_init(&fCondition, &cond_attr);
Assert(ret == 0);
#endif
#else
fCondition = mycondition_alloc();
Assert(fCondition != NULL);
#endif
}
开发者ID:bensonX,项目名称:EasyDarwin,代码行数:21,代码来源:OSCond.cpp
示例14: uv_cond_init
int uv_cond_init(uv_cond_t* cond) {
pthread_condattr_t attr;
if (pthread_condattr_init(&attr)) return -1;
#if !(defined(__ANDROID__) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC))
if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC)) goto error2;
#endif
if (pthread_cond_init(cond, &attr)) goto error2;
if (pthread_condattr_destroy(&attr)) goto error;
return 0;
error:
pthread_cond_destroy(cond);
error2:
pthread_condattr_destroy(&attr);
return -1;
}
开发者ID:vldmkr,项目名称:jxcore-android-scripts,代码行数:21,代码来源:thread.c
示例15: xshmfence_init
void
xshmfence_init(int fd)
{
struct xshmfence *f = xshmfence_map_shm(fd);
pthread_mutexattr_t mutex_attr;
pthread_condattr_t cond_attr;
if (!f)
return;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED);
pthread_mutex_init(&f->lock, &mutex_attr);
pthread_condattr_init(&cond_attr);
pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED);
pthread_cond_init(&f->wakeup, &cond_attr);
f->value = 0;
f->waiting = 0;
xshmfence_unmap_shm(f);
}
开发者ID:freedesktop-unofficial-mirror,项目名称:xorg__lib__libxshmfence,代码行数:21,代码来源:xshmfence_pthread.c
示例16: sysv_barrier_create
int sysv_barrier_create(sysv_barrier_t barrier, int num_procs)
{
pthread_mutexattr_t mutex_shared_attr;
PTHREAD_SAFE(pthread_mutexattr_init(&mutex_shared_attr));
PTHREAD_SAFE(pthread_mutexattr_setpshared(&mutex_shared_attr,
PTHREAD_PROCESS_SHARED));
PTHREAD_SAFE(pthread_mutex_init(&(barrier->mutex), &mutex_shared_attr));
PTHREAD_SAFE(pthread_mutexattr_destroy(&mutex_shared_attr));
pthread_condattr_t cond_shared_attr;
PTHREAD_SAFE(pthread_condattr_init(&cond_shared_attr));
PTHREAD_SAFE(pthread_condattr_setpshared(&cond_shared_attr,
PTHREAD_PROCESS_SHARED));
PTHREAD_SAFE(pthread_cond_init(&(barrier->cond), &cond_shared_attr));
PTHREAD_SAFE(pthread_condattr_destroy(&cond_shared_attr));
barrier->num_procs = num_procs;
barrier->num_waiting = 0;
return 0;
}
开发者ID:dash-project,项目名称:dash,代码行数:21,代码来源:shmem_barriers_sysv.c
示例17: ipc_condattr
/*
* On first invocation, allocates a condition variable attributes
* structure and initializes it with appropriate attributes. In
* all cases, returns a pointer to the structure.
*/
pthread_condattr_t *
ipc_condattr(void)
{
#ifdef USE_PROCESS_MODEL
if (condattr == NULL) {
if ((condattr = malloc(sizeof (pthread_condattr_t))) == NULL) {
filebench_log(LOG_ERROR, "cannot alloc cond attr");
filebench_shutdown(1);
}
#ifdef HAVE_PROCSCOPE_PTHREADS
(void) pthread_condattr_init(condattr);
if (pthread_condattr_setpshared(condattr,
PTHREAD_PROCESS_SHARED) != 0) {
filebench_log(LOG_ERROR,
"cannot set cond attr PROCESS_SHARED");
filebench_shutdown(1);
}
#endif /* HAVE_PROCSCOPE_PTHREADS */
}
#endif /* USE_PROCESS_MODEL */
return (condattr);
}
开发者ID:alhazred,项目名称:onarm,代码行数:27,代码来源:ipc.c
示例18: ChannelCreate
clsThread::clsThread()
{
m_idThread = 0;
m_chThread = ChannelCreate(0);
m_coidThread = ConnectAttach(ND_LOCAL_NODE, 0, m_chThread, _NTO_SIDE_CHANNEL, 0);
pthread_condattr_t attrCond;
pthread_condattr_init(&attrCond);
pthread_cond_init(&m_condThread, &attrCond);
pthread_mutexattr_t attrMtx;
pthread_mutexattr_init(&attrMtx);
pthread_mutex_init(&m_mtxThread, &attrMtx);
pthread_mutex_lock(&m_mtxThread);
m_bReady = FALSE;
m_nCount = 0;
}
开发者ID:SaiVineethKS,项目名称:IMAV-D-Roof-top-landing-Gumstix-code,代码行数:22,代码来源:thread.cpp
示例19: open
ion_semaphore_t * IonImageSem::Create(const char *semaphore_name)
{
int fd;
ion_semaphore_t *semap;
fd = open(semaphore_name, O_RDWR | O_CREAT /*| O_EXCL*/, 0666);
if (fd < 0){
ISMLOG("%s: failed, %s\n",__FUNCTION__,strerror(errno));
return (NULL);
}
if( ftruncate(fd, sizeof(ion_semaphore_t)))
{}
#ifdef USE_ION_PTHREAD_SEM
pthread_mutexattr_t psharedm;
pthread_condattr_t psharedc;
(void) pthread_mutexattr_init(&psharedm);
// int robustness=0;
// (void) pthread_mutexattr_getrobust_np(&psharedm,&robustness);
// DTRACEP("%s: robust: %d\n",__FUNCTION__,robustness);
(void) pthread_mutexattr_setpshared(&psharedm, PTHREAD_PROCESS_SHARED);
(void)pthread_mutexattr_setrobust_np(&psharedm, PTHREAD_MUTEX_ROBUST_NP);
(void) pthread_condattr_init(&psharedc);
(void) pthread_condattr_setpshared(&psharedc,
PTHREAD_PROCESS_SHARED);
#endif
semap = (ion_semaphore_t *) mmap(NULL, sizeof(ion_semaphore_t),
PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
close (fd);
if(semap)
{
memset(semap,0,sizeof(ion_semaphore_t));
#ifdef USE_ION_PTHREAD_SEM
(void) pthread_mutex_init(&semap->lock, &psharedm);
#endif
// (void) pthread_cond_init(&semap->nonzero, &psharedc);
}
return (semap);
}
开发者ID:biocyberman,项目名称:TS,代码行数:39,代码来源:IonImageSem.cpp
示例20: OSA_flgCreate
int OSA_flgCreate(OSA_FlgHndl *hndl, Uint32 initPattern)
{
pthread_mutexattr_t mutex_attr;
pthread_condattr_t cond_attr;
int status=OSA_SOK;
status |= pthread_mutexattr_init(&mutex_attr);
status |= pthread_condattr_init(&cond_attr);
status |= pthread_mutex_init(&hndl->lock, &mutex_attr);
status |= pthread_cond_init(&hndl->cond, &cond_attr);
hndl->pattern = initPattern;
if(status!=OSA_SOK)
OSA_ERROR("OSA_flgCreate() = %d \r\n", status);
pthread_condattr_destroy(&cond_attr);
pthread_mutexattr_destroy(&mutex_attr);
return status;
}
开发者ID:119,项目名称:ipnc,代码行数:22,代码来源:osa_flg.c
注:本文中的pthread_condattr_init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论