本文共 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/