Tianji Wu
/
hw2_pt
HW2 implemented using protothread
lc.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 protothreads library. |
the729 | 0:e2cc8ae74a24 | 30 | * |
the729 | 0:e2cc8ae74a24 | 31 | * Author: Adam Dunkels <adam@sics.se> |
the729 | 0:e2cc8ae74a24 | 32 | * |
the729 | 0:e2cc8ae74a24 | 33 | * $Id: lc.h,v 1.2 2005/02/24 10:36:59 adam Exp $ |
the729 | 0:e2cc8ae74a24 | 34 | */ |
the729 | 0:e2cc8ae74a24 | 35 | |
the729 | 0:e2cc8ae74a24 | 36 | /** |
the729 | 0:e2cc8ae74a24 | 37 | * \addtogroup pt |
the729 | 0:e2cc8ae74a24 | 38 | * @{ |
the729 | 0:e2cc8ae74a24 | 39 | */ |
the729 | 0:e2cc8ae74a24 | 40 | |
the729 | 0:e2cc8ae74a24 | 41 | /** |
the729 | 0:e2cc8ae74a24 | 42 | * \defgroup lc Local continuations |
the729 | 0:e2cc8ae74a24 | 43 | * @{ |
the729 | 0:e2cc8ae74a24 | 44 | * |
the729 | 0:e2cc8ae74a24 | 45 | * Local continuations form the basis for implementing protothreads. A |
the729 | 0:e2cc8ae74a24 | 46 | * local continuation can be <i>set</i> in a specific function to |
the729 | 0:e2cc8ae74a24 | 47 | * capture the state of the function. After a local continuation has |
the729 | 0:e2cc8ae74a24 | 48 | * been set can be <i>resumed</i> in order to restore the state of the |
the729 | 0:e2cc8ae74a24 | 49 | * function at the point where the local continuation was set. |
the729 | 0:e2cc8ae74a24 | 50 | * |
the729 | 0:e2cc8ae74a24 | 51 | * |
the729 | 0:e2cc8ae74a24 | 52 | */ |
the729 | 0:e2cc8ae74a24 | 53 | |
the729 | 0:e2cc8ae74a24 | 54 | /** |
the729 | 0:e2cc8ae74a24 | 55 | * \file lc.h |
the729 | 0:e2cc8ae74a24 | 56 | * Local continuations |
the729 | 0:e2cc8ae74a24 | 57 | * \author |
the729 | 0:e2cc8ae74a24 | 58 | * Adam Dunkels <adam@sics.se> |
the729 | 0:e2cc8ae74a24 | 59 | * |
the729 | 0:e2cc8ae74a24 | 60 | */ |
the729 | 0:e2cc8ae74a24 | 61 | |
the729 | 0:e2cc8ae74a24 | 62 | #ifdef DOXYGEN |
the729 | 0:e2cc8ae74a24 | 63 | /** |
the729 | 0:e2cc8ae74a24 | 64 | * Initialize a local continuation. |
the729 | 0:e2cc8ae74a24 | 65 | * |
the729 | 0:e2cc8ae74a24 | 66 | * This operation initializes the local continuation, thereby |
the729 | 0:e2cc8ae74a24 | 67 | * unsetting any previously set continuation state. |
the729 | 0:e2cc8ae74a24 | 68 | * |
the729 | 0:e2cc8ae74a24 | 69 | * \hideinitializer |
the729 | 0:e2cc8ae74a24 | 70 | */ |
the729 | 0:e2cc8ae74a24 | 71 | #define LC_INIT(lc) |
the729 | 0:e2cc8ae74a24 | 72 | |
the729 | 0:e2cc8ae74a24 | 73 | /** |
the729 | 0:e2cc8ae74a24 | 74 | * Set a local continuation. |
the729 | 0:e2cc8ae74a24 | 75 | * |
the729 | 0:e2cc8ae74a24 | 76 | * The set operation saves the state of the function at the point |
the729 | 0:e2cc8ae74a24 | 77 | * where the operation is executed. As far as the set operation is |
the729 | 0:e2cc8ae74a24 | 78 | * concerned, the state of the function does <b>not</b> include the |
the729 | 0:e2cc8ae74a24 | 79 | * call-stack or local (automatic) variables, but only the program |
the729 | 0:e2cc8ae74a24 | 80 | * counter and such CPU registers that needs to be saved. |
the729 | 0:e2cc8ae74a24 | 81 | * |
the729 | 0:e2cc8ae74a24 | 82 | * \hideinitializer |
the729 | 0:e2cc8ae74a24 | 83 | */ |
the729 | 0:e2cc8ae74a24 | 84 | #define LC_SET(lc) |
the729 | 0:e2cc8ae74a24 | 85 | |
the729 | 0:e2cc8ae74a24 | 86 | /** |
the729 | 0:e2cc8ae74a24 | 87 | * Resume a local continuation. |
the729 | 0:e2cc8ae74a24 | 88 | * |
the729 | 0:e2cc8ae74a24 | 89 | * The resume operation resumes a previously set local continuation, thus |
the729 | 0:e2cc8ae74a24 | 90 | * restoring the state in which the function was when the local |
the729 | 0:e2cc8ae74a24 | 91 | * continuation was set. If the local continuation has not been |
the729 | 0:e2cc8ae74a24 | 92 | * previously set, the resume operation does nothing. |
the729 | 0:e2cc8ae74a24 | 93 | * |
the729 | 0:e2cc8ae74a24 | 94 | * \hideinitializer |
the729 | 0:e2cc8ae74a24 | 95 | */ |
the729 | 0:e2cc8ae74a24 | 96 | #define LC_RESUME(lc) |
the729 | 0:e2cc8ae74a24 | 97 | |
the729 | 0:e2cc8ae74a24 | 98 | /** |
the729 | 0:e2cc8ae74a24 | 99 | * Mark the end of local continuation usage. |
the729 | 0:e2cc8ae74a24 | 100 | * |
the729 | 0:e2cc8ae74a24 | 101 | * The end operation signifies that local continuations should not be |
the729 | 0:e2cc8ae74a24 | 102 | * used any more in the function. This operation is not needed for |
the729 | 0:e2cc8ae74a24 | 103 | * most implementations of local continuation, but is required by a |
the729 | 0:e2cc8ae74a24 | 104 | * few implementations. |
the729 | 0:e2cc8ae74a24 | 105 | * |
the729 | 0:e2cc8ae74a24 | 106 | * \hideinitializer |
the729 | 0:e2cc8ae74a24 | 107 | */ |
the729 | 0:e2cc8ae74a24 | 108 | #define LC_END(lc) |
the729 | 0:e2cc8ae74a24 | 109 | |
the729 | 0:e2cc8ae74a24 | 110 | /** |
the729 | 0:e2cc8ae74a24 | 111 | * \var typedef lc_t; |
the729 | 0:e2cc8ae74a24 | 112 | * |
the729 | 0:e2cc8ae74a24 | 113 | * The local continuation type. |
the729 | 0:e2cc8ae74a24 | 114 | * |
the729 | 0:e2cc8ae74a24 | 115 | * \hideinitializer |
the729 | 0:e2cc8ae74a24 | 116 | */ |
the729 | 0:e2cc8ae74a24 | 117 | #endif /* DOXYGEN */ |
the729 | 0:e2cc8ae74a24 | 118 | |
the729 | 0:e2cc8ae74a24 | 119 | #ifndef __LC_H__ |
the729 | 0:e2cc8ae74a24 | 120 | #define __LC_H__ |
the729 | 0:e2cc8ae74a24 | 121 | |
the729 | 0:e2cc8ae74a24 | 122 | |
the729 | 0:e2cc8ae74a24 | 123 | #ifdef LC_INCLUDE |
the729 | 0:e2cc8ae74a24 | 124 | #include LC_INCLUDE |
the729 | 0:e2cc8ae74a24 | 125 | #else |
the729 | 0:e2cc8ae74a24 | 126 | #include "lc-switch.h" |
the729 | 0:e2cc8ae74a24 | 127 | #endif /* LC_INCLUDE */ |
the729 | 0:e2cc8ae74a24 | 128 | |
the729 | 0:e2cc8ae74a24 | 129 | #endif /* __LC_H__ */ |
the729 | 0:e2cc8ae74a24 | 130 | |
the729 | 0:e2cc8ae74a24 | 131 | /** @} */ |
the729 | 0:e2cc8ae74a24 | 132 | /** @} */ |