1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: os_LightEvent.h 4 5 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev: 12449 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_OS_OS_LIGHTEVENT_H_ 17 #define NN_OS_OS_LIGHTEVENT_H_ 18 19 #ifdef __cplusplus 20 21 #include <nn/os/os_WaitableCounter.h> 22 #include <nn/assert.h> 23 #include <nn/WithInitialize.h> 24 #include <nn/util/detail/util_ScopedLockImpl.h> 25 26 namespace nn { namespace os { 27 28 /* Please see man pages for details 29 30 31 32 33 */ 34 35 /* 36 37 38 39 40 41 42 43 44 45 46 47 */ 48 class LightEvent 49 { 50 private: 51 static const s32 SIGNALED_MANUAL = 1; 52 static const s32 SIGNALED_AUTO = 0; 53 static const s32 NOT_SIGNALED_AUTO = -1; 54 static const s32 NOT_SIGNALED_MANUAL = -2; 55 56 private: 57 WaitableCounter m_Counter; 58 59 public: 60 //---------------------------------------- 61 // 62 // 63 64 /* 65 66 67 68 69 70 71 72 73 */ LightEvent()74 LightEvent(){} 75 76 /* 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 */ LightEvent(bool isManualReset)99 LightEvent(bool isManualReset) 100 { 101 Initialize(isManualReset); 102 } 103 104 /* 105 106 107 108 109 110 111 112 */ Initialize(bool isManualReset)113 void Initialize(bool isManualReset) 114 { 115 *m_Counter = isManualReset ? NOT_SIGNALED_MANUAL: NOT_SIGNALED_AUTO; 116 } 117 118 /* 119 120 121 122 123 */ Finalize()124 void Finalize() {} 125 126 // 127 128 //---------------------------------------- 129 // 130 // 131 132 /* 133 134 135 136 137 138 139 140 141 142 143 144 145 */ IsSignaled()146 bool IsSignaled() const { return *m_Counter >= 0; } 147 148 /* 149 150 151 152 153 154 */ IsManualReset()155 bool IsManualReset() const 156 { 157 const s32 c = *m_Counter; 158 return (c == SIGNALED_MANUAL) || (c == NOT_SIGNALED_MANUAL); 159 } 160 161 // 162 163 //---------------------------------------- 164 // 165 // 166 167 /* 168 169 170 171 172 173 174 175 176 */ 177 bool TryWait(); 178 179 /* 180 181 182 183 184 185 186 187 */ 188 void Wait(); 189 190 /* 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 */ 210 void Signal(); 211 212 /* 213 214 215 216 217 218 219 220 221 222 223 224 225 226 */ 227 void Pulse(); 228 229 /* 230 231 232 233 234 */ 235 void ClearSignal(); 236 237 // 238 }; 239 240 241 }} // namespace nn::os 242 243 #endif // __cplusplus 244 245 // C declarations follow 246 247 #include <nn/util/detail/util_CLibImpl.h> 248 249 /* Please see man pages for details 250 251 252 253 254 255 256 257 258 */ 259 260 /* Please see man pages for details 261 262 263 264 */ 265 NN_UTIL_DETAIL_CLIBIMPL_DEFINE_BUFFER_CLASS(nnosLightEvent, nn::os::LightEvent, 4, u32); 266 267 /* Please see man pages for details 268 269 */ 270 NN_EXTERN_C void nnosLightEventInitialize(nnosLightEvent* this_, bool isManualReset); 271 272 /* Please see man pages for details 273 274 */ 275 NN_EXTERN_C bool nnosLightEventIsSignaled(nnosLightEvent* this_); 276 277 /* Please see man pages for details 278 279 */ 280 NN_EXTERN_C bool nnosLightEventIsManualReset(nnosLightEvent* this_); 281 282 /* Please see man pages for details 283 284 */ 285 NN_EXTERN_C bool nnosLightEventTryWait(nnosLightEvent* this_); 286 287 /* Please see man pages for details 288 289 */ 290 NN_EXTERN_C void nnosLightEventWait(nnosLightEvent* this_); 291 292 /* Please see man pages for details 293 294 */ 295 NN_EXTERN_C void nnosLightEventSignal(nnosLightEvent* this_); 296 297 /* Please see man pages for details 298 299 */ 300 NN_EXTERN_C void nnosLightEventPulse(nnosLightEvent* this_); 301 302 /* Please see man pages for details 303 304 */ 305 NN_EXTERN_C void nnosLightEventClearSignal(nnosLightEvent* this_); 306 307 /* Please see man pages for details 308 309 */ 310 NN_EXTERN_C void nnosLightEventFinalize(nnosLightEvent* this_); 311 312 /* 313 314 315 316 */ 317 318 319 320 #endif // ifndef NN_OS_OS_LIGHTEVENT_H_ 321