forked from torvalds/linux
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thread: move thread bits accessors to separated file
Thread bits may be accessed from low-level code, so isolating is a measure to avoid circular dependencies in header files. The exact reason for circular dependency is WARN_ON() macro added in patch edd63a2 "set_restore_sigmask() is never called without SIGPENDING (and never should be)" Signed-off-by: Yury Norov <ynorov@caviumnetworks.com> Signed-off-by: Yury Norov <ynorov@marvell.com>
- Loading branch information
Showing
3 changed files
with
89 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
|
||
/* Common low-level thread bits accessors */ | ||
|
||
#ifndef _LINUX_THREAD_BITS_H | ||
#define _LINUX_THREAD_BITS_H | ||
|
||
#ifndef __ASSEMBLY__ | ||
|
||
/* | ||
* For per-arch arch_within_stack_frames() implementations, defined in | ||
* asm/thread_info.h. | ||
*/ | ||
enum { | ||
BAD_STACK = -1, | ||
NOT_STACK = 0, | ||
GOOD_FRAME, | ||
GOOD_STACK, | ||
}; | ||
|
||
#include <linux/bitops.h> | ||
#include <asm/thread_info.h> | ||
|
||
#ifdef CONFIG_THREAD_INFO_IN_TASK | ||
/* | ||
* For CONFIG_THREAD_INFO_IN_TASK kernels we need <asm/current.h> for the | ||
* definition of current, but for !CONFIG_THREAD_INFO_IN_TASK kernels, | ||
* including <asm/current.h> can cause a circular dependency on some platforms. | ||
*/ | ||
#include <asm/current.h> | ||
#define current_thread_info() ((struct thread_info *)current) | ||
#endif | ||
|
||
/* | ||
* flag set/clear/test wrappers | ||
* - pass TIF_xxxx constants to these functions | ||
*/ | ||
|
||
static inline void set_ti_thread_flag(struct thread_info *ti, int flag) | ||
{ | ||
set_bit(flag, (unsigned long *)&ti->flags); | ||
} | ||
|
||
static inline void clear_ti_thread_flag(struct thread_info *ti, int flag) | ||
{ | ||
clear_bit(flag, (unsigned long *)&ti->flags); | ||
} | ||
|
||
static inline void update_ti_thread_flag(struct thread_info *ti, int flag, | ||
bool value) | ||
{ | ||
if (value) | ||
set_ti_thread_flag(ti, flag); | ||
else | ||
clear_ti_thread_flag(ti, flag); | ||
} | ||
|
||
static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag) | ||
{ | ||
return test_and_set_bit(flag, (unsigned long *)&ti->flags); | ||
} | ||
|
||
static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag) | ||
{ | ||
return test_and_clear_bit(flag, (unsigned long *)&ti->flags); | ||
} | ||
|
||
static inline int test_ti_thread_flag(struct thread_info *ti, int flag) | ||
{ | ||
return test_bit(flag, (unsigned long *)&ti->flags); | ||
} | ||
|
||
#define set_thread_flag(flag) \ | ||
set_ti_thread_flag(current_thread_info(), flag) | ||
#define clear_thread_flag(flag) \ | ||
clear_ti_thread_flag(current_thread_info(), flag) | ||
#define update_thread_flag(flag, value) \ | ||
update_ti_thread_flag(current_thread_info(), flag, value) | ||
#define test_and_set_thread_flag(flag) \ | ||
test_and_set_ti_thread_flag(current_thread_info(), flag) | ||
#define test_and_clear_thread_flag(flag) \ | ||
test_and_clear_ti_thread_flag(current_thread_info(), flag) | ||
#define test_thread_flag(flag) \ | ||
test_ti_thread_flag(current_thread_info(), flag) | ||
|
||
#endif /* !__ASSEMBLY__ */ | ||
#endif /* _LINUX_THREAD_BITS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters