3 #include "linux/preempt.h"
6 * In userspace, pthreads are preemptible and can migrate CPUs at any time.
8 * In the kernel, preempt_disable() logic essentially guarantees that a marked
9 * critical section owns its CPU for the relevant block. This is necessary for
10 * various code paths, critically including the percpu system as it allows for
11 * non-atomic reads and writes to CPU-local data structures.
13 * The high performance userspace equivalent would be to use thread local
14 * storage to replace percpu data, but that would be complicated. It should be
15 * correct to instead guarantee mutual exclusion for the critical sections.
18 static pthread_mutex_t preempt_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
20 void preempt_disable(void)
22 pthread_mutex_lock(&preempt_lock);
25 void preempt_enable(void)
27 pthread_mutex_unlock(&preempt_lock);