linux/include/linux/preempt.h
<<
>>
Prefs
   1#ifndef __LINUX_PREEMPT_H
   2#define __LINUX_PREEMPT_H
   3
   4/*
   5 * include/linux/preempt.h - macros for accessing and manipulating
   6 * preempt_count (used for kernel preemption, interrupt count, etc.)
   7 */
   8
   9#include <linux/thread_info.h>
  10#include <linux/linkage.h>
  11#include <linux/list.h>
  12
  13#ifdef CONFIG_DEBUG_PREEMPT
  14  extern void add_preempt_count(int val);
  15  extern void sub_preempt_count(int val);
  16#else
  17# define add_preempt_count(val) do { preempt_count() += (val); } while (0)
  18# define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
  19#endif
  20
  21#define inc_preempt_count() add_preempt_count(1)
  22#define dec_preempt_count() sub_preempt_count(1)
  23
  24#define preempt_count() (current_thread_info()->preempt_count)
  25
  26#ifdef CONFIG_PREEMPT
  27
  28asmlinkage void preempt_schedule(void);
  29
  30#define preempt_disable() \
  31do { \
  32        inc_preempt_count(); \
  33        barrier(); \
  34} while (0)
  35
  36#define preempt_enable_no_resched() \
  37do { \
  38        barrier(); \
  39        dec_preempt_count(); \
  40} while (0)
  41
  42#define preempt_check_resched() \
  43do { \
  44        if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
  45                preempt_schedule(); \
  46} while (0)
  47
  48#define preempt_enable() \
  49do { \
  50        preempt_enable_no_resched(); \
  51        barrier(); \
  52        preempt_check_resched(); \
  53} while (0)
  54
  55#else
  56
  57#define preempt_disable()               do { } while (0)
  58#define preempt_enable_no_resched()     do { } while (0)
  59#define preempt_enable()                do { } while (0)
  60#define preempt_check_resched()         do { } while (0)
  61
  62#endif
  63
  64#ifdef CONFIG_PREEMPT_NOTIFIERS
  65
  66struct preempt_notifier;
  67
  68/**
  69 * preempt_ops - notifiers called when a task is preempted and rescheduled
  70 * @sched_in: we're about to be rescheduled:
  71 *    notifier: struct preempt_notifier for the task being scheduled
  72 *    cpu:  cpu we're scheduled on
  73 * @sched_out: we've just been preempted
  74 *    notifier: struct preempt_notifier for the task being preempted
  75 *    next: the task that's kicking us out
  76 */
  77struct preempt_ops {
  78        void (*sched_in)(struct preempt_notifier *notifier, int cpu);
  79        void (*sched_out)(struct preempt_notifier *notifier,
  80                          struct task_struct *next);
  81};
  82
  83/**
  84 * preempt_notifier - key for installing preemption notifiers
  85 * @link: internal use
  86 * @ops: defines the notifier functions to be called
  87 *
  88 * Usually used in conjunction with container_of().
  89 */
  90struct preempt_notifier {
  91        struct hlist_node link;
  92        struct preempt_ops *ops;
  93};
  94
  95void preempt_notifier_register(struct preempt_notifier *notifier);
  96void preempt_notifier_unregister(struct preempt_notifier *notifier);
  97
  98static inline void preempt_notifier_init(struct preempt_notifier *notifier,
  99                                     struct preempt_ops *ops)
 100{
 101        INIT_HLIST_NODE(&notifier->link);
 102        notifier->ops = ops;
 103}
 104
 105#endif
 106
 107#endif /* __LINUX_PREEMPT_H */
 108
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.