本文整理汇总了C++中pthread_condattr_init函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_condattr_init函数的具体用法?C++ pthread_condattr_init怎么用?C++ pthread_condattr_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_condattr_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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
}
示例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;
}
示例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);
}