mirror of
https://github.com/wiiu-env/wut.git
synced 2025-01-06 14:38:13 +01:00
wutstdc++: Use malloc / free instead of MEM functions.
This commit is contained in:
parent
d5effaaf88
commit
4220023511
@ -1,4 +1,6 @@
|
||||
#include "wut_gthread.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
@ -59,8 +61,11 @@ __wut_get_thread_keys()
|
||||
{
|
||||
const void **keys = (const void **)OSGetThreadSpecific(__WUT_KEY_THREAD_SPECIFIC_ID);
|
||||
if (!keys) {
|
||||
MEMExpandedHeap *heap = (MEMExpandedHeap *)MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2);
|
||||
keys = (const void **)MEMAllocFromExpHeapEx(heap, sizeof(void *) * sizeof(__WUT_MAX_KEYS), 4);
|
||||
keys = (const void **)malloc(sizeof(void *) * sizeof(__WUT_MAX_KEYS));
|
||||
if (!keys) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(keys, 0, sizeof(void *) * sizeof(__WUT_MAX_KEYS));
|
||||
OSSetThreadSpecific(__WUT_KEY_THREAD_SPECIFIC_ID, keys);
|
||||
}
|
||||
@ -71,14 +76,24 @@ __wut_get_thread_keys()
|
||||
void *
|
||||
__wut_getspecific(__wut_key_t key)
|
||||
{
|
||||
return (void *)__wut_get_thread_keys()[key];
|
||||
const void **keys = __wut_get_thread_keys();
|
||||
if (!keys) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (void *)(keys[key]);
|
||||
}
|
||||
|
||||
int
|
||||
__wut_setspecific(__wut_key_t key,
|
||||
const void *ptr)
|
||||
{
|
||||
__wut_get_thread_keys()[key] = ptr;
|
||||
const void **keys = __wut_get_thread_keys();
|
||||
if (!keys) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
keys[key] = ptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -99,4 +114,5 @@ __wut_key_cleanup(OSThread *thread)
|
||||
}
|
||||
|
||||
__wut_mutex_unlock(&key_mutex);
|
||||
free(keys);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "wut_gthread.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
@ -7,9 +8,8 @@ static void
|
||||
__wut_thread_deallocator(OSThread *thread,
|
||||
void *stack)
|
||||
{
|
||||
MEMExpandedHeap *heap = (MEMExpandedHeap *)MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2);
|
||||
MEMFreeToExpHeap(heap, thread);
|
||||
MEMFreeToExpHeap(heap, stack);
|
||||
free(thread);
|
||||
free(stack);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -23,9 +23,8 @@ __wut_thread_create(OSThread **outThread,
|
||||
void *(*entryPoint) (void*),
|
||||
void *entryArgs)
|
||||
{
|
||||
MEMExpandedHeap *heap = (MEMExpandedHeap *)MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2);
|
||||
OSThread *thread = (OSThread *)MEMAllocFromExpHeapEx(heap, sizeof(OSThread), 8);
|
||||
char *stack = (char *)MEMAllocFromExpHeapEx(heap, __WUT_STACK_SIZE, 8);
|
||||
OSThread *thread = (OSThread *)memalign(16, sizeof(OSThread));
|
||||
char *stack = (char *)memalign(16, __WUT_STACK_SIZE);
|
||||
memset(thread, 0, sizeof(OSThread));
|
||||
|
||||
if (!OSCreateThread(thread,
|
||||
@ -36,7 +35,8 @@ __wut_thread_create(OSThread **outThread,
|
||||
__WUT_STACK_SIZE,
|
||||
16,
|
||||
OS_THREAD_ATTRIB_AFFINITY_ANY)) {
|
||||
MEMFreeToExpHeap((MEMExpandedHeap*)MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), thread);
|
||||
free(thread);
|
||||
free(stack);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user