2 * Copyright (C) 2014 Spreadtrum Communications Inc.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #ifndef _SIMPLE_EVENTS_H_
15 #define _SIMPLE_EVENTS_H_
17 #include <linux/wait.h>
21 struct __simple_event {
28 typedef struct __simple_event simple_event_t;
31 static inline void simple_evnet_init(simple_event_t* evt)
33 spin_lock_init(&evt->lock);
34 init_waitqueue_head(&evt->wq);
38 static inline int simple_evnet_get(simple_event_t* evt, unsigned int req_flags,
39 unsigned int *actual_flags)
47 while(!(*actual_flags)) {
48 wait_event(evt->wq, (evt->flags & req_flags));
50 spin_lock_irqsave(&evt->lock, flags);
51 *actual_flags = evt->flags & req_flags;
52 evt->flags &= ~req_flags;
53 spin_unlock_irqrestore(&evt->lock, flags);
60 static inline int simple_evnet_set(simple_event_t* evt, unsigned int flags,
63 unsigned long irq_flags;
68 spin_lock_irqsave(&evt->lock, irq_flags);
78 spin_unlock_irqrestore(&evt->lock, irq_flags);
88 #endif /* !_SIMPLE_EVENTS_H_ */