博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tars源码漫谈第25篇------tc_thread_rwlock.h/tc_thread_rwlock.cpp(读写锁)
阅读量:4142 次
发布时间:2019-05-25

本文共 1398 字,大约阅读时间需要 4 分钟。

      tc_thread_rwlock里面的类TC_ThreadRWLocker是对读写锁操作的封装。 而读写锁, 是linux中非常基本的概念, 在某次面试的时候, 我还被问到过。

      来看看:

/** * Tencent is pleased to support the open source community by making Tars available. * * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. * * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except  * in compliance with the License. You may obtain a copy of the License at * * https://opensource.org/licenses/BSD-3-Clause * * Unless required by applicable law or agreed to in writing, software distributed  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  * CONDITIONS OF ANY KIND, either express or implied. See the License for the  * specific language governing permissions and limitations under the License. */#include "util/tc_thread_rwlock.h"#include 
#include
#include
namespace tars{TC_ThreadRWLocker::TC_ThreadRWLocker(){ int ret = ::pthread_rwlock_init(&m_sect, NULL); assert(ret == 0); if(ret != 0) { throw TC_ThreadRW_Exception("[TC_ThreadRWLocker::TC_ThreadRWLocker] pthread_rwlock_init error", ret); }}TC_ThreadRWLocker::~TC_ThreadRWLocker(){ int ret = ::pthread_rwlock_destroy(&m_sect); if(ret != 0) { cerr<<"[TC_ThreadRWLocker::~TC_ThreadRWLocker] pthread_rwlock_destroy error:"<
<

          可以看到, 是简单的封装, 别无其他。

 

 

转载地址:http://egwti.baihongyu.com/

你可能感兴趣的文章
Mysql初始化的命令
查看>>
MySQL关键字的些许问题
查看>>
浅谈HTML
查看>>
css基础
查看>>
Servlet进阶和JSP基础
查看>>
servlet中的cookie和session
查看>>
过滤器及JSP九大隐式对象
查看>>
软件(项目)的分层
查看>>
菜单树
查看>>
Servlet的生命周期
查看>>
JAVA八大经典书籍,你看过几本?
查看>>
《读书笔记》—–书单推荐
查看>>
JAVA数据类型
查看>>
【Python】学习笔记——-6.2、使用第三方模块
查看>>
【Python】学习笔记——-7.0、面向对象编程
查看>>
【Python】学习笔记——-7.2、访问限制
查看>>
【Python】学习笔记——-7.3、继承和多态
查看>>
【Python】学习笔记——-7.5、实例属性和类属性
查看>>
git中文安装教程
查看>>
虚拟机 CentOS7/RedHat7/OracleLinux7 配置静态IP地址 Ping 物理机和互联网
查看>>