1 /*---------------------------------------------------------------------------*
2   Project:  OS Mutex API
3   File:     OSMutex.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 __OSMUTEX_H__
16 #define __OSMUTEX_H__
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include <cafe/os/OSThread.h>
23 
24 #define OSMUTEX_TXT_TAG 0x6D557458
25 #define OSCOND_TXT_TAG 0x634E6456
26 
27 struct OSMutex
28 {
29     u32             txtTag;         // 'mUtX' 0x6D557458
30     char *          name;           // debug name or NULL
31     u32             os_reserved1;
32 
33     OSThreadQueue   queue;
34     OSThread*       thread; // the current owner
35     s32             count;  // lock count
36     OSMutexLink     link;   // for OSThread.queueMutex
37 };
38 
39 struct OSCond
40 {
41     u32             txtTag;         // 'cNdV' 0x634E6456
42     char *          name;           // debug name or NULL
43     u32             os_reserved1;
44 
45     OSThreadQueue   queue;
46 };
47 
48 void OSInitMutex   ( OSMutex* mutex );
49 void OSInitMutexEx ( OSMutex* mutex, char * name );
50 void OSLockMutex   ( OSMutex* mutex );
51 void OSUnlockMutex ( OSMutex* mutex );
52 BOOL OSTryLockMutex( OSMutex* mutex );
53 
54 void OSInitCond    ( OSCond* cond );
55 void OSInitCondEx  ( OSCond* cond, char * name );
56 void OSWaitCond    ( OSCond* cond, OSMutex* mutex );
57 void OSSignalCond  ( OSCond* cond );
58 
59 #ifdef __cplusplus
60 }
61 #endif
62 
63 #endif  // __OSMUTEX_H__
64 
65