3 #ifndef REENTRANT_SYSCALLS_PROVIDED
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
;
21 __lwp_thread_dispatchdisable();
27 attr
.mode
= LWP_MUTEX_FIFO
;
28 attr
.nest_behavior
= LWP_MUTEX_NEST_ACQUIRE
;
29 attr
.onlyownerrelease
= TRUE
;
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
),
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
),
51 if(!initialized
) return;
53 __lwp_thread_dispatchdisable();
54 __lwp_mutex_surrender(&mem_lock
);
55 __lwp_thread_dispatchenable();
59 void _DEFUN(__libogc_malloc_lock
,(ptr
),
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
),
74 if(!initialized
) return;
76 __lwp_thread_dispatchdisable();
77 ptr
->_errno
= __lwp_mutex_surrender(&mem_lock
);
78 __lwp_thread_dispatchenable();