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