• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pthread_rwlock_trywrlock函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中pthread_rwlock_trywrlock函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_rwlock_trywrlock函数的具体用法?C++ pthread_rwlock_trywrlock怎么用?C++ pthread_rwlock_trywrlock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pthread_rwlock_trywrlock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: write_try_lock

Error RWLockPosix::write_try_lock() {
	if (pthread_rwlock_trywrlock(&rwlock) != 0) {
		return ERR_BUSY;
	} else {
		return OK;
	}
}
开发者ID:KellyThomas,项目名称:godot,代码行数:7,代码来源:rw_lock_posix.cpp


示例2: TRI_TryWriteLockReadWriteLock

bool TRI_TryWriteLockReadWriteLock (TRI_read_write_lock_t* lock) {
  int rc;

  rc = pthread_rwlock_trywrlock(lock);

  return (rc == 0);
}
开发者ID:eranshir,项目名称:ArangoDB,代码行数:7,代码来源:locks-posix.c


示例3: PlatformRWTryWLock

int PlatformRWTryWLock(RWLock lock) {
#ifndef WIN32
   pthread_rwlock_t *l = lock;
   return pthread_rwlock_trywrlock(l);
#else
#endif
}
开发者ID:sscreation,项目名称:BlockManager,代码行数:7,代码来源:platformops.c


示例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;
}
开发者ID:520SRig,项目名称:valgrind,代码行数:60,代码来源:trylock.c


示例5: IMPL

 bool RWLock::try_write_lock()
 {
     IMPL(impl);
     if (pthread_rwlock_trywrlock(&impl->rwlock) == 0)
         return true;
     return false;
 }
开发者ID:BackupTheBerlios,项目名称:xicorr-svn,代码行数:7,代码来源:rw_lock.cpp


示例6: pthread_rwlock_trywrlock

bool
cThreadLockRw::TryWriteLock()
{
  int rv = pthread_rwlock_trywrlock( &m_rwlock );

  return rv == 0;
}
开发者ID:openhpi1,项目名称:testrepo,代码行数:7,代码来源:thread.cpp


示例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;
}
开发者ID:andrey-gvrd,项目名称:rusl,代码行数:7,代码来源:pthread_rwlock-ebusy.c


示例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
}
开发者ID:ProfDrLuigi,项目名称:zanka,代码行数:7,代码来源:wi-lock.c


示例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));
}
开发者ID:loongchow,项目名称:platform_bionic,代码行数:47,代码来源:pthread_test.cpp


示例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
}
开发者ID:FelixPe,项目名称:gpu-voxels,代码行数:18,代码来源:RWLockImplPosix.cpp


示例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;
}
开发者ID:adozenlines,项目名称:sandhawk,代码行数:8,代码来源:pttrace.c


示例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
}
开发者ID:Inch4Tk,项目名称:ModernDB2016SS,代码行数:12,代码来源:RWLock.cpp


示例13: func

void * func(void * arg)
{
  assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY);

  washere = 1;

  return 0; 
}
开发者ID:ColinGilbert,项目名称:noobEngine,代码行数:8,代码来源:rwlock3.c


示例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);
 }
开发者ID:beevek,项目名称:libkrb,代码行数:8,代码来源:locker.hpp


示例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 = &lt->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;
}
开发者ID:LorneyZizzart,项目名称:asterisk,代码行数:58,代码来源:lock.c


示例16: uv_rwlock_trywrlock

int uv_rwlock_trywrlock(uv_rwlock_t* rwlock) {
  int err;

  err = pthread_rwlock_trywrlock(rwlock);
  if (err && err != EBUSY && err != EAGAIN)
    abort();

  return -err;
}
开发者ID:BurnBeforeReading,项目名称:cjdns,代码行数:9,代码来源:thread.c


示例17: pthread_rwlock_trywrlock

bool BufferFrame::tryLock(bool exclusive) {
	int result;
	if (exclusive){
		result = pthread_rwlock_trywrlock(&header.rwlock);
	}else{
		result = pthread_rwlock_tryrdlock(&header.rwlock);
	}
	return result == 0;
}
开发者ID:mschrimpf,项目名称:dbimpl,代码行数:9,代码来源:BufferFrame.cpp


示例18: TryLock

			bool TryLock(void) const
			{
				int ret = pthread_rwlock_trywrlock(&rwlock);

				DKASSERT_DESC_DEBUG(ret != EDEADLK, "The calling thread already owns the read/write lock.");
				DKASSERT_DESC_DEBUG(ret != EINVAL, "The value specified by rwlock is invalid.");
				DKASSERT_DESC_DEBUG(ret != ENOMEM, "Insufficient memory?");
				return ret == 0;
			}
开发者ID:hhg128,项目名称:DKGL,代码行数:9,代码来源:DKSharedLock.cpp


示例19: kl_pthread_rwlock_wrlock

void kl_pthread_rwlock_wrlock(void *data, bool tryOnly)
{
	if (tryOnly)
	{
		pthread_rwlock_trywrlock((pthread_rwlock_t *)data);
	} else {
		pthread_rwlock_wrlock((pthread_rwlock_t *)data);
	}
}
开发者ID:lessc0de,项目名称:KafkaLite,代码行数:9,代码来源:klpthreadmutex.c


示例20: TryWriteLock

/******************************************************************************
函数名 :TryWriteLock
功能   :尝试对系统读写锁进行写加锁
输入   :无
输出   :无
返回值 :成功返回1,失败0
其他   :无
******************************************************************************/
int CRWLock::TryWriteLock()
{
	if (0 == pthread_rwlock_trywrlock(&m_rwlock))
	{
		return 1;
	}
	
	return 0;
}
开发者ID:hehenpan,项目名称:backend_server_for_loginserver,代码行数:17,代码来源:ThreadSync.cpp



注:本文中的pthread_rwlock_trywrlock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pthread_rwlock_unlock函数代码示例发布时间:2022-05-30
下一篇:
C++ pthread_rwlock_tryrdlock函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap