MySQL 9.1.0
Source Code Documentation
thread_resource_control.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License, version 2.0,
4 as published by the Free Software Foundation.
5
6 This program is designed to work with certain software (including
7 but not limited to OpenSSL) that is licensed under separate terms,
8 as designated in a particular file or component or in included license
9 documentation. The authors of MySQL hereby grant you an additional
10 permission to link the program and your derivative works with the
11 separately licensed software that they have either included with
12 the program or referenced in the documentation.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef RESOURCEGROUPS_THREAD_RESOURCE_CONTROL_H_
24#define RESOURCEGROUPS_THREAD_RESOURCE_CONTROL_H_
25
26#include <vector>
27
28#include "my_thread_os_id.h"
30
31namespace resourcegroups {
32
33/**
34 Class that abstracts the resource control that can be applied
35 to threads. The resource controls include set of CPU IDS which
36 determine the CPUS the thread is allowed to run and the thread
37 priority.
38*/
39
41 public:
42 /**
43 Default constructor
44 */
45
47
48 /**
49 Get priority associated with Thread resource control object.
50
51 @return an int value indicating the thread priority.
52 */
53
54 int priority() const { return m_priority; }
55
56 /**
57 Set priority associated with Thread resource control object.
58 */
59
61
62 /**
63 Get const pointer of vector of CPU ID range.
64
65 @return pointer to vector of CPU ID range.
66 */
67
68 const std::vector<Range> &vcpu_vector() const { return m_vcpu_vector; }
69
70 /**
71 Set the CPU ID range vector.
72 */
73
74 void set_vcpu_vector(const std::vector<Range> &vcpu_vector) {
75 m_vcpu_vector.clear();
76 for (const auto &cpu_range : vcpu_vector)
77 m_vcpu_vector.emplace_back(cpu_range);
78 }
79
80 /**
81 Apply the thread resource controls to the thread on
82 which this function is called.
83
84 @return false if control application is successful else true
85 */
86
87 bool apply_control();
88
89 /**
90 Apply the thread resource controls to thread identified by
91 the thread os id.
92
93 @param thread_os_id Thread OS ID.
94
95 @return false if control application is successful else true
96 */
97
98 bool apply_control(my_thread_os_id_t thread_os_id);
99
100 /**
101 Validate the CPU ID Ranges and thread priority value associate with
102 the thread resource control object.
103
104 @return false if validation is successful else true.
105 */
106
107 bool validate(const Type &resource_group_type) const;
108
109 private:
110 /**
111 Vector of CPU ID range.
112 */
113 std::vector<Range> m_vcpu_vector;
114
115 /**
116 Thread priority value
117 */
119};
120} // namespace resourcegroups
121#endif // RESOURCEGROUPS_THREAD_RESOURCE_CONTROL_H_
Class that abstracts the resource control that can be applied to threads.
Definition: thread_resource_control.h:40
bool validate(const Type &resource_group_type) const
Validate the CPU ID Ranges and thread priority value associate with the thread resource control objec...
Definition: thread_resource_control.cc:34
bool apply_control()
Apply the thread resource controls to the thread on which this function is called.
Definition: thread_resource_control.cc:75
const std::vector< Range > & vcpu_vector() const
Get const pointer of vector of CPU ID range.
Definition: thread_resource_control.h:68
void set_priority(int priority)
Set priority associated with Thread resource control object.
Definition: thread_resource_control.h:60
void set_vcpu_vector(const std::vector< Range > &vcpu_vector)
Set the CPU ID range vector.
Definition: thread_resource_control.h:74
int priority() const
Get priority associated with Thread resource control object.
Definition: thread_resource_control.h:54
Thread_resource_control()
Default constructor.
Definition: thread_resource_control.h:46
int m_priority
Thread priority value.
Definition: thread_resource_control.h:118
std::vector< Range > m_vcpu_vector
Vector of CPU ID range.
Definition: thread_resource_control.h:113
Portable wrapper for gettid().
unsigned long long my_thread_os_id_t
Definition: my_thread_os_id.h:48
Definition: dd_resource_group.h:29
Type
Definition: resource_group_basic_types.h:33