Tianji Wu
/
hw2_pt
HW2 implemented using protothread
lc-switch.h@0:e2cc8ae74a24, 2010-12-01 (annotated)
- Committer:
- the729
- Date:
- Wed Dec 01 02:53:56 2010 +0000
- Revision:
- 0:e2cc8ae74a24
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
the729 | 0:e2cc8ae74a24 | 1 | /* |
the729 | 0:e2cc8ae74a24 | 2 | * Copyright (c) 2004-2005, Swedish Institute of Computer Science. |
the729 | 0:e2cc8ae74a24 | 3 | * All rights reserved. |
the729 | 0:e2cc8ae74a24 | 4 | * |
the729 | 0:e2cc8ae74a24 | 5 | * Redistribution and use in source and binary forms, with or without |
the729 | 0:e2cc8ae74a24 | 6 | * modification, are permitted provided that the following conditions |
the729 | 0:e2cc8ae74a24 | 7 | * are met: |
the729 | 0:e2cc8ae74a24 | 8 | * 1. Redistributions of source code must retain the above copyright |
the729 | 0:e2cc8ae74a24 | 9 | * notice, this list of conditions and the following disclaimer. |
the729 | 0:e2cc8ae74a24 | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
the729 | 0:e2cc8ae74a24 | 11 | * notice, this list of conditions and the following disclaimer in the |
the729 | 0:e2cc8ae74a24 | 12 | * documentation and/or other materials provided with the distribution. |
the729 | 0:e2cc8ae74a24 | 13 | * 3. Neither the name of the Institute nor the names of its contributors |
the729 | 0:e2cc8ae74a24 | 14 | * may be used to endorse or promote products derived from this software |
the729 | 0:e2cc8ae74a24 | 15 | * without specific prior written permission. |
the729 | 0:e2cc8ae74a24 | 16 | * |
the729 | 0:e2cc8ae74a24 | 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
the729 | 0:e2cc8ae74a24 | 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
the729 | 0:e2cc8ae74a24 | 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
the729 | 0:e2cc8ae74a24 | 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
the729 | 0:e2cc8ae74a24 | 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
the729 | 0:e2cc8ae74a24 | 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
the729 | 0:e2cc8ae74a24 | 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
the729 | 0:e2cc8ae74a24 | 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
the729 | 0:e2cc8ae74a24 | 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
the729 | 0:e2cc8ae74a24 | 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
the729 | 0:e2cc8ae74a24 | 27 | * SUCH DAMAGE. |
the729 | 0:e2cc8ae74a24 | 28 | * |
the729 | 0:e2cc8ae74a24 | 29 | * This file is part of the Contiki operating system. |
the729 | 0:e2cc8ae74a24 | 30 | * |
the729 | 0:e2cc8ae74a24 | 31 | * Author: Adam Dunkels <adam@sics.se> |
the729 | 0:e2cc8ae74a24 | 32 | * |
the729 | 0:e2cc8ae74a24 | 33 | * $Id: lc-switch.h,v 1.4 2006/06/03 11:29:43 adam Exp $ |
the729 | 0:e2cc8ae74a24 | 34 | */ |
the729 | 0:e2cc8ae74a24 | 35 | |
the729 | 0:e2cc8ae74a24 | 36 | /** |
the729 | 0:e2cc8ae74a24 | 37 | * \addtogroup lc |
the729 | 0:e2cc8ae74a24 | 38 | * @{ |
the729 | 0:e2cc8ae74a24 | 39 | */ |
the729 | 0:e2cc8ae74a24 | 40 | |
the729 | 0:e2cc8ae74a24 | 41 | /** |
the729 | 0:e2cc8ae74a24 | 42 | * \file |
the729 | 0:e2cc8ae74a24 | 43 | * Implementation of local continuations based on switch() statment |
the729 | 0:e2cc8ae74a24 | 44 | * \author Adam Dunkels <adam@sics.se> |
the729 | 0:e2cc8ae74a24 | 45 | * |
the729 | 0:e2cc8ae74a24 | 46 | * This implementation of local continuations uses the C switch() |
the729 | 0:e2cc8ae74a24 | 47 | * statement to resume execution of a function somewhere inside the |
the729 | 0:e2cc8ae74a24 | 48 | * function's body. The implementation is based on the fact that |
the729 | 0:e2cc8ae74a24 | 49 | * switch() statements are able to jump directly into the bodies of |
the729 | 0:e2cc8ae74a24 | 50 | * control structures such as if() or while() statmenets. |
the729 | 0:e2cc8ae74a24 | 51 | * |
the729 | 0:e2cc8ae74a24 | 52 | * This implementation borrows heavily from Simon Tatham's coroutines |
the729 | 0:e2cc8ae74a24 | 53 | * implementation in C: |
the729 | 0:e2cc8ae74a24 | 54 | * http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html |
the729 | 0:e2cc8ae74a24 | 55 | */ |
the729 | 0:e2cc8ae74a24 | 56 | |
the729 | 0:e2cc8ae74a24 | 57 | #ifndef __LC_SWITCH_H__ |
the729 | 0:e2cc8ae74a24 | 58 | #define __LC_SWITCH_H__ |
the729 | 0:e2cc8ae74a24 | 59 | |
the729 | 0:e2cc8ae74a24 | 60 | /* WARNING! lc implementation using switch() does not work if an |
the729 | 0:e2cc8ae74a24 | 61 | LC_SET() is done within another switch() statement! */ |
the729 | 0:e2cc8ae74a24 | 62 | |
the729 | 0:e2cc8ae74a24 | 63 | /** \hideinitializer */ |
the729 | 0:e2cc8ae74a24 | 64 | typedef unsigned short lc_t; |
the729 | 0:e2cc8ae74a24 | 65 | |
the729 | 0:e2cc8ae74a24 | 66 | #define LC_INIT(s) s = 0; |
the729 | 0:e2cc8ae74a24 | 67 | |
the729 | 0:e2cc8ae74a24 | 68 | #define LC_RESUME(s) switch(s) { case 0: |
the729 | 0:e2cc8ae74a24 | 69 | |
the729 | 0:e2cc8ae74a24 | 70 | #define LC_SET(s) s = __LINE__; case __LINE__: |
the729 | 0:e2cc8ae74a24 | 71 | |
the729 | 0:e2cc8ae74a24 | 72 | #define LC_END(s) } |
the729 | 0:e2cc8ae74a24 | 73 | |
the729 | 0:e2cc8ae74a24 | 74 | #endif /* __LC_SWITCH_H__ */ |
the729 | 0:e2cc8ae74a24 | 75 | |
the729 | 0:e2cc8ae74a24 | 76 | /** @} */ |