My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sw_wait.h
Go to the documentation of this file.
1 /*
2  * OpenVirtualization:
3  * For additional details and support contact developer@sierraware.com.
4  * Additional documentation can be found at www.openvirtualization.org
5  *
6  * Copyright (C) 2010-2014 SierraWare
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  */
23 /*
24  * SW Wait-Queue Definition.
25  */
26 
27 #ifndef __SW_WAIT_H_
28 #define __SW_WAIT_H_
29 
30 #include <sw_types.h>
31 #include <sw_semaphores.h>
32 #include <sw_list.h>
33 #include <sw_timer.h>
34 #include <task.h>
35 
36 
37 #define TASK_INTERRUPTIBLE 0
38 #define TASK_UNINTERRUPTIBLE 1
39 
40 #define WAKE_UP 0
41 #define WAKE_UP_IMMEDIATE 1
42 
43 struct wait_queue;
44 
53 typedef void (*wait_queue_function)(struct wait_queue* , u32);
54 
64 };
65 
70 struct wait_queue{
71  struct list head;
72  void* data;
74 };
75 
76 
77 #define __sw_wait_event(wq_head, condition) \
78 do { \
79  \
80  struct wait_queue wq; \
81  INIT_LIST_HEAD(&wq.head); \
82  wq.data = get_current_task(); \
83  wq.func = sw_default_wake_function; \
84  \
85  while(1){ \
86  \
87  if(condition) \
88  break; \
89  sw_prepare_for_wait(wq_head, &wq, TASK_STATE_WAIT); \
90  schedule(); \
91  } \
92  \
93  sw_complete_wait(wq_head, &wq); \
94  \
95  \
96 }while(0)
97 
98 
113 #define sw_wait_event(wq_head, condition) \
114 do { \
115  if(condition) \
116  break; \
117  __sw_wait_event(wq_head, condition); \
118 }while(0)
119 
120 #ifdef OTZONE_ASYNC_NOTIFY_SUPPORT
121 
122 #define __sw_wait_event_async(wq_head, condition, retval) \
123 do { \
124  \
125  struct wait_queue wq; \
126  INIT_LIST_HEAD(&wq.head); \
127  wq.data = get_current_task(); \
128  wq.func = sw_default_wake_function; \
129  int call_smc = 1; \
130  \
131  while(1){ \
132  \
133  if(condition) \
134  break; \
135  sw_prepare_for_wait(wq_head, &wq, TASK_STATE_WAIT); \
136  if(call_smc){ \
137  call_smc = 0; \
138  set_secure_api_ret(retval); \
139  } \
140  schedule(); \
141  } \
142  \
143  sw_complete_wait(wq_head, &wq); \
144  \
145  \
146 }while(0)
147 
162 #define sw_wait_event_async(wq_head, condition, retval) \
163 do { \
164  if(condition) \
165  break; \
166  __sw_wait_event_async(wq_head, condition, retval); \
167 }while(0)
168 
169 #endif
170 
181 void sw_wakeup(struct wait_queue_head * wq_head, u32 wakeup_flag);
182 
195 void sw_wakeup_all(struct wait_queue_head * wq_head, u32 wakeup_flag);
196 
207 void sw_default_wake_function(struct wait_queue* wq, u32 flag);
208 
219  wait_queue_function func);
227 void sw_init_waitqueue_entry(struct wait_queue* wq);
228 
238 void sw_add_to_waitqueue(struct wait_queue_head* wq_head,
239  struct wait_queue* wq);
240 
250 void sw_remove_from_waitqueue(struct wait_queue_head* wq_head,
251  struct wait_queue* wq);
252 
259 void sw_set_task_state(int state);
260 
273 void sw_prepare_for_wait(struct wait_queue_head* wq_head, struct wait_queue* wq,
274  u32 state);
275 
285 void sw_complete_wait(struct wait_queue_head *wq_head, struct wait_queue *wq);
286 
287 #endif
void sw_prepare_for_wait(struct wait_queue_head *wq_head, struct wait_queue *wq, u32 state)
This function sets the state of the TASK to the given state and adds the element to the waitqueue...
Definition: sw_wait.c:144
struct list elements_list
Definition: sw_wait.h:63
wait_queue_function func
Definition: sw_wait.h:73
void sw_wakeup(struct wait_queue_head *wq_head, u32 wakeup_flag)
This function wakes up an element from the given waitqueue.
Definition: sw_wait.c:223
struct spinlock spin_lock
Definition: sw_wait.h:62
void sw_remove_from_waitqueue(struct wait_queue_head *wq_head, struct wait_queue *wq)
This function is called to remove the wait queue element from the wait queue head.
Definition: sw_wait.c:75
void sw_add_to_waitqueue(struct wait_queue_head *wq_head, struct wait_queue *wq)
This function is called to add the wait queue element to the wait queue head.
Definition: sw_wait.c:58
void sw_default_wake_function(struct wait_queue *wq, u32 flag)
This function wakes up a task by changing the state of the task and adding it to the ready to run lis...
Definition: sw_wait.c:253
void sw_init_waitqueue_entry(struct wait_queue *wq)
Initializes the wait queue element.
Definition: sw_wait.c:92
void * data
Definition: sw_wait.h:72
Wait queue list head. Wait queue elements are added to this.
Definition: sw_wait.h:60
void sw_complete_wait(struct wait_queue_head *wq_head, struct wait_queue *wq)
This function is called when the task is woken up and this function removes the waitqueue element fro...
Definition: sw_wait.c:170
Wait queue element.
Definition: sw_wait.h:70
int elements_count
Definition: sw_wait.h:61
void(* wait_queue_function)(struct wait_queue *, u32)
Definition: sw_wait.h:53
Definition: sw_list.h:56
void sw_wakeup_all(struct wait_queue_head *wq_head, u32 wakeup_flag)
This function wakes up all the elements attached to the given waitqueue head.
Definition: sw_wait.c:196
void sw_set_task_state(int state)
This function sets the state of the TASK.
Definition: sw_wait.c:126
Definition: sw_semaphores.h:236
struct list head
Definition: sw_wait.h:71
void sw_init_waitqueue_entry_func(struct wait_queue *wq, wait_queue_function func)
Initializes the wait queue element.
Definition: sw_wait.c:110