manu jose
/
6hrslave
B.3 PROGRAM .SLAVE
pt.h@1:695db1757630, 2010-12-14 (annotated)
- Committer:
- manujose
- Date:
- Tue Dec 14 23:26:42 2010 +0000
- Revision:
- 1:695db1757630
- Parent:
- 0:9092ea8d9a6c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
manujose | 0:9092ea8d9a6c | 1 | /* |
manujose | 0:9092ea8d9a6c | 2 | * Copyright (c) 2004-2005, Swedish Institute of Computer Science. |
manujose | 0:9092ea8d9a6c | 3 | * All rights reserved. |
manujose | 0:9092ea8d9a6c | 4 | * |
manujose | 0:9092ea8d9a6c | 5 | * Redistribution and use in source and binary forms, with or without |
manujose | 0:9092ea8d9a6c | 6 | * modification, are permitted provided that the following conditions |
manujose | 0:9092ea8d9a6c | 7 | * are met: |
manujose | 0:9092ea8d9a6c | 8 | * 1. Redistributions of source code must retain the above copyright |
manujose | 0:9092ea8d9a6c | 9 | * notice, this list of conditions and the following disclaimer. |
manujose | 0:9092ea8d9a6c | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
manujose | 0:9092ea8d9a6c | 11 | * notice, this list of conditions and the following disclaimer in the |
manujose | 0:9092ea8d9a6c | 12 | * documentation and/or other materials provided with the distribution. |
manujose | 0:9092ea8d9a6c | 13 | * 3. Neither the name of the Institute nor the names of its contributors |
manujose | 0:9092ea8d9a6c | 14 | * may be used to endorse or promote products derived from this software |
manujose | 0:9092ea8d9a6c | 15 | * without specific prior written permission. |
manujose | 0:9092ea8d9a6c | 16 | * |
manujose | 0:9092ea8d9a6c | 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
manujose | 0:9092ea8d9a6c | 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
manujose | 0:9092ea8d9a6c | 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
manujose | 0:9092ea8d9a6c | 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
manujose | 0:9092ea8d9a6c | 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
manujose | 0:9092ea8d9a6c | 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
manujose | 0:9092ea8d9a6c | 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
manujose | 0:9092ea8d9a6c | 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
manujose | 0:9092ea8d9a6c | 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
manujose | 0:9092ea8d9a6c | 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
manujose | 0:9092ea8d9a6c | 27 | * SUCH DAMAGE. |
manujose | 0:9092ea8d9a6c | 28 | * |
manujose | 0:9092ea8d9a6c | 29 | * This file is part of the Contiki operating system. |
manujose | 0:9092ea8d9a6c | 30 | * |
manujose | 0:9092ea8d9a6c | 31 | * Author: Adam Dunkels <adam@sics.se> |
manujose | 0:9092ea8d9a6c | 32 | * |
manujose | 0:9092ea8d9a6c | 33 | * $Id: pt.h,v 1.7 2006/10/02 07:52:56 adam Exp $ |
manujose | 0:9092ea8d9a6c | 34 | */ |
manujose | 0:9092ea8d9a6c | 35 | |
manujose | 0:9092ea8d9a6c | 36 | /** |
manujose | 0:9092ea8d9a6c | 37 | * \addtogroup pt |
manujose | 0:9092ea8d9a6c | 38 | * @{ |
manujose | 0:9092ea8d9a6c | 39 | */ |
manujose | 0:9092ea8d9a6c | 40 | |
manujose | 0:9092ea8d9a6c | 41 | /** |
manujose | 0:9092ea8d9a6c | 42 | * \file |
manujose | 0:9092ea8d9a6c | 43 | * Protothreads implementation. |
manujose | 0:9092ea8d9a6c | 44 | * \author |
manujose | 0:9092ea8d9a6c | 45 | * Adam Dunkels <adam@sics.se> |
manujose | 0:9092ea8d9a6c | 46 | * |
manujose | 0:9092ea8d9a6c | 47 | */ |
manujose | 0:9092ea8d9a6c | 48 | |
manujose | 0:9092ea8d9a6c | 49 | #ifndef __PT_H__ |
manujose | 0:9092ea8d9a6c | 50 | #define __PT_H__ |
manujose | 0:9092ea8d9a6c | 51 | |
manujose | 0:9092ea8d9a6c | 52 | #include "lc.h" |
manujose | 0:9092ea8d9a6c | 53 | |
manujose | 0:9092ea8d9a6c | 54 | struct pt { |
manujose | 0:9092ea8d9a6c | 55 | lc_t lc; |
manujose | 0:9092ea8d9a6c | 56 | }; |
manujose | 0:9092ea8d9a6c | 57 | |
manujose | 0:9092ea8d9a6c | 58 | #define PT_WAITING 0 |
manujose | 0:9092ea8d9a6c | 59 | #define PT_YIELDED 1 |
manujose | 0:9092ea8d9a6c | 60 | #define PT_EXITED 2 |
manujose | 0:9092ea8d9a6c | 61 | #define PT_ENDED 3 |
manujose | 0:9092ea8d9a6c | 62 | |
manujose | 0:9092ea8d9a6c | 63 | /** |
manujose | 0:9092ea8d9a6c | 64 | * \name Initialization |
manujose | 0:9092ea8d9a6c | 65 | * @{ |
manujose | 0:9092ea8d9a6c | 66 | */ |
manujose | 0:9092ea8d9a6c | 67 | |
manujose | 0:9092ea8d9a6c | 68 | /** |
manujose | 0:9092ea8d9a6c | 69 | * Initialize a protothread. |
manujose | 0:9092ea8d9a6c | 70 | * |
manujose | 0:9092ea8d9a6c | 71 | * Initializes a protothread. Initialization must be done prior to |
manujose | 0:9092ea8d9a6c | 72 | * starting to execute the protothread. |
manujose | 0:9092ea8d9a6c | 73 | * |
manujose | 0:9092ea8d9a6c | 74 | * \param pt A pointer to the protothread control structure. |
manujose | 0:9092ea8d9a6c | 75 | * |
manujose | 0:9092ea8d9a6c | 76 | * \sa PT_SPAWN() |
manujose | 0:9092ea8d9a6c | 77 | * |
manujose | 0:9092ea8d9a6c | 78 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 79 | */ |
manujose | 0:9092ea8d9a6c | 80 | #define PT_INIT(pt) LC_INIT((pt)->lc) |
manujose | 0:9092ea8d9a6c | 81 | |
manujose | 0:9092ea8d9a6c | 82 | /** @} */ |
manujose | 0:9092ea8d9a6c | 83 | |
manujose | 0:9092ea8d9a6c | 84 | /** |
manujose | 0:9092ea8d9a6c | 85 | * \name Declaration and definition |
manujose | 0:9092ea8d9a6c | 86 | * @{ |
manujose | 0:9092ea8d9a6c | 87 | */ |
manujose | 0:9092ea8d9a6c | 88 | |
manujose | 0:9092ea8d9a6c | 89 | /** |
manujose | 0:9092ea8d9a6c | 90 | * Declaration of a protothread. |
manujose | 0:9092ea8d9a6c | 91 | * |
manujose | 0:9092ea8d9a6c | 92 | * This macro is used to declare a protothread. All protothreads must |
manujose | 0:9092ea8d9a6c | 93 | * be declared with this macro. |
manujose | 0:9092ea8d9a6c | 94 | * |
manujose | 0:9092ea8d9a6c | 95 | * \param name_args The name and arguments of the C function |
manujose | 0:9092ea8d9a6c | 96 | * implementing the protothread. |
manujose | 0:9092ea8d9a6c | 97 | * |
manujose | 0:9092ea8d9a6c | 98 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 99 | */ |
manujose | 0:9092ea8d9a6c | 100 | #define PT_THREAD(name_args) char name_args |
manujose | 0:9092ea8d9a6c | 101 | |
manujose | 0:9092ea8d9a6c | 102 | /** |
manujose | 0:9092ea8d9a6c | 103 | * Declare the start of a protothread inside the C function |
manujose | 0:9092ea8d9a6c | 104 | * implementing the protothread. |
manujose | 0:9092ea8d9a6c | 105 | * |
manujose | 0:9092ea8d9a6c | 106 | * This macro is used to declare the starting point of a |
manujose | 0:9092ea8d9a6c | 107 | * protothread. It should be placed at the start of the function in |
manujose | 0:9092ea8d9a6c | 108 | * which the protothread runs. All C statements above the PT_BEGIN() |
manujose | 0:9092ea8d9a6c | 109 | * invokation will be executed each time the protothread is scheduled. |
manujose | 0:9092ea8d9a6c | 110 | * |
manujose | 0:9092ea8d9a6c | 111 | * \param pt A pointer to the protothread control structure. |
manujose | 0:9092ea8d9a6c | 112 | * |
manujose | 0:9092ea8d9a6c | 113 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 114 | */ |
manujose | 0:9092ea8d9a6c | 115 | #define PT_BEGIN(pt) { char PT_YIELD_FLAG = 1; LC_RESUME((pt)->lc) |
manujose | 0:9092ea8d9a6c | 116 | |
manujose | 0:9092ea8d9a6c | 117 | /** |
manujose | 0:9092ea8d9a6c | 118 | * Declare the end of a protothread. |
manujose | 0:9092ea8d9a6c | 119 | * |
manujose | 0:9092ea8d9a6c | 120 | * This macro is used for declaring that a protothread ends. It must |
manujose | 0:9092ea8d9a6c | 121 | * always be used together with a matching PT_BEGIN() macro. |
manujose | 0:9092ea8d9a6c | 122 | * |
manujose | 0:9092ea8d9a6c | 123 | * \param pt A pointer to the protothread control structure. |
manujose | 0:9092ea8d9a6c | 124 | * |
manujose | 0:9092ea8d9a6c | 125 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 126 | */ |
manujose | 0:9092ea8d9a6c | 127 | #define PT_END(pt) LC_END((pt)->lc); PT_YIELD_FLAG = 0; \ |
manujose | 0:9092ea8d9a6c | 128 | PT_INIT(pt); return PT_ENDED; } |
manujose | 0:9092ea8d9a6c | 129 | |
manujose | 0:9092ea8d9a6c | 130 | /** @} */ |
manujose | 0:9092ea8d9a6c | 131 | |
manujose | 0:9092ea8d9a6c | 132 | /** |
manujose | 0:9092ea8d9a6c | 133 | * \name Blocked wait |
manujose | 0:9092ea8d9a6c | 134 | * @{ |
manujose | 0:9092ea8d9a6c | 135 | */ |
manujose | 0:9092ea8d9a6c | 136 | |
manujose | 0:9092ea8d9a6c | 137 | /** |
manujose | 0:9092ea8d9a6c | 138 | * Block and wait until condition is true. |
manujose | 0:9092ea8d9a6c | 139 | * |
manujose | 0:9092ea8d9a6c | 140 | * This macro blocks the protothread until the specified condition is |
manujose | 0:9092ea8d9a6c | 141 | * true. |
manujose | 0:9092ea8d9a6c | 142 | * |
manujose | 0:9092ea8d9a6c | 143 | * \param pt A pointer to the protothread control structure. |
manujose | 0:9092ea8d9a6c | 144 | * \param condition The condition. |
manujose | 0:9092ea8d9a6c | 145 | * |
manujose | 0:9092ea8d9a6c | 146 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 147 | */ |
manujose | 0:9092ea8d9a6c | 148 | #define PT_WAIT_UNTIL(pt, condition) \ |
manujose | 0:9092ea8d9a6c | 149 | do { \ |
manujose | 0:9092ea8d9a6c | 150 | LC_SET((pt)->lc); \ |
manujose | 0:9092ea8d9a6c | 151 | if(!(condition)) { \ |
manujose | 0:9092ea8d9a6c | 152 | return PT_WAITING; \ |
manujose | 0:9092ea8d9a6c | 153 | } \ |
manujose | 0:9092ea8d9a6c | 154 | } while(0) |
manujose | 0:9092ea8d9a6c | 155 | |
manujose | 0:9092ea8d9a6c | 156 | /** |
manujose | 0:9092ea8d9a6c | 157 | * Block and wait while condition is true. |
manujose | 0:9092ea8d9a6c | 158 | * |
manujose | 0:9092ea8d9a6c | 159 | * This function blocks and waits while condition is true. See |
manujose | 0:9092ea8d9a6c | 160 | * PT_WAIT_UNTIL(). |
manujose | 0:9092ea8d9a6c | 161 | * |
manujose | 0:9092ea8d9a6c | 162 | * \param pt A pointer to the protothread control structure. |
manujose | 0:9092ea8d9a6c | 163 | * \param cond The condition. |
manujose | 0:9092ea8d9a6c | 164 | * |
manujose | 0:9092ea8d9a6c | 165 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 166 | */ |
manujose | 0:9092ea8d9a6c | 167 | #define PT_WAIT_WHILE(pt, cond) PT_WAIT_UNTIL((pt), !(cond)) |
manujose | 0:9092ea8d9a6c | 168 | |
manujose | 0:9092ea8d9a6c | 169 | /** @} */ |
manujose | 0:9092ea8d9a6c | 170 | |
manujose | 0:9092ea8d9a6c | 171 | /** |
manujose | 0:9092ea8d9a6c | 172 | * \name Hierarchical protothreads |
manujose | 0:9092ea8d9a6c | 173 | * @{ |
manujose | 0:9092ea8d9a6c | 174 | */ |
manujose | 0:9092ea8d9a6c | 175 | |
manujose | 0:9092ea8d9a6c | 176 | /** |
manujose | 0:9092ea8d9a6c | 177 | * Block and wait until a child protothread completes. |
manujose | 0:9092ea8d9a6c | 178 | * |
manujose | 0:9092ea8d9a6c | 179 | * This macro schedules a child protothread. The current protothread |
manujose | 0:9092ea8d9a6c | 180 | * will block until the child protothread completes. |
manujose | 0:9092ea8d9a6c | 181 | * |
manujose | 0:9092ea8d9a6c | 182 | * \note The child protothread must be manually initialized with the |
manujose | 0:9092ea8d9a6c | 183 | * PT_INIT() function before this function is used. |
manujose | 0:9092ea8d9a6c | 184 | * |
manujose | 0:9092ea8d9a6c | 185 | * \param pt A pointer to the protothread control structure. |
manujose | 0:9092ea8d9a6c | 186 | * \param thread The child protothread with arguments |
manujose | 0:9092ea8d9a6c | 187 | * |
manujose | 0:9092ea8d9a6c | 188 | * \sa PT_SPAWN() |
manujose | 0:9092ea8d9a6c | 189 | * |
manujose | 0:9092ea8d9a6c | 190 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 191 | */ |
manujose | 0:9092ea8d9a6c | 192 | #define PT_WAIT_THREAD(pt, thread) PT_WAIT_WHILE((pt), PT_SCHEDULE(thread)) |
manujose | 0:9092ea8d9a6c | 193 | |
manujose | 0:9092ea8d9a6c | 194 | /** |
manujose | 0:9092ea8d9a6c | 195 | * Spawn a child protothread and wait until it exits. |
manujose | 0:9092ea8d9a6c | 196 | * |
manujose | 0:9092ea8d9a6c | 197 | * This macro spawns a child protothread and waits until it exits. The |
manujose | 0:9092ea8d9a6c | 198 | * macro can only be used within a protothread. |
manujose | 0:9092ea8d9a6c | 199 | * |
manujose | 0:9092ea8d9a6c | 200 | * \param pt A pointer to the protothread control structure. |
manujose | 0:9092ea8d9a6c | 201 | * \param child A pointer to the child protothread's control structure. |
manujose | 0:9092ea8d9a6c | 202 | * \param thread The child protothread with arguments |
manujose | 0:9092ea8d9a6c | 203 | * |
manujose | 0:9092ea8d9a6c | 204 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 205 | */ |
manujose | 0:9092ea8d9a6c | 206 | #define PT_SPAWN(pt, child, thread) \ |
manujose | 0:9092ea8d9a6c | 207 | do { \ |
manujose | 0:9092ea8d9a6c | 208 | PT_INIT((child)); \ |
manujose | 0:9092ea8d9a6c | 209 | PT_WAIT_THREAD((pt), (thread)); \ |
manujose | 0:9092ea8d9a6c | 210 | } while(0) |
manujose | 0:9092ea8d9a6c | 211 | |
manujose | 0:9092ea8d9a6c | 212 | /** @} */ |
manujose | 0:9092ea8d9a6c | 213 | |
manujose | 0:9092ea8d9a6c | 214 | /** |
manujose | 0:9092ea8d9a6c | 215 | * \name Exiting and restarting |
manujose | 0:9092ea8d9a6c | 216 | * @{ |
manujose | 0:9092ea8d9a6c | 217 | */ |
manujose | 0:9092ea8d9a6c | 218 | |
manujose | 0:9092ea8d9a6c | 219 | /** |
manujose | 0:9092ea8d9a6c | 220 | * Restart the protothread. |
manujose | 0:9092ea8d9a6c | 221 | * |
manujose | 0:9092ea8d9a6c | 222 | * This macro will block and cause the running protothread to restart |
manujose | 0:9092ea8d9a6c | 223 | * its execution at the place of the PT_BEGIN() call. |
manujose | 0:9092ea8d9a6c | 224 | * |
manujose | 0:9092ea8d9a6c | 225 | * \param pt A pointer to the protothread control structure. |
manujose | 0:9092ea8d9a6c | 226 | * |
manujose | 0:9092ea8d9a6c | 227 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 228 | */ |
manujose | 0:9092ea8d9a6c | 229 | #define PT_RESTART(pt) \ |
manujose | 0:9092ea8d9a6c | 230 | do { \ |
manujose | 0:9092ea8d9a6c | 231 | PT_INIT(pt); \ |
manujose | 0:9092ea8d9a6c | 232 | return PT_WAITING; \ |
manujose | 0:9092ea8d9a6c | 233 | } while(0) |
manujose | 0:9092ea8d9a6c | 234 | |
manujose | 0:9092ea8d9a6c | 235 | /** |
manujose | 0:9092ea8d9a6c | 236 | * Exit the protothread. |
manujose | 0:9092ea8d9a6c | 237 | * |
manujose | 0:9092ea8d9a6c | 238 | * This macro causes the protothread to exit. If the protothread was |
manujose | 0:9092ea8d9a6c | 239 | * spawned by another protothread, the parent protothread will become |
manujose | 0:9092ea8d9a6c | 240 | * unblocked and can continue to run. |
manujose | 0:9092ea8d9a6c | 241 | * |
manujose | 0:9092ea8d9a6c | 242 | * \param pt A pointer to the protothread control structure. |
manujose | 0:9092ea8d9a6c | 243 | * |
manujose | 0:9092ea8d9a6c | 244 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 245 | */ |
manujose | 0:9092ea8d9a6c | 246 | #define PT_EXIT(pt) \ |
manujose | 0:9092ea8d9a6c | 247 | do { \ |
manujose | 0:9092ea8d9a6c | 248 | PT_INIT(pt); \ |
manujose | 0:9092ea8d9a6c | 249 | return PT_EXITED; \ |
manujose | 0:9092ea8d9a6c | 250 | } while(0) |
manujose | 0:9092ea8d9a6c | 251 | |
manujose | 0:9092ea8d9a6c | 252 | /** @} */ |
manujose | 0:9092ea8d9a6c | 253 | |
manujose | 0:9092ea8d9a6c | 254 | /** |
manujose | 0:9092ea8d9a6c | 255 | * \name Calling a protothread |
manujose | 0:9092ea8d9a6c | 256 | * @{ |
manujose | 0:9092ea8d9a6c | 257 | */ |
manujose | 0:9092ea8d9a6c | 258 | |
manujose | 0:9092ea8d9a6c | 259 | /** |
manujose | 0:9092ea8d9a6c | 260 | * Schedule a protothread. |
manujose | 0:9092ea8d9a6c | 261 | * |
manujose | 0:9092ea8d9a6c | 262 | * This function shedules a protothread. The return value of the |
manujose | 0:9092ea8d9a6c | 263 | * function is non-zero if the protothread is running or zero if the |
manujose | 0:9092ea8d9a6c | 264 | * protothread has exited. |
manujose | 0:9092ea8d9a6c | 265 | * |
manujose | 0:9092ea8d9a6c | 266 | * \param f The call to the C function implementing the protothread to |
manujose | 0:9092ea8d9a6c | 267 | * be scheduled |
manujose | 0:9092ea8d9a6c | 268 | * |
manujose | 0:9092ea8d9a6c | 269 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 270 | */ |
manujose | 0:9092ea8d9a6c | 271 | #define PT_SCHEDULE(f) ((f) < PT_EXITED) |
manujose | 0:9092ea8d9a6c | 272 | |
manujose | 0:9092ea8d9a6c | 273 | /** @} */ |
manujose | 0:9092ea8d9a6c | 274 | |
manujose | 0:9092ea8d9a6c | 275 | /** |
manujose | 0:9092ea8d9a6c | 276 | * \name Yielding from a protothread |
manujose | 0:9092ea8d9a6c | 277 | * @{ |
manujose | 0:9092ea8d9a6c | 278 | */ |
manujose | 0:9092ea8d9a6c | 279 | |
manujose | 0:9092ea8d9a6c | 280 | /** |
manujose | 0:9092ea8d9a6c | 281 | * Yield from the current protothread. |
manujose | 0:9092ea8d9a6c | 282 | * |
manujose | 0:9092ea8d9a6c | 283 | * This function will yield the protothread, thereby allowing other |
manujose | 0:9092ea8d9a6c | 284 | * processing to take place in the system. |
manujose | 0:9092ea8d9a6c | 285 | * |
manujose | 0:9092ea8d9a6c | 286 | * \param pt A pointer to the protothread control structure. |
manujose | 0:9092ea8d9a6c | 287 | * |
manujose | 0:9092ea8d9a6c | 288 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 289 | */ |
manujose | 0:9092ea8d9a6c | 290 | #define PT_YIELD(pt) \ |
manujose | 0:9092ea8d9a6c | 291 | do { \ |
manujose | 0:9092ea8d9a6c | 292 | PT_YIELD_FLAG = 0; \ |
manujose | 0:9092ea8d9a6c | 293 | LC_SET((pt)->lc); \ |
manujose | 0:9092ea8d9a6c | 294 | if(PT_YIELD_FLAG == 0) { \ |
manujose | 0:9092ea8d9a6c | 295 | return PT_YIELDED; \ |
manujose | 0:9092ea8d9a6c | 296 | } \ |
manujose | 0:9092ea8d9a6c | 297 | } while(0) |
manujose | 0:9092ea8d9a6c | 298 | |
manujose | 0:9092ea8d9a6c | 299 | /** |
manujose | 0:9092ea8d9a6c | 300 | * \brief Yield from the protothread until a condition occurs. |
manujose | 0:9092ea8d9a6c | 301 | * \param pt A pointer to the protothread control structure. |
manujose | 0:9092ea8d9a6c | 302 | * \param cond The condition. |
manujose | 0:9092ea8d9a6c | 303 | * |
manujose | 0:9092ea8d9a6c | 304 | * This function will yield the protothread, until the |
manujose | 0:9092ea8d9a6c | 305 | * specified condition evaluates to true. |
manujose | 0:9092ea8d9a6c | 306 | * |
manujose | 0:9092ea8d9a6c | 307 | * |
manujose | 0:9092ea8d9a6c | 308 | * \hideinitializer |
manujose | 0:9092ea8d9a6c | 309 | */ |
manujose | 0:9092ea8d9a6c | 310 | #define PT_YIELD_UNTIL(pt, cond) \ |
manujose | 0:9092ea8d9a6c | 311 | do { \ |
manujose | 0:9092ea8d9a6c | 312 | PT_YIELD_FLAG = 0; \ |
manujose | 0:9092ea8d9a6c | 313 | LC_SET((pt)->lc); \ |
manujose | 0:9092ea8d9a6c | 314 | if((PT_YIELD_FLAG == 0) || !(cond)) { \ |
manujose | 0:9092ea8d9a6c | 315 | return PT_YIELDED; \ |
manujose | 0:9092ea8d9a6c | 316 | } \ |
manujose | 0:9092ea8d9a6c | 317 | } while(0) |
manujose | 0:9092ea8d9a6c | 318 | |
manujose | 0:9092ea8d9a6c | 319 | /** @} */ |
manujose | 0:9092ea8d9a6c | 320 | |
manujose | 0:9092ea8d9a6c | 321 | #endif /* __PT_H__ */ |
manujose | 0:9092ea8d9a6c | 322 | |
manujose | 0:9092ea8d9a6c | 323 | /** @} */ |