Unify Framework Lib 1.6.0
pt.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 * Author: Adam Dunkels <adam@sics.se>
32 *
33 * $Id: pt.h,v 1.3 2008/10/14 12:46:39 nvt-se Exp $
34 */
35
49#ifndef __PT_H__
50#define __PT_H__
51
52#include "sys/lc.h"
53
54struct pt {
56};
57
58#define PT_WAITING 0
59#define PT_YIELDED 1
60#define PT_EXITED 2
61#define PT_ENDED 3
62
80#define PT_INIT(pt) LC_INIT((pt)->lc)
81
100#define PT_THREAD(name_args) char name_args CC_REENTRANT_ARG
101
115#define PT_BEGIN(pt) { char PT_YIELD_FLAG = 1; LC_RESUME((pt)->lc)
116
127#define PT_END(pt) LC_END((pt)->lc); PT_YIELD_FLAG = 0; \
128 PT_INIT(pt); return PT_ENDED; }
129
148#define PT_WAIT_UNTIL(pt, condition) \
149 do { \
150 LC_SET((pt)->lc); \
151 if(!(condition)) { \
152 return PT_WAITING; \
153 } \
154 } while(0)
155
167#define PT_WAIT_WHILE(pt, cond) PT_WAIT_UNTIL((pt), !(cond))
168
192#define PT_WAIT_THREAD(pt, thread) PT_WAIT_WHILE((pt), PT_SCHEDULE(thread))
193
206#define PT_SPAWN(pt, child, thread) \
207 do { \
208 PT_INIT((child)); \
209 PT_WAIT_THREAD((pt), (thread)); \
210 } while(0)
211
229#define PT_RESTART(pt) \
230 do { \
231 PT_INIT(pt); \
232 return PT_WAITING; \
233 } while(0)
234
246#define PT_EXIT(pt) \
247 do { \
248 PT_INIT(pt); \
249 return PT_EXITED; \
250 } while(0)
251
271#define PT_SCHEDULE(f) ((f) < PT_EXITED)
272
290#define PT_YIELD(pt) \
291 do { \
292 PT_YIELD_FLAG = 0; \
293 LC_SET((pt)->lc); \
294 if(PT_YIELD_FLAG == 0) { \
295 return PT_YIELDED; \
296 } \
297 } while(0)
298
310#define PT_YIELD_UNTIL(pt, cond) \
311 do { \
312 PT_YIELD_FLAG = 0; \
313 LC_SET((pt)->lc); \
314 if((PT_YIELD_FLAG == 0) || !(cond)) { \
315 return PT_YIELDED; \
316 } \
317 } while(0)
318
321#endif /* __PT_H__ */
322
unsigned short lc_t
Definition: lc-switch.h:67
Definition: pt.h:54
lc_t lc
Definition: pt.h:55