treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / perf / util / trigger.h
blob33e997f9ccc84a28a224eb00aec2c732077b7bc7
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __TRIGGER_H_
3 #define __TRIGGER_H_ 1
5 #include "asm/bug.h"
7 /*
8 * Use trigger to model operations which need to be executed when
9 * an event (a signal, for example) is observed.
11 * States and transits:
14 * OFF--> ON --> READY --(hit)--> HIT
15 * ^ |
16 * | (ready)
17 * | |
18 * \_____________/
20 * is_hit and is_ready are two key functions to query the state of
21 * a trigger. is_hit means the event already happen; is_ready means the
22 * trigger is waiting for the event.
25 struct trigger {
26 volatile enum {
27 TRIGGER_ERROR = -2,
28 TRIGGER_OFF = -1,
29 TRIGGER_ON = 0,
30 TRIGGER_READY = 1,
31 TRIGGER_HIT = 2,
32 } state;
33 const char *name;
36 #define TRIGGER_WARN_ONCE(t, exp) \
37 WARN_ONCE(t->state != exp, "trigger '%s' state transist error: %d in %s()\n", \
38 t->name, t->state, __func__)
40 static inline bool trigger_is_available(struct trigger *t)
42 return t->state >= 0;
45 static inline bool trigger_is_error(struct trigger *t)
47 return t->state <= TRIGGER_ERROR;
50 static inline void trigger_on(struct trigger *t)
52 TRIGGER_WARN_ONCE(t, TRIGGER_OFF);
53 t->state = TRIGGER_ON;
56 static inline void trigger_ready(struct trigger *t)
58 if (!trigger_is_available(t))
59 return;
60 t->state = TRIGGER_READY;
63 static inline void trigger_hit(struct trigger *t)
65 if (!trigger_is_available(t))
66 return;
67 TRIGGER_WARN_ONCE(t, TRIGGER_READY);
68 t->state = TRIGGER_HIT;
71 static inline void trigger_off(struct trigger *t)
73 if (!trigger_is_available(t))
74 return;
75 t->state = TRIGGER_OFF;
78 static inline void trigger_error(struct trigger *t)
80 t->state = TRIGGER_ERROR;
83 static inline bool trigger_is_ready(struct trigger *t)
85 return t->state == TRIGGER_READY;
88 static inline bool trigger_is_hit(struct trigger *t)
90 return t->state == TRIGGER_HIT;
93 #define DEFINE_TRIGGER(n) \
94 struct trigger n = {.state = TRIGGER_OFF, .name = #n}
95 #endif