Chinaunix首页 | 论坛 | 博客
  • 博客访问: 535982
  • 博文数量: 142
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1452
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-12 16:28
文章分类

全部博文(142)

文章存档

2016年(10)

2015年(60)

2014年(72)

我的朋友

分类: C/C++

2014-12-16 10:54:48


点击(此处)折叠或打开

  1. #include "../unipc.h"
  2. #include "pthread_rwlock.h"
  3. int my_phread_rwlock_tryrdlock(my_pthread_rwlock_t *rw)
  4. {
  5.     int rc;

  6.     if(rw->rw_magic != RW_MAGIC)
  7.         return EINVAL;

  8.     rc = pthread_mutex_lock(&rw->rw_mutex);
  9.     if (rc != 0)
  10.         return rc;

  11.     if((rw->rw_refcount == -1) || (rw->rw_nwaitwriters > 0)) {
  12.         rc = EBUSY;
  13.     }else {
  14.         rw->rw_refcount++;
  15.     }
  16.     pthread_mutex_unlock(&rw->rw_mutex);
  17.     return rc;
  18. }


阅读(350) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~