wutstdc++: Use malloc / free instead of MEM functions.

This commit is contained in:
James Benton 2018-05-30 13:14:01 +01:00
parent d5effaaf88
commit 4220023511
2 changed files with 27 additions and 11 deletions

View File

@ -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);
}

View File

@ -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;
}