本文整理汇总了C++中pthread_rwlock_trywrlock函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_rwlock_trywrlock函数的具体用法?C++ pthread_rwlock_trywrlock怎么用?C++ pthread_rwlock_trywrlock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_rwlock_trywrlock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_try_lock
Error RWLockPosix::write_try_lock() {
if (pthread_rwlock_trywrlock(&rwlock) != 0) {
return ERR_BUSY;
} else {
return OK;
}
}
示例2: TRI_TryWriteLockReadWriteLock
bool TRI_TryWriteLockReadWriteLock (TRI_read_write_lock_t* lock) {
int rc;
rc = pthread_rwlock_trywrlock(lock);
return (rc == 0);
}
示例3: PlatformRWTryWLock
int PlatformRWTryWLock(RWLock lock) {
#ifndef WIN32
pthread_rwlock_t *l = lock;
return pthread_rwlock_trywrlock(l);
#else
#endif
}
示例4: main
int main(int argc, char** argv)
{
int r;
pthread_mutex_t mutex;
pthread_rwlock_t rwlock;
struct timespec abs_timeout;
time(&abs_timeout.tv_sec);
abs_timeout.tv_nsec = 0;
abs_timeout.tv_sec += 10;
r = pthread_rwlock_init(&rwlock, NULL); assert(r == 0);
fprintf(stderr, "Locking rwlock via pthread_rwlock_wrlock().\n");
r = pthread_rwlock_wrlock(&rwlock); assert(r == 0);
r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
fprintf(stderr, "Locking rwlock via pthread_rwlock_trywrlock().\n");
r = pthread_rwlock_trywrlock(&rwlock); assert(r == 0);
r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
fprintf(stderr, "Locking rwlock via pthread_rwlock_timedwrlock().\n");
#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
r = pthread_rwlock_timedwrlock(&rwlock, &abs_timeout); assert(r == 0);
r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
#endif
fprintf(stderr, "Locking rwlock via pthread_rwlock_rdlock().\n");
r = pthread_rwlock_rdlock(&rwlock); assert(r == 0);
r = pthread_rwlock_rdlock(&rwlock); assert(r == 0);
r = pthread_rwlock_rdlock(&rwlock); assert(r == 0);
r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
fprintf(stderr, "Locking rwlock via pthread_rwlock_tryrdlock().\n");
r = pthread_rwlock_tryrdlock(&rwlock); assert(r == 0);
r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
fprintf(stderr, "Locking rwlock via pthread_rwlock_timedrdlock().\n");
#ifdef HAVE_PTHREAD_RWLOCK_TIMEDRDLOCK
r = pthread_rwlock_timedrdlock(&rwlock, &abs_timeout); assert(r == 0);
r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
#endif
fprintf(stderr, "Attempt to lock for writing recursively (not allowed).\n");
r = pthread_rwlock_wrlock(&rwlock); assert(r == 0);
r = pthread_rwlock_wrlock(&rwlock); assert(r != 0);
r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
r = pthread_rwlock_destroy(&rwlock); assert(r == 0);
r = pthread_mutex_init(&mutex, NULL); assert(r == 0);
fprintf(stderr, "Locking mutex via pthread_mutex_trylock().\n");
r = pthread_mutex_trylock(&mutex); assert(r == 0);
r = pthread_mutex_unlock(&mutex); assert(r == 0);
fprintf(stderr, "Locking mutex via pthread_mutex_lock().\n");
r = pthread_mutex_lock(&mutex); assert(r == 0);
r = pthread_mutex_unlock(&mutex); assert(r == 0);
fprintf(stderr, "Locking mutex via pthread_mutex_timedlock().\n");
#ifdef HAVE_PTHREAD_MUTEX_TIMEDLOCK
r = pthread_mutex_timedlock(&mutex, &abs_timeout); assert(r == 0);
r = pthread_mutex_unlock(&mutex); assert(r == 0);
#endif
r = pthread_mutex_destroy(&mutex); assert(r == 0);
return 0;
}
示例5: IMPL
bool RWLock::try_write_lock()
{
IMPL(impl);
if (pthread_rwlock_trywrlock(&impl->rwlock) == 0)
return true;
return false;
}
示例6: pthread_rwlock_trywrlock
bool
cThreadLockRw::TryWriteLock()
{
int rv = pthread_rwlock_trywrlock( &m_rwlock );
return rv == 0;
}
示例7: pthread_rwlock_trywrlock
static void *trywrlock(void *arg)
{
int r = pthread_rwlock_trywrlock(arg);
if (r != EBUSY)
t_error("trywrlock for rdlocked lock returned %s, want EBUSY\n", strerror(r));
return 0;
}
示例8: wi_rwlock_trywrlock
wi_boolean_t wi_rwlock_trywrlock(wi_rwlock_t *lock) {
#ifdef WI_PTHREADS
return (pthread_rwlock_trywrlock(&lock->rwlock) == 0);
#else
return true;
#endif
}
示例9: TEST
TEST(pthread, pthread_rwlock_smoke) {
pthread_rwlock_t l;
ASSERT_EQ(0, pthread_rwlock_init(&l, NULL));
// Single read lock
ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
ASSERT_EQ(0, pthread_rwlock_unlock(&l));
// Multiple read lock
ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
ASSERT_EQ(0, pthread_rwlock_rdlock(&l));
ASSERT_EQ(0, pthread_rwlock_unlock(&l));
ASSERT_EQ(0, pthread_rwlock_unlock(&l));
// Write lock
ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
ASSERT_EQ(0, pthread_rwlock_unlock(&l));
// Try writer lock
ASSERT_EQ(0, pthread_rwlock_trywrlock(&l));
ASSERT_EQ(EBUSY, pthread_rwlock_trywrlock(&l));
ASSERT_EQ(EBUSY, pthread_rwlock_tryrdlock(&l));
ASSERT_EQ(0, pthread_rwlock_unlock(&l));
// Try reader lock
ASSERT_EQ(0, pthread_rwlock_tryrdlock(&l));
ASSERT_EQ(0, pthread_rwlock_tryrdlock(&l));
ASSERT_EQ(EBUSY, pthread_rwlock_trywrlock(&l));
ASSERT_EQ(0, pthread_rwlock_unlock(&l));
ASSERT_EQ(0, pthread_rwlock_unlock(&l));
// Try writer lock after unlock
ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
ASSERT_EQ(0, pthread_rwlock_unlock(&l));
// EDEADLK in "read after write"
ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
ASSERT_EQ(EDEADLK, pthread_rwlock_rdlock(&l));
ASSERT_EQ(0, pthread_rwlock_unlock(&l));
// EDEADLK in "write after write"
ASSERT_EQ(0, pthread_rwlock_wrlock(&l));
ASSERT_EQ(EDEADLK, pthread_rwlock_wrlock(&l));
ASSERT_EQ(0, pthread_rwlock_unlock(&l));
ASSERT_EQ(0, pthread_rwlock_destroy(&l));
}
示例10: pthread_rwlock_trywrlock
// WriteLock with absolute timeout
bool RWLockImplPosix::writeLock(const ::icl_core::TimeStamp& timeout)
{
#ifdef _SYSTEM_DARWIN_
int ret = pthread_rwlock_trywrlock(m_rwlock);
while ((ret != 0) && ((timeout > icl_core::TimeStamp::now())))
{
// one microsecond
icl_core::os::usleep(1);
ret = pthread_rwlock_trywrlock(m_rwlock);
}
return (ret == 0);
#else
struct timespec timeout_timespec = timeout.timespec();
bool ret = pthread_rwlock_timedwrlock(m_rwlock, &timeout_timespec);
return (ret == 0);
#endif
}
示例11: ptt_pthread_rwlock_trywrlock
DLL_EXPORT int ptt_pthread_rwlock_trywrlock(RWLOCK *rwlock, char *loc)
{
int result;
PTTRACE ("trywr before", rwlock, NULL, loc, PTT_MAGIC);
result = pthread_rwlock_trywrlock(rwlock);
PTTRACE ("trywr after", rwlock, NULL, loc, result);
return result;
}
示例12: return
/// <summary>
/// Tries to acquire write lock (now). Returns true if succeeded, false if failed.
/// </summary>
/// <returns></returns>
bool RWLock::TryLockWrite()
{
#ifdef PLATFORM_WIN
return (TryAcquireSRWLockExclusive( &mRwlock ) > 0);
#else
return (pthread_rwlock_trywrlock( &mRwlock ) == 0);
#endif
}
示例13: func
void * func(void * arg)
{
assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY);
washere = 1;
return 0;
}
示例14: try_write_locker
try_write_locker(pthread_rwlock_t &lock)
: L(lock), ok(false)
{
int rv = pthread_rwlock_trywrlock(&L);
if(rv != 0 && rv != EBUSY)
throw strerror_exception("Failed trying wrlock", rv);
ok = (rv == 0);
}
示例15: __ast_rwlock_trywrlock
int __ast_rwlock_trywrlock(const char *filename, int line, const char *func, ast_rwlock_t *t, const char *name)
{
int res;
#ifdef DEBUG_THREADS
struct ast_lock_track *lt = NULL;
#ifdef HAVE_BKTR
struct ast_bt *bt = NULL;
#endif
if (t->tracking) {
lt = ast_get_reentrancy(&t->track);
}
if (lt) {
#ifdef HAVE_BKTR
struct ast_bt tmp;
/* The implementation of backtrace() may have its own locks.
* Capture the backtrace outside of the reentrancy lock to
* avoid deadlocks. See ASTERISK-22455. */
ast_bt_get_addresses(&tmp);
ast_reentrancy_lock(lt);
if (lt->reentrancy < AST_MAX_REENTRANCY) {
lt->backtrace[lt->reentrancy] = tmp;
bt = <->backtrace[lt->reentrancy];
}
ast_reentrancy_unlock(lt);
ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
#else
ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
#endif
}
#endif /* DEBUG_THREADS */
res = pthread_rwlock_trywrlock(&t->lock);
#ifdef DEBUG_THREADS
if (!res && lt) {
ast_reentrancy_lock(lt);
if (lt->reentrancy < AST_MAX_REENTRANCY) {
lt->file[lt->reentrancy] = filename;
lt->lineno[lt->reentrancy] = line;
lt->func[lt->reentrancy] = func;
lt->thread[lt->reentrancy] = pthread_self();
lt->reentrancy++;
}
ast_reentrancy_unlock(lt);
ast_mark_lock_acquired(t);
} else if (lt) {
ast_mark_lock_failed(t);
}
#endif /* DEBUG_THREADS */
return res;
}