ISIX-RTOS - small operating system for ARM microcontrollers 1.2

semaphore.h

Go to the documentation of this file.
00001 #ifndef _ISIX_SEMAPHORE_H
00002 #define _ISIX_SEMAPHORE_H
00003 
00004 #include <isix/config.h>
00005 #include <isix/types.h>
00006 
00007 /*--------------------------------------------------------------*/
00008 #ifdef __cplusplus
00009 extern "C" {
00010 namespace isix {
00011 #endif /*__cplusplus*/
00012 /*--------------------------------------------------------------*/
00013 
00014 struct sem_struct;
00015 typedef struct sem_struct sem_t;
00016 /*--------------------------------------------------------------*/
00017 #ifdef __cplusplus
00018 static const unsigned ISIX_TIME_INFINITE = 0;
00019 static const unsigned ISIX_SEM_ULIMITED = 0;
00020 #else
00021 #define ISIX_TIME_INFINITE (0)
00022 #define ISIX_SEM_ULIMITED (0)
00023 #endif /*__cplusplus*/
00024 /*--------------------------------------------------------------*/
00031 sem_t* isix_sem_create_limited(sem_t *sem,int val, int limit_val);
00032 
00033 /*--------------------------------------------------------------*/
00039 static inline sem_t* isix_sem_create(sem_t *sem,int val)
00040 {
00041         return isix_sem_create_limited( sem, val, ISIX_SEM_ULIMITED );
00042 }
00043 
00044 /*--------------------------------------------------------------*/
00050 int isix_sem_wait(sem_t *sem, tick_t timeout);
00051 
00052 /*--------------------------------------------------------------*/
00057 int isix_sem_get_isr(sem_t *sem);
00058 
00059 /*--------------------------------------------------------------*/
00065 int isixp_sem_signal(sem_t *sem, bool isr);
00066 
00067 /*--------------------------------------------------------------*/
00072 static inline int isix_sem_signal(sem_t *sem)
00073 {
00074         return isixp_sem_signal( sem, false );
00075 }
00076 
00077 /*--------------------------------------------------------------*/
00082 static inline int isix_sem_signal_isr(sem_t *sem)
00083 {
00084         return isixp_sem_signal(sem,true);
00085 }
00086 
00087 /*--------------------------------------------------------------*/
00093 int isix_sem_setval(sem_t *sem,int val);
00094 
00095 /*--------------------------------------------------------------*/
00100 int isix_sem_getval(sem_t *sem);
00101 
00102 /*--------------------------------------------------------------*/
00107 int isix_sem_destroy(sem_t *sem);
00108 
00109 /*--------------------------------------------------------------*/
00114 tick_t isix_ms2tick(unsigned long ms);
00115 
00116 /*--------------------------------------------------------------*/
00117 
00122 int isix_wait(tick_t timeout);
00123 
00124 /*-----------------------------------------------------------*/
00129 static inline int isix_wait_ms(unsigned long ms)
00130 {
00131         return isix_wait(isix_ms2tick(ms));
00132 }
00133 
00134 /*-----------------------------------------------------------*/
00135 
00136 #ifdef __cplusplus
00137 }       //end namespace
00138 }       //end extern-C
00139 #endif /* __cplusplus */
00140 
00141 /*-----------------------------------------------------------*/
00142 //****************************** C++ API ***********************************
00143 #ifdef __cplusplus
00144 #include <cstddef>
00145 namespace isix {
00146 /*--------------------------------------------------------------*/
00147 #ifdef ISIX_CONFIG_USE_MULTIOBJECTS
00148 union ihandle;
00149 #endif
00150 
00151 /*--------------------------------------------------------------*/
00153 class semaphore
00154 {
00155 #ifdef ISIX_CONFIG_USE_MULTIOBJECTS
00156         friend union ihandle;
00157 #endif
00158 public:
00162         explicit semaphore( int val, int limit_val=ISIX_SEM_ULIMITED )
00163         {
00164                 sem = isix_sem_create_limited( NULL, val, limit_val );
00165         }
00167         ~semaphore()
00168         {
00169                 isix_sem_destroy(sem);
00170         }
00174         bool is_valid() { return sem!=0; }
00178         int wait(tick_t timeout)
00179         {
00180                 return isix_sem_wait( sem, timeout );
00181         }
00185         int get_isr()
00186         {
00187                 return isix_sem_get_isr(sem);
00188         }
00192         int signal()
00193         {
00194                 return isix_sem_signal(sem);
00195         }
00199         int signal_isr()
00200         {
00201                 return isix_sem_signal_isr(sem);
00202         }
00207         int setval(int val)
00208         {
00209                 return isix_sem_setval( sem, val );
00210         }
00214         int getval()
00215         {
00216                 return isix_sem_getval( sem );
00217         }
00218 private:
00219         semaphore(const semaphore&);
00220         semaphore& operator=(const semaphore&);
00221 private:
00222         sem_t *sem;
00223 };
00224 
00225 
00226 /*--------------------------------------------------------------*/
00227 }
00228 #endif /* __cplusplus */
00229 
00230 /*-----------------------------------------------------------*/
00231 #endif /* __ISIX_SEMAPHORE_H */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines