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