本文整理汇总了C++中pthread_condattr_setclock函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_condattr_setclock函数的具体用法?C++ pthread_condattr_setclock怎么用?C++ pthread_condattr_setclock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_condattr_setclock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: fstrm__get_best_monotonic_clock_pthread
bool
fstrm__get_best_monotonic_clock_pthread(clockid_t *c)
{
bool res = false;
int rc;
struct timespec ts;
pthread_condattr_t ca;
rc = pthread_condattr_init(&ca);
assert(rc == 0);
#if defined(CLOCK_MONOTONIC_COARSE)
*c = CLOCK_MONOTONIC_COARSE;
if (clock_gettime(*c, &ts) == 0 &&
pthread_condattr_setclock(&ca, *c) == 0)
{
res = true;
goto out;
}
#endif
#if defined(CLOCK_MONOTONIC_RAW)
*c = CLOCK_MONOTONIC_RAW;
if (clock_gettime(*c, &ts) == 0 &&
pthread_condattr_setclock(&ca, *c) == 0)
{
res = true;
goto out;
}
#endif
#if defined(CLOCK_MONOTONIC_FAST)
*c = CLOCK_MONOTONIC_FAST;
if (clock_gettime(*c, &ts) == 0 &&
pthread_condattr_setclock(&ca, *c) == 0)
{
res = true;
goto out;
}
#endif
#if defined(CLOCK_MONOTONIC)
*c = CLOCK_MONOTONIC;
if (clock_gettime(*c, &ts) == 0 &&
pthread_condattr_setclock(&ca, *c) == 0)
{
res = true;
goto out;
}
#endif
out:
rc = pthread_condattr_destroy(&ca);
assert(rc == 0);
return res;
}
开发者ID:farsightsec,项目名称:fstrm,代码行数:56,代码来源:time.c
示例2: pthread_condattr_init
Conditional::attribute::attribute()
{
pthread_condattr_init(&attr);
#if _POSIX_TIMERS > 0 && defined(HAVE_PTHREAD_CONDATTR_SETCLOCK)
#if defined(_POSIX_MONOTONIC_CLOCK)
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
#else
pthread_condattr_setclock(&attr, CLOCK_REALTIME);
#endif
#endif
}
开发者ID:SebastianSchildt,项目名称:ibrdtnBLETest,代码行数:12,代码来源:Conditional.cpp
示例3: TEST
TEST(pthread, pthread_condattr_setclock) {
pthread_condattr_t attr;
pthread_condattr_init(&attr);
ASSERT_EQ(0, pthread_condattr_setclock(&attr, CLOCK_REALTIME));
clockid_t clock;
ASSERT_EQ(0, pthread_condattr_getclock(&attr, &clock));
ASSERT_EQ(CLOCK_REALTIME, clock);
ASSERT_EQ(0, pthread_condattr_setclock(&attr, CLOCK_MONOTONIC));
ASSERT_EQ(0, pthread_condattr_getclock(&attr, &clock));
ASSERT_EQ(CLOCK_MONOTONIC, clock);
ASSERT_EQ(EINVAL, pthread_condattr_setclock(&attr, CLOCK_PROCESS_CPUTIME_ID));
}
开发者ID:nick0lay,项目名称:platform_bionic,代码行数:15,代码来源:pthread_test.cpp
示例4: main
int main() {
typedef unsigned long long u64;
pthread_mutex_t m;
pthread_cond_t c;
pthread_condattr_t at;
struct timespec ts0, ts1, ts2;
int res;
u64 sleep;
pthread_mutex_init(&m, 0);
pthread_condattr_init(&at);
pthread_condattr_setclock(&at, CLOCK_MONOTONIC);
pthread_cond_init(&c, &at);
clock_gettime(CLOCK_MONOTONIC, &ts0);
ts1 = ts0;
ts1.tv_sec += 2;
pthread_mutex_lock(&m);
do {
res = pthread_cond_timedwait(&c, &m, &ts1);
} while (res == 0);
pthread_mutex_unlock(&m);
clock_gettime(CLOCK_MONOTONIC, &ts2);
sleep = (u64)ts2.tv_sec * 1000000000 + ts2.tv_nsec -
((u64)ts0.tv_sec * 1000000000 + ts0.tv_nsec);
if (res != ETIMEDOUT)
exit(printf("bad return value %d, want %d\n", res, ETIMEDOUT));
if (sleep < 1000000000)
exit(printf("bad sleep duration %lluns, want %dns\n", sleep, 1000000000));
fprintf(stderr, "OK\n");
}
开发者ID:BBBSnowball,项目名称:mehari-llvm-compiler-rt,代码行数:33,代码来源:cond_version.c
示例5: 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)
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:niceaji,项目名称:libuv,代码行数:25,代码来源:thread.c
示例6: NdbCondition_Init
int
NdbCondition_Init(struct NdbCondition* ndb_cond)
{
int result;
assert(init); /* Make sure library has been initialized */
#if defined HAVE_CLOCK_GETTIME && defined HAVE_PTHREAD_CONDATTR_SETCLOCK && \
defined CLOCK_MONOTONIC
if (clock_id == CLOCK_MONOTONIC)
{
pthread_condattr_t attr;
pthread_condattr_init(&attr);
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
result = pthread_cond_init(&ndb_cond->cond, &attr);
pthread_condattr_destroy(&attr);
}
else
{
result = pthread_cond_init(&ndb_cond->cond, NULL);
}
#else
result = native_cond_init(&ndb_cond->cond);
#endif
assert(result==0);
return result;
}
开发者ID:carrotli,项目名称:ansql,代码行数:27,代码来源:NdbCondition.c
示例7: main
int main()
{
pthread_condattr_t condattr;
clockid_t clockid;
int rc;
/* Initialize a cond attributes object */
if ((rc=pthread_condattr_init(&condattr)) != 0)
{
fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc);
printf("Test FAILED\n");
return PTS_FAIL;
}
rc = pthread_condattr_setclock(&condattr, CLOCK_REALTIME);
if (rc != 0)
{
perror("Error: Could not set clock to CLOCK_REALTIME\n");
return PTS_UNRESOLVED;
}
rc = pthread_condattr_getclock(&condattr, &clockid);
if (rc != 0)
{
printf("Test FAILED: Could not get the clock attribute\n");
return PTS_FAIL;
}
printf("Test PASSED\n");
return PTS_PASS;
}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:31,代码来源:1-2.c
示例8: uv_cond_init
int uv_cond_init(uv_cond_t* cond) {
pthread_condattr_t attr;
int err;
err = pthread_condattr_init(&attr);
if (err)
return -err;
#if !(defined(__ANDROID__) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC))
err = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
if (err)
goto error2;
#endif
err = pthread_cond_init(cond, &attr);
if (err)
goto error2;
err = pthread_condattr_destroy(&attr);
if (err)
goto error;
return 0;
error:
pthread_cond_destroy(cond);
error2:
pthread_condattr_destroy(&attr);
return -err;
}
开发者ID:sjw7453584,项目名称:Server,代码行数:30,代码来源:thread.c
示例9: Condition_Init
COND_HANDLE Condition_Init(void)
{
// If we don't know our time basis, find it.
if (time_basis == -1)
{
pthread_condattr_t cattr;
pthread_condattr_init(&cattr);
pthread_condattr_getclock(&cattr, &time_basis);
pthread_condattr_destroy(&cattr);
}
// Codes_SRS_CONDITION_18_002: [ Condition_Init shall create and return a CONDITION_HANDLE ]
pthread_cond_t * cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t));
if (cond != NULL)
{
// set our time basis when configuring the condition
pthread_condattr_t cattr;
pthread_condattr_init(&cattr);
pthread_condattr_setclock(&cattr, time_basis);
pthread_cond_init(cond, &cattr);
pthread_condattr_destroy(&cattr);
}
// Codes_SRS_CONDITION_18_008: [ Condition_Init shall return NULL if it fails to allocate the CONDITION_HANDLE ]
return cond;
}
开发者ID:aog2000a,项目名称:azure-c-shared-utility,代码行数:25,代码来源:condition_pthreads.c
示例10: uv_cond_init
int uv_cond_init(uv_cond_t* cond) {
pthread_condattr_t attr;
if (pthread_condattr_init(&attr))
return -1;
#ifndef __ANDROID__
if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
#else
if (pthread_condattr_setpshared(&attr, CLOCK_MONOTONIC))
#endif
goto error2;
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:559210,项目名称:libpomelo,代码行数:26,代码来源:thread.c
示例11: pthread_condattr_init
IceUtil::Cond::Cond()
{
pthread_condattr_t attr;
int rc = pthread_condattr_init(&attr);
if(rc != 0)
{
throw ThreadSyscallException(__FILE__, __LINE__, rc);
}
#if !defined(__hpux) && !defined(__APPLE__)
rc = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
if(rc != 0)
{
throw ThreadSyscallException(__FILE__, __LINE__, rc);
}
#endif
rc = pthread_cond_init(&_cond, &attr);
if(rc != 0)
{
throw ThreadSyscallException(__FILE__, __LINE__, rc);
}
rc = pthread_condattr_destroy(&attr);
if(rc != 0)
{
throw ThreadSyscallException(__FILE__, __LINE__, rc);
}
}
开发者ID:2008hatake,项目名称:zeroc-ice,代码行数:30,代码来源:Cond.cpp
示例12: initCondAttr
/**
* Called by omrthread library init to set the cond clock to CLOCK_MONOTONIC.
* If the attempt fails, revert to CLOCK_REALTIME.
* This requires AIX 5.3 or later.
*
* @return zero on success, non-zero on error or CLOCK_MONOTONIC not available
*/
static intptr_t
initCondAttr(void)
{
intptr_t rc = 0;
rc = pthread_condattr_init(&defaultCondAttr_s);
if (0 == rc) {
struct timespec tp;
/* Confirm that CLOCK_MONOTONIC is supported. We don't care about the returned time. */
if (0 == clock_gettime(CLOCK_MONOTONIC, &tp)) {
rc = pthread_condattr_setclock(&defaultCondAttr_s, CLOCK_MONOTONIC);
if (0 == rc) {
defaultCondAttr = &defaultCondAttr_s;
timeoutClock = CLOCK_MONOTONIC;
}
} else {
rc = errno;
if (0 == rc) {
/* set rc to indicate an error, in case clock_gettime() failed to follow its spec */
rc = -1;
}
}
}
return rc;
}
开发者ID:bjornvar,项目名称:omr,代码行数:33,代码来源:thrdsup.c
示例13: _dbus_pthread_condvar_new
static DBusCondVar *
_dbus_pthread_condvar_new (void)
{
DBusCondVarPThread *pcond;
pthread_condattr_t attr;
int result;
pcond = dbus_new (DBusCondVarPThread, 1);
if (pcond == NULL)
return NULL;
pthread_condattr_init (&attr);
#ifdef HAVE_MONOTONIC_CLOCK
if (have_monotonic_clock)
pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
#endif
result = pthread_cond_init (&pcond->cond, &attr);
pthread_condattr_destroy (&attr);
if (result == EAGAIN || result == ENOMEM)
{
dbus_free (pcond);
return NULL;
}
else
{
PTHREAD_CHECK ("pthread_cond_init", result);
}
return DBUS_COND_VAR (pcond);
}
开发者ID:kizukukoto,项目名称:WDN900_GPL,代码行数:32,代码来源:dbus-sysdeps-pthread.c
示例14: create_cond
static int
create_cond(os_handler_t *handler,
os_hnd_cond_t **new_cond)
{
os_hnd_cond_t *cond;
pthread_condattr_t attr;
int rv;
rv = pthread_condattr_init(&attr);
if (rv)
return rv;
rv = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
if (rv) {
pthread_condattr_destroy(&attr);
return rv;
}
cond = malloc(sizeof(*cond));
if (!cond) {
pthread_condattr_destroy(&attr);
return ENOMEM;
}
rv = pthread_cond_init(&cond->cond, &attr);
pthread_condattr_destroy(&attr);
if (rv) {
free(cond);
return rv;
}
*new_cond = cond;
return 0;
}
开发者ID:sharkconi,项目名称:openipmi,代码行数:34,代码来源:posix_thread_os_hnd.c
示例15: pthread_condattr_init
Threading::Cond::Cond(void)
{
pthread_condattr_t condattr;
int returnVal = pthread_condattr_init(&condattr);
if (0 != returnVal)
{
throw ThreadSyscallException(__FILE__, __LINE__, returnVal);
}
#if ! defined(__hpux) && ! defined(__APPLE__)
returnVal = pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC);
if (0 != returnVal)
{
throw ThreadSyscallException(__FILE__, __LINE__, returnVal);
}
#endif
returnVal = pthread_cond_init(&m_cond, &condattr);
if (0 != returnVal)
{
throw ThreadSyscallException(__FILE__, __LINE__, returnVal);
}
returnVal = pthread_condattr_destroy(&condattr);
if (0 != returnVal)
{
throw ThreadSyscallException(__FILE__, __LINE__, returnVal);
}
}
开发者ID:happyluo,项目名称:Threading,代码行数:30,代码来源:Cond.cpp
示例16: main
int main()
{
pthread_condattr_t condattr;
struct timespec ts;
int rc;
/* Check whether kernel supports CLOCK_MONOTONIC */
rc = clock_getres(CLOCK_MONOTONIC, &ts);
if (rc != 0)
{
printf("UNSUPPORTED: CLOCK_MONOTONIC is unsupported\n");
return PTS_UNSUPPORTED;
}
/* Initialize a cond attributes object */
if ((rc=pthread_condattr_init(&condattr)) != 0)
{
fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc);
printf("Test FAILED\n");
return PTS_FAIL;
}
rc = pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC);
if (rc != 0)
{
printf("Test FAILED: Could not set clock to CLOCK_MONOTONIC\n");
return PTS_FAIL;
}
printf("Test PASSED\n");
return PTS_PASS;
}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:32,代码来源:1-2.c
示例17: defined
int ConditionVariable::Construct()
{
#if defined(CIO_IOS)
pthread_cond_init(&cond_, nullptr);
#elif defined(CIO_ANDROID)
int result = 0;
pthread_condattr_t cond_attr;
result = pthread_condattr_init(&cond_attr);
if (result != 0) {
return -1;
}
result = pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC);
if (result != 0) {
return -1;
}
result = pthread_cond_init(&cond_, &cond_attr);
if (result != 0) {
return -1;
}
result = pthread_condattr_destroy(&cond_attr);
if (result != 0) {
return -1;
}
#endif
return 0;
}
开发者ID:chenjianjun571,项目名称:cioforandroid,代码行数:27,代码来源:ConditionVariable.cpp
示例18: uv_cond_init
int uv_cond_init(uv_cond_t* cond) {
pthread_condattr_t attr;
int err;
err = pthread_condattr_init(&attr);
if (err)
return UV__ERR(err);
#if !(defined(__ANDROID_API__) && __ANDROID_API__ < 21)
err = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
if (err)
goto error2;
#endif
err = pthread_cond_init(cond, &attr);
if (err)
goto error2;
err = pthread_condattr_destroy(&attr);
if (err)
goto error;
return 0;
error:
pthread_cond_destroy(cond);
error2:
pthread_condattr_destroy(&attr);
return UV__ERR(err);
}
开发者ID:AustinShalit,项目名称:allwpilib,代码行数:30,代码来源:thread.cpp
示例19: native_cond_initialize
static void
native_cond_initialize(rb_nativethread_cond_t *cond, int flags)
{
#ifdef HAVE_PTHREAD_COND_INIT
int r;
# if USE_MONOTONIC_COND
pthread_condattr_t attr;
pthread_condattr_init(&attr);
cond->clockid = CLOCK_REALTIME;
if (flags & RB_CONDATTR_CLOCK_MONOTONIC) {
r = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
if (r == 0) {
cond->clockid = CLOCK_MONOTONIC;
}
}
r = pthread_cond_init(&cond->cond, &attr);
pthread_condattr_destroy(&attr);
# else
r = pthread_cond_init(&cond->cond, NULL);
# endif
if (r != 0) {
rb_bug_errno("pthread_cond_init", r);
}
return;
#endif
}
开发者ID:mathewv,项目名称:ruby-oneshot,代码行数:30,代码来源:thread_pthread.c
示例20: main
int
main(void)
{
int err, conderr;
long *input_set;
int i, size = NUM_ITERATION;
input_set = polynomial_dist(size, 4, 0, 10000000);
pthread_condattr_t condattr;
pthread_condattr_init(&condattr);
#ifdef COND_SETCLOCK
pthread_condattr_setclock(&condattr, CLOCK_ID);
#endif
pthread_cond_init(&cond, &condattr);
for (i = 0; i < size; i++) {
struct timespec ts_begin, ts_deadline, ts_end, ts_diff;
err = pthread_mutex_lock(&mutex);
if (err != 0)
error(1, err, "pthread_mutex_lock() failed");
err = clock_gettime(CLOCK_ID, &ts_begin);
if (err != 0)
error(1, errno, "clock_gettime() failed");
ts_deadline = ts_begin;
ts_deadline.tv_nsec += input_set[i];
timespec_normalize(&ts_deadline);
conderr = pthread_cond_timedwait(&cond, &mutex, &ts_deadline);
err = clock_gettime(CLOCK_ID, &ts_end);
if (err != 0)
error(1, errno, "clock_gettime() failed");
timespec_subtract(&ts_diff, &ts_deadline, &ts_end);
if (conderr != 0) {
if (conderr == ETIMEDOUT) {
printf("TIMEOUT,%.9Lf,%ld.%09ld\n",
(long double)input_set[i] / 1000000000, ts_diff.tv_sec, ts_diff.tv_nsec);
}
else
error(1, conderr, "pthread_cond_timedwait() failed");
err = pthread_mutex_unlock(&mutex);
if (err != 0)
error(1, err, "pthread_mutex_unlock() failed");
}
else { /* unlikely, except suprious wakeup */
printf("SUCCESS %Lf %ld.%09ld\n",
(long double)input_set[i] / 1000000000, ts_diff.tv_sec, ts_diff.tv_nsec);
}
}
return 0;
}
开发者ID:cinsk,项目名称:snippets,代码行数:59,代码来源:condwait.c
注:本文中的pthread_condattr_setclock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论