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