MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
one_thread_per_connection_thread_handler.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11//
12// Created by Wangyunlai on 2024/01/10.
13//
14
15#include "net/thread_handler.h"
16#include "common/lang/mutex.h"
17#include "common/lang/unordered_map.h"
18
19class Worker;
20
26{
27public:
30
32 virtual RC start() override { return RC::SUCCESS; }
33
35 virtual RC stop() override;
37 virtual RC await_stop() override;
38
40 virtual RC new_connection(Communicator *communicator) override;
42 virtual RC close_connection(Communicator *communicator) override;
43
44private:
46 unordered_map<Communicator *, Worker *> thread_map_; // 当前编译器没有支持jthread
48 mutex lock_;
49};
负责与客户端通讯
Definition: communicator.h:42
一个连接一个线程的线程模型
Definition: one_thread_per_connection_thread_handler.h:26
virtual RC await_stop() override
等待线程模型停止
Definition: one_thread_per_connection_thread_handler.cpp:168
mutex lock_
保护线程安全的锁
Definition: one_thread_per_connection_thread_handler.h:48
virtual RC close_connection(Communicator *communicator) override
连接断开时,调用此接口。通常都是内部调用
Definition: one_thread_per_connection_thread_handler.cpp:136
unordered_map< Communicator *, Worker * > thread_map_
记录一个连接Communicator关联的线程数据
Definition: one_thread_per_connection_thread_handler.h:46
virtual RC new_connection(Communicator *communicator) override
有新的连接到达时,调用此接口
Definition: one_thread_per_connection_thread_handler.cpp:121
virtual RC start() override
启动线程模型
Definition: one_thread_per_connection_thread_handler.h:32
virtual RC stop() override
停止线程模型
Definition: one_thread_per_connection_thread_handler.cpp:158
Definition: thread_handler.h:28
Definition: one_thread_per_connection_thread_handler.cpp:29