1 /*---------------------------------------------------------------------------* 2 Project: OS Mutex API 3 File: OSFastMutex.h 4 5 Copyright 1998-2011 Nintendo. 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 *---------------------------------------------------------------------------*/ 14 15 #ifndef __OSFASTMUTEX_H__ 16 #define __OSFASTMUTEX_H__ 17 18 #define OSFASTMUTEX_OFFSET_OWNEDLINKNEXT 20 19 #define OSFASTMUTEX_OFFSET_OWNEDLINKPREV 24 20 #define OSFASTMUTEX_OFFSET_LOCK 28 21 #define OSFASTMUTEX_OFFSET_LOCKCOUNT 32 22 #define OSFASTMUTEX_OFFSET_CONTENDEDLINKNEXT 36 23 #define OSFASTMUTEX_OFFSET_CONTENDEDLINKPREV 40 24 25 #define OSTHREAD_OFFSET_CANCELSTATE 1492 26 #define OSTHREAD_OFFSET_REQUESTFLAG 1496 27 #define OSTHREAD_OFFSET_CONTENDEDFASTMUTEXES 1648 28 #define OSTHREAD_OFFSET_OWNEDFASTMUTEXES 1656 29 30 #define OSFASTMUTEXQ_OFFSET_HEAD 0 31 #define OSFASTMUTEXQ_OFFSET_TAIL 4 32 33 34 #ifndef _ASSEMBLER 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #include <cafe/os/OSThread.h> 40 41 #define OSFASTMUTEX_TXT_TAG 0x664D7458 42 #define OSFASTCOND_TXT_TAG 0x664E6456 43 44 #define OSFASTMUTEX_EMPTY 0 45 #define OSFASTMUTEX_WBIT 0x00000001 46 #define OSFASTMUTEX_THREAD(__fastMutex__) ((OSThread *)(__fastMutex__->lock & ~OSFASTMUTEX_WBIT)) 47 #define OSFASTMUTEX_LOCK(__lock__) ((OSThread *)(__lock__ & ~OSFASTMUTEX_WBIT)) 48 49 50 struct OSFastMutex 51 { 52 u32 txtTag; // +0 'fMtX' 0x664D7458 53 char * name; // +4 debug name or NULL 54 BOOL in_contended_queue; // +8 55 56 OSThreadSmallQueue contendedQueue; // +12 queue of threads waiting on this fastmutex 57 OSFastMutexLink ownedLink; // +20 updated by owner-thread only, list of fastmutxes held 58 u32 lock; // +28 the current owner thread & waiters (low) bit 59 s32 lockCount; // +32 per-thread lock count 60 OSFastMutexLink contendedLink; // +36 updated underneath scheduler lock by contended thread(s) 61 }; 62 63 struct OSFastCond 64 { 65 u32 txtTag; // 'fNdV' 0x664E6456 66 char * name; // debug name or NULL 67 u32 os_reserved1; 68 69 OSThreadQueue queue; 70 }; 71 72 void OSFastMutex_Init ( OSFastMutex * fastMutex, char * name ); 73 void OSFastMutex_Lock ( OSFastMutex * fastMutex ); 74 void OSFastMutex_Unlock ( OSFastMutex * fastMutex ); 75 BOOL OSFastMutex_TryLock( OSFastMutex * fastMutex ); 76 77 void OSFastCond_Init ( OSFastCond * fastCond, char * name ); 78 void OSFastCond_Wait ( OSFastCond * fastCond, OSFastMutex * fastMutex ); 79 void OSFastCond_Signal( OSFastCond * fastCond ); 80 81 #ifdef __cplusplus 82 } 83 #endif 84 #endif // _ASSEMBLER 85 86 #endif // __OSFASTMUTEX_H__ 87 88 89