MySQL 9.0.0
Source Code Documentation
my_xp_thread.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MY_XP_THREAD_INCLUDED
25#define MY_XP_THREAD_INCLUDED
26
27#ifndef XCOM_STANDALONE
28
29#include "my_sys.h"
30#include "my_thread.h"
32
37
38#define NATIVE_THREAD_CREATE_DETACHED MY_THREAD_CREATE_DETACHED
39#define NATIVE_THREAD_CREATE_JOINABLE MY_THREAD_CREATE_JOINABLE
40#endif
41
43
44/**
45 @class My_xp_thread
46
47 Abstract class used to wrap mutex for various platforms.
48
49 A typical use case is:
50
51 @code{.cpp}
52
53 My_xp_thread *thread= new My_xp_thread_impl();
54 thread->create(key, NULL, &function, &args);
55
56 void *result;
57 thread->join(&result);
58
59 @endcode
60*/
62 public:
63 /**
64 Creates thread.
65
66 @param key thread instrumentation key
67 @param attr thread attributes
68 @param func routine function
69 @param arg function parameters
70 @return success status
71 */
72
74 native_start_routine func, void *arg) = 0;
75
76 /**
77 Creates a detached thread.
78
79 @param key thread instrumentation key
80 @param attr thread attributes
81 @param func routine function
82 @param arg function parameters
83 @return success status
84 */
85
87 native_start_routine func, void *arg) = 0;
88
89 /**
90 Suspend invoking thread until this thread terminates.
91
92 @param value_ptr pointer for a placeholder for the terminating thread status
93 @return success status
94 */
95
96 virtual int join(void **value_ptr) = 0;
97
98 /**
99 Cancel this thread.
100
101 @return success status
102 */
103
104 virtual int cancel() = 0;
105
106 /**
107 Retrieves native thread reference
108
109 @return native thread pointer
110 */
111
113
114 virtual ~My_xp_thread() = default;
115};
116
117#ifndef XCOM_STANDALONE
119 public:
120 explicit My_xp_thread_server();
121 ~My_xp_thread_server() override;
122
124 native_start_routine func, void *arg) override;
126 native_start_routine func, void *arg) override;
127 int join(void **value_ptr) override;
128 int cancel() override;
130
131 protected:
133};
134#endif
135
136#ifndef XCOM_STANDALONE
138#endif
139{
140 public:
141 explicit My_xp_thread_impl() = default;
142 ~My_xp_thread_impl() override = default;
143};
144
146 public:
147 /**
148 Initialize a MySQL context on the invoking thread.
149
150 @return success status
151 */
152
153 static bool init();
154
155 /**
156 Terminate invoking thread.
157
158 @param value_ptr thread exit value pointer
159 */
160
161 static void exit(void *value_ptr);
162
163 /**
164 Initialize thread attributes object.
165
166 @param attr thread attributes
167 @return success status
168 */
169
170 static int attr_init(native_thread_attr_t *attr);
171
172 /**
173 Destroy thread attributes object.
174
175 @param attr thread attributes
176 @return success status
177 */
178
179 static int attr_destroy(native_thread_attr_t *attr);
180
181 /**
182 Retrieve current thread id.
183
184 @return current thread id
185 */
186
187 static native_thread_t self();
188
189 /**
190 Compares two thread identifiers.
191
192 @param t1 identifier of one thread
193 @param t2 identifier of another thread
194 @retval 0 if ids are different
195 @retval some other value if ids are equal
196 */
197
198 static int equal(native_thread_t t1, native_thread_t t2);
199
200 /**
201 Sets the stack size attribute of the thread attributes object referred
202 to by attr to the value specified in stacksize.
203
204 @param attr thread attributes
205 @param stacksize new attribute stack size
206 @retval 0 on success
207 @retval nonzero error number, on error
208 */
209
210 static int attr_setstacksize(native_thread_attr_t *attr, size_t stacksize);
211
212 /**
213 Returns the stack size attribute of the thread attributes object referred
214 to by attr in the buffer pointed to by stacksize.
215
216 @param attr thread attributes
217 @param stacksize pointer to attribute stack size returning placeholder
218 @retval 0 on success
219 @retval nonzero error number, on error
220 */
221
222 static int attr_getstacksize(native_thread_attr_t *attr, size_t *stacksize);
223
224 /**
225 Sets the detach state attribute of the thread attributes object referred
226 to by attr to the value specified in detachstate.
227
228 @param attr thread attributes
229 @param detachstate determines if the thread is to be created in a joinable
230 (MY_THREAD_CREATE_JOINABLE) or a detached state (MY_THREAD_CREATE_DETACHED)
231 @retval 0 on success
232 @retval nonzero error number, on error
233 */
234
235 static int attr_setdetachstate(native_thread_attr_t *attr, int detachstate);
236
237 /**
238 Causes the calling thread to relinquish the CPU, and to be moved to the
239 end of the queue and another thread gets to run.
240 */
241
242 static void yield();
243};
244
245#endif // MY_XP_THREAD_INCLUDED
Definition: my_xp_thread.h:139
My_xp_thread_impl()=default
~My_xp_thread_impl() override=default
Definition: my_xp_thread.h:118
int join(void **value_ptr) override
Suspend invoking thread until this thread terminates.
Definition: my_xp_thread.cc:69
native_thread_t * get_native_thread() override
Retrieves native thread reference.
Definition: my_xp_thread.cc:38
int cancel() override
Cancel this thread.
Definition: my_xp_thread.cc:73
~My_xp_thread_server() override
Definition: my_xp_thread.cc:36
My_xp_thread_server()
Definition: my_xp_thread.cc:32
int create(PSI_thread_key key, const native_thread_attr_t *attr, native_start_routine func, void *arg) override
Creates thread.
Definition: my_xp_thread.cc:42
int create_detached(PSI_thread_key key, native_thread_attr_t *attr, native_start_routine func, void *arg) override
Creates a detached thread.
Definition: my_xp_thread.cc:48
native_thread_handle * m_thread_handle
Definition: my_xp_thread.h:132
Definition: my_xp_thread.h:145
static void exit(void *value_ptr)
Terminate invoking thread.
Definition: my_xp_thread.cc:77
static int attr_destroy(native_thread_attr_t *attr)
Destroy thread attributes object.
Definition: my_xp_thread.cc:86
static int attr_setstacksize(native_thread_attr_t *attr, size_t stacksize)
Sets the stack size attribute of the thread attributes object referred to by attr to the value specif...
Definition: my_xp_thread.cc:96
static int attr_init(native_thread_attr_t *attr)
Initialize thread attributes object.
Definition: my_xp_thread.cc:82
static void yield()
Causes the calling thread to relinquish the CPU, and to be moved to the end of the queue and another ...
Definition: my_xp_thread.cc:111
static int attr_getstacksize(native_thread_attr_t *attr, size_t *stacksize)
Returns the stack size attribute of the thread attributes object referred to by attr in the buffer po...
Definition: my_xp_thread.cc:106
static int attr_setdetachstate(native_thread_attr_t *attr, int detachstate)
Sets the detach state attribute of the thread attributes object referred to by attr to the value spec...
Definition: my_xp_thread.cc:101
static bool init()
Initialize a MySQL context on the invoking thread.
Definition: my_xp_thread.cc:75
static int equal(native_thread_t t1, native_thread_t t2)
Compares two thread identifiers.
Definition: my_xp_thread.cc:92
Abstract class used to wrap mutex for various platforms.
Definition: my_xp_thread.h:61
virtual int create(PSI_thread_key key, const native_thread_attr_t *attr, native_start_routine func, void *arg)=0
Creates thread.
virtual ~My_xp_thread()=default
virtual int create_detached(PSI_thread_key key, native_thread_attr_t *attr, native_start_routine func, void *arg)=0
Creates a detached thread.
virtual int join(void **value_ptr)=0
Suspend invoking thread until this thread terminates.
virtual native_thread_t * get_native_thread()=0
Retrieves native thread reference.
virtual int cancel()=0
Cancel this thread.
unsigned int PSI_thread_key
Instrumented thread key.
Definition: psi_thread_bits.h:50
Common header for many mysys elements.
Defines to make different thread packages compatible.
void *(* my_start_routine)(void *)
Definition: my_thread.h:72
pthread_attr_t my_thread_attr_t
Definition: my_thread_bits.h:49
pthread_t my_thread_t
Definition: my_thread_bits.h:48
my_thread_t native_thread_t
Definition: my_xp_thread.h:33
my_start_routine native_start_routine
Definition: my_xp_thread.h:36
my_thread_attr_t native_thread_attr_t
Definition: my_xp_thread.h:35
my_thread_handle native_thread_handle
Definition: my_xp_thread.h:34
Performance schema instrumentation interface.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Definition: my_thread_bits.h:58