MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
timeout_info.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 Longda on 2010
13//
14
15#ifndef __COMMON_TIME_TIMEOUT_INFO_H__
16#define __COMMON_TIME_TIMEOUT_INFO_H__
17
18#include <time.h>
19
20#include "common/lang/mutex.h"
21namespace common {
22
31{
32public:
37 TimeoutInfo(time_t deadline_);
38
39 // Increase ref count
40 void attach();
41
42 // Decrease ref count
43 void detach();
44
45 // Check if it has timed out
46 bool has_timed_out();
47
48private:
49 // Forbid copy ctor and =() to support ref count
50
51 // Copy constructor.
52 TimeoutInfo(const TimeoutInfo &ti);
53
54 // Assignment operator.
55 TimeoutInfo &operator=(const TimeoutInfo &ti);
56
57protected:
58 // Avoid heap-based \c TimeoutInfo
59 // so it can easily associated with \c StageEvent
60
61 // Destructor.
63
64private:
65 time_t deadline_; // when should this be timed out
66
67 // used to predict timeout if now + reservedTime > deadline_
68 // time_t reservedTime;
69
70 bool is_timed_out_; // timeout flag
71
72 int ref_cnt_; // reference count of this object
73 pthread_mutex_t mutex_; // mutex_ to protect ref_cnt_ and flag
74};
75
76} // namespace common
77#endif // __COMMON_TIME_TIMEOUT_INFO_H__
Definition: timeout_info.h:31