don't do a DVD_Mount for GC-mode on Wii, add ifdef for Wii-only SMB code
[libogc.git] / libogc / malloc_lock.c
blob5086ce32373276bcf2f24b5929ba0c6a1edbd85c
1 #include <_ansi.h>
2 #include <_syslist.h>
3 #ifndef REENTRANT_SYSCALLS_PROVIDED
4 #include <reent.h>
5 #endif
6 #include <errno.h>
7 #undef errno
8 extern int errno;
10 #include "asm.h"
11 #include "processor.h"
12 #include "lwp_mutex.h"
14 #define MEMLOCK_MUTEX_ID 0x00030040
16 static int initialized = 0;
17 static lwp_mutex mem_lock;
19 void __memlock_init()
21 __lwp_thread_dispatchdisable();
22 if(!initialized) {
23 lwp_mutex_attr attr;
25 initialized = 1;
27 attr.mode = LWP_MUTEX_FIFO;
28 attr.nest_behavior = LWP_MUTEX_NEST_ACQUIRE;
29 attr.onlyownerrelease = TRUE;
30 attr.prioceil = 1;
31 __lwp_mutex_initialize(&mem_lock,&attr,LWP_MUTEX_UNLOCKED);
33 __lwp_thread_dispatchunnest();
36 #ifndef REENTRANT_SYSCALLS_PROVIDED
37 void _DEFUN(__libogc_malloc_lock,(r),
38 struct _reent *r)
40 unsigned int level;
42 if(!initialized) return;
44 _CPU_ISR_Disable(level);
45 __lwp_mutex_seize(&mem_lock,MEMLOCK_MUTEX_ID,TRUE,LWP_THREADQ_NOTIMEOUT,level);
48 void _DEFUN(__libogc_malloc_unlock,(r),
49 struct _reent *r)
51 if(!initialized) return;
53 __lwp_thread_dispatchdisable();
54 __lwp_mutex_surrender(&mem_lock);
55 __lwp_thread_dispatchenable();
58 #else
59 void _DEFUN(__libogc_malloc_lock,(ptr),
60 struct _reent *ptr)
62 unsigned int level;
64 if(!initialized) return;
66 _CPU_ISR_Disable(level);
67 __lwp_mutex_seize(&mem_lock,MEMLOCK_MUTEX_ID,TRUE,LWP_THREADQ_NOTIMEOUT,level);
68 ptr->_errno = _thr_executing->wait.ret_code;
71 void _DEFUN(__libogc_malloc_unlock,(ptr),
72 struct _reent *ptr)
74 if(!initialized) return;
76 __lwp_thread_dispatchdisable();
77 ptr->_errno = __lwp_mutex_surrender(&mem_lock);
78 __lwp_thread_dispatchenable();
81 #endif