1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef PREEMPT_H 3#define PREEMPT_H 4 5#include <stdbool.h> 6 7#include "bug_on.h" 8 9/* This flag contains garbage if preempt_disable_count is 0. */ 10extern __thread int thread_cpu_id; 11 12/* Support recursive preemption disabling. */ 13extern __thread int preempt_disable_count; 14 15void preempt_disable(void); 16void preempt_enable(void); 17 18static inline void preempt_disable_notrace(void) 19{ 20 preempt_disable(); 21} 22 23static inline void preempt_enable_no_resched(void) 24{ 25 preempt_enable(); 26} 27 28static inline void preempt_enable_notrace(void) 29{ 30 preempt_enable(); 31} 32 33static inline int preempt_count(void) 34{ 35 return preempt_disable_count; 36} 37 38static inline bool preemptible(void) 39{ 40 return !preempt_count(); 41} 42 43static inline int get_cpu(void) 44{ 45 preempt_disable(); 46 return thread_cpu_id; 47} 48 49static inline void put_cpu(void) 50{ 51 preempt_enable(); 52} 53 54static inline void might_sleep(void) 55{ 56 BUG_ON(preempt_disable_count); 57} 58 59#endif 60