atom.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00034 /*
00035  * $Log$
00036  * Revision 1.2  2008/08/11 06:59:39  haraldkipp
00037  * BSD types replaced by stdint types (feature request #1282721).
00038  *
00039  * Revision 1.1  2005/05/27 17:41:52  drsung
00040  * Moved the file.
00041  *
00042  * Revision 1.1  2005/05/26 10:08:42  drsung
00043  * Moved the platform dependend code from include/sys/atom.h to this file.
00044  *
00045  *
00046  */
00047 
00048 #ifndef _SYS_ATOM_H_
00049 #error "Do not include this file directly. Use sys/atom.h instead!"
00050 #endif
00051 
00052 __BEGIN_DECLS
00053 #include <pthread.h>
00054 #include <signal.h>
00055 #include <sys/thread.h>
00056 #include <stdio.h>
00057 #include <stdlib.h>
00058 #include <stdint.h>
00059 extern uint16_t main_cs_level;
00060 extern sigset_t irq_signal;
00061 
00062 extern FILE *__os_trs;
00063 extern uint8_t __os_trf;
00064 
00065 #define AtomicInc(p)     (++(*p))
00066 #define AtomicDec(p)     (--(*p))
00067 
00068 #define NutEnterCritical()                       \
00069         pthread_sigmask(SIG_BLOCK, &irq_signal, 0);  \
00070         if (runningThread){                      \
00071             /* if (runningThread->td_cs_level==0)                                                   \
00072                 printf("Entered a: %s.%d - %s\n", __FILE__, __LINE__, runningThread->td_name); */   \
00073             runningThread->td_cs_level++;        \
00074         } else {                                 \
00075             /* if (main_cs_level==0)                                                \
00076                 printf("Entered b: %s.%d - %s\n", __FILE__, __LINE__, "ROOT") */;   \
00077             main_cs_level++;                     \
00078         }                                        \
00079 
00080 #define NutExitCritical()                                   \
00081         if (runningThread){                                 \
00082             if (--runningThread->td_cs_level == 0) {        \
00083                 /* printf("Left a: %s.%d - %s\n", __FILE__, __LINE__, runningThread->td_name);  */ \
00084                 pthread_sigmask(SIG_UNBLOCK, &irq_signal, 0);   \
00085             }                                               \
00086         } else {                                            \
00087             if (--main_cs_level == 0) {                     \
00088                 /* printf("Left a: %s.%d - %s\n", __FILE__, __LINE__, "ROOT");  */ \
00089                 pthread_sigmask(SIG_UNBLOCK, &irq_signal, 0);   \
00090             }                                               \
00091         }
00092 
00093 #if 0
00094 
00095 #define NutEnterCritical()                       \
00096         if (runningThread){                      \
00097             if (runningThread->td_cs_level==0)                                              \
00098                 printf("Entered a: %s.%d - %s\n", __FILE__, __LINE__, runningThread->td_name);  \
00099             runningThread->td_cs_level++;        \
00100         } else {                                 \
00101             if (main_cs_level==0)                                               \
00102                 printf("Entered b: %s.%d - %s\n", __FILE__, __LINE__, "ROOT");  \
00103             main_cs_level++;                     \
00104         }                                        \
00105 
00106 #define NutExitCritical()                                   \
00107         if (runningThread){                                 \
00108             if (--runningThread->td_cs_level == 0) {        \
00109                 printf("Left a: %s.%d - %s\n", __FILE__, __LINE__, runningThread->td_name); \
00110             }                                               \
00111         } else {                                            \
00112             if (--main_cs_level == 0) {                     \
00113                 printf("Left a: %s.%d - %s\n", __FILE__, __LINE__, "ROOT"); \
00114             }                                               \
00115         }
00116 #endif
00117 
00118 #define NutJumpOutCritical() NutExitCritical()
00119 
00120 __END_DECLS

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/