Qingtao Li / Mbed 2 deprecated Protothread

Dependencies:   mbed

Committer:
liqingtaobkd
Date:
Wed Dec 01 01:02:23 2010 +0000
Revision:
0:4985e86d0bfa

        

Who changed what in which revision?

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