Motr  M0
thread.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 
25 #ifndef __MOTR_LIB_THREAD_H__
26 #define __MOTR_LIB_THREAD_H__
27 
28 #ifndef __KERNEL__
29 # include "lib/user_space/thread.h"
30 #else
31 # include "lib/linux_kernel/thread.h"
32 #endif
33 #include "lib/semaphore.h"
34 
35 #include "lib/list.h"
36 #include "addb2/counter.h" /* m0_addb2_sensor */
37 
38 struct m0_bitmap;
39 struct m0;
40 struct m0_addb2_mach;
41 
60 struct m0_thread;
61 
63 struct m0_thread_tls {
71 };
72 
79  TS_PARKED = 0,
81 };
82 
110 struct m0_thread {
113  int (*t_init)(void *);
114  void (*t_func)(void *);
115  void *t_arg;
117  int t_initrc;
120 };
121 
139 #define M0_THREAD_INIT(thread, TYPE, init, func, arg, namefmt, ...) \
140 ({ \
141  typeof(func) __func = (func); \
142  typeof(arg) __arg = (arg); \
143  TYPE __dummy; \
144  (void)(__func == (void (*)(TYPE))NULL); \
145  (void)(&__arg == &__dummy); \
146  m0_thread_init(thread, \
147  (int (*)(void *))init, \
148  (void (*)(void *))__func, \
149  (void *)(unsigned long)__arg, \
150  namefmt , ## __VA_ARGS__); \
151 })
152 
160 M0_INTERNAL int m0_thread_init_impl(struct m0_thread *q, const char *name);
161 
171 M0_INTERNAL void *m0_thread_trampoline(void *t);
172 
194 int m0_thread_init(struct m0_thread *q, int (*init)(void *),
195  void (*func)(void *), void *arg, const char *namefmt, ...)
196  __attribute__ ((format (printf, 5, 6)));
197 
203 void m0_thread_fini(struct m0_thread *q);
204 
221 int m0_thread_join(struct m0_thread *q);
222 
226 M0_INTERNAL int m0_thread_signal(struct m0_thread *q, int sig);
227 
244 M0_INTERNAL int m0_thread_confine(struct m0_thread *q,
245  const struct m0_bitmap *processors);
246 
250 M0_INTERNAL struct m0_thread *m0_thread_self(void);
251 
256 M0_INTERNAL struct m0_thread_tls *m0_thread_tls(void);
257 
266 M0_INTERNAL int m0_threads_init(struct m0 *instance);
267 M0_INTERNAL void m0_threads_fini(void);
268 
269 M0_INTERNAL int m0_threads_once_init(void);
270 M0_INTERNAL void m0_threads_once_fini(void);
271 
273 M0_INTERNAL void m0_enter_awkward(void);
274 
276 M0_INTERNAL void m0_exit_awkward(void);
277 
279 M0_INTERNAL bool m0_is_awkward(void);
280 
284 M0_INTERNAL uint64_t m0_pid(void);
285 
290 M0_INTERNAL uint64_t m0_process(void);
291 
310 M0_INTERNAL int m0_thread_adopt(struct m0_thread *thread, struct m0 *instance);
311 
315 M0_INTERNAL void m0_thread_shun(void);
316 
317 M0_INTERNAL int m0_thread_arch_adopt(struct m0_thread *thread,
318  struct m0 *instance, bool full);
319 M0_INTERNAL void m0_thread_arch_shun(void);
320 
322 #endif /* __MOTR_LIB_THREAD_H__ */
323 
324 /*
325  * Local variables:
326  * c-indentation-style: "K&R"
327  * c-basic-offset: 8
328  * tab-width: 8
329  * fill-column: 80
330  * scroll-step: 1
331  * End:
332  */
static struct m0_semaphore q
Definition: rwlock.c:55
M0_INTERNAL int m0_thread_signal(struct m0_thread *q, int sig)
Definition: uthread.c:124
M0_INTERNAL int m0_thread_arch_adopt(struct m0_thread *thread, struct m0 *instance, bool full)
Definition: uthread.c:231
struct m0_addb2_mach * tls_addb2_mach
Definition: thread.h:68
M0_INTERNAL int m0_threads_once_init(void)
Definition: uthread.c:168
M0_INTERNAL uint64_t m0_process(void)
Definition: uthread.c:226
static void full(void)
Definition: base.c:334
struct m0 * tls_m0_instance
Definition: thread.h:65
struct m0_thread_tls t_tls
Definition: thread.h:118
enum m0_md_lustre_logrec_type __attribute__
Definition: balloc.c:2745
struct m0_semaphore t_wait
Definition: thread.h:116
m0_thread_state
Definition: thread.h:78
M0_INTERNAL uint64_t m0_pid(void)
Definition: uthread.c:221
M0_INTERNAL int m0_thread_adopt(struct m0_thread *thread, struct m0 *instance)
Definition: thread.c:127
M0_INTERNAL int m0_threads_init(struct m0 *instance)
Definition: uthread.c:155
struct m0_thread_arch_tls tls_arch
Definition: thread.h:67
const char * name
Definition: trace.c:110
M0_INTERNAL void * m0_thread_trampoline(void *arg)
Definition: thread.c:101
struct m0_thread thread
Definition: note.c:104
static struct m0_thread t[8]
Definition: service_ut.c:1230
M0_INTERNAL int m0_thread_confine(struct m0_thread *q, const struct m0_bitmap *processors)
Definition: uthread.c:129
int m0_thread_init(struct m0_thread *q, int(*init)(void *), void(*func)(void *), void *arg, const char *namefmt,...)
Definition: thread.c:41
void m0_thread_fini(struct m0_thread *q)
Definition: thread.c:92
Definition: instance.h:80
M0_INTERNAL void m0_enter_awkward(void)
Definition: uthread.c:194
struct m0_addb2_sensor tls_clock
Definition: thread.h:70
M0_INTERNAL int m0_thread_init_impl(struct m0_thread *q, const char *name)
Definition: uthread.c:103
M0_INTERNAL void m0_threads_fini(void)
Definition: uthread.c:163
M0_INTERNAL void m0_thread_shun(void)
Definition: thread.c:134
int(* t_init)(void *)
Definition: thread.h:113
int init(struct workload *w)
M0_INTERNAL void m0_exit_awkward(void)
Definition: uthread.c:208
format
Definition: hist.py:128
int m0_thread_join(struct m0_thread *q)
Definition: uthread.c:111
void(* t_func)(void *)
Definition: thread.h:114
M0_INTERNAL struct m0_thread * m0_thread_self(void)
Definition: thread.c:122
int t_initrc
Definition: thread.h:117
static struct m0 instance
Definition: main.c:78
M0_INTERNAL bool m0_is_awkward(void)
Definition: uthread.c:216
void * t_arg
Definition: thread.h:115
struct m0_thread * tls_self
Definition: thread.h:69
struct m0_thread_handle t_h
Definition: thread.h:112
M0_INTERNAL void m0_thread_arch_shun(void)
Definition: uthread.c:244
char t_namebuf[M0_THREAD_NAME_LEN]
Definition: thread.h:119
M0_INTERNAL void m0_threads_once_fini(void)
Definition: uthread.c:189
enum m0_thread_state t_state
Definition: thread.h:111