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