Added gfxRealloc()
This commit is contained in:
parent
b91097e311
commit
2bef5da2f3
4 changed files with 40 additions and 0 deletions
|
@ -76,6 +76,7 @@ extern "C" {
|
||||||
#define gfxMutexDestroy(pmutex) {}
|
#define gfxMutexDestroy(pmutex) {}
|
||||||
#define gfxMutexEnter(pmutex) chMtxLock(pmutex)
|
#define gfxMutexEnter(pmutex) chMtxLock(pmutex)
|
||||||
#define gfxMutexExit(pmutex) chMtxUnlock()
|
#define gfxMutexExit(pmutex) chMtxUnlock()
|
||||||
|
void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
|
||||||
void gfxSleepMilliseconds(delaytime_t ms);
|
void gfxSleepMilliseconds(delaytime_t ms);
|
||||||
void gfxSleepMicroseconds(delaytime_t ms);
|
void gfxSleepMicroseconds(delaytime_t ms);
|
||||||
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
|
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
|
||||||
|
|
|
@ -127,6 +127,26 @@
|
||||||
*/
|
*/
|
||||||
void *gfxAlloc(size_t sz);
|
void *gfxAlloc(size_t sz);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Re-allocate memory
|
||||||
|
* @return A pointer to the new memory area or NULL if there is no more memory available
|
||||||
|
*
|
||||||
|
* @param[in] ptr The old memory area to be increased/decreased in size
|
||||||
|
* @param[in] oldsz The size in bytes of the old memory area
|
||||||
|
* @param[in] newsz The size in bytes of the new memory area
|
||||||
|
*
|
||||||
|
* @note Some operating systems don't use the oldsz parameter as they implicitly know the size of
|
||||||
|
* old memory area. The parameter must always be supplied however for API compatibility.
|
||||||
|
* @note gfxRealloc() can make the area smaller or larger but may have to return a different pointer.
|
||||||
|
* If this occurs the new area contains a copy of the data from the old area. The old memory
|
||||||
|
* pointer should not be used after this routine as the original area may have been freed.
|
||||||
|
* @note If there is insufficient memory to create the new memory region, NULL is returned and the
|
||||||
|
* old memory area is left unchanged.
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Free memory
|
* @brief Free memory
|
||||||
*
|
*
|
||||||
|
|
|
@ -55,6 +55,7 @@ typedef HANDLE gfxThreadHandle;
|
||||||
|
|
||||||
#define gfxExit() ExitProcess(0)
|
#define gfxExit() ExitProcess(0)
|
||||||
#define gfxAlloc(sz) malloc(sz)
|
#define gfxAlloc(sz) malloc(sz)
|
||||||
|
#define gfxRealloc(p,osz,nsz) realloc(p, nsz)
|
||||||
#define gfxFree(ptr) free(ptr)
|
#define gfxFree(ptr) free(ptr)
|
||||||
#define gfxSleepMilliseconds(ms) Sleep(ms)
|
#define gfxSleepMilliseconds(ms) Sleep(ms)
|
||||||
#define gfxYield() Sleep(0)
|
#define gfxYield() Sleep(0)
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#if GFX_USE_OS_CHIBIOS
|
#if GFX_USE_OS_CHIBIOS
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#if !CH_USE_MUTEXES
|
#if !CH_USE_MUTEXES
|
||||||
#error "GOS: CH_USE_MUTEXES must be defined in chconf.h"
|
#error "GOS: CH_USE_MUTEXES must be defined in chconf.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,6 +31,22 @@ void _gosInit(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz) {
|
||||||
|
void *np;
|
||||||
|
|
||||||
|
if (newsz <= oldsz)
|
||||||
|
return ptr;
|
||||||
|
|
||||||
|
np = gfxAlloc(newsz);
|
||||||
|
if (!np)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (oldsz)
|
||||||
|
memcpy(np, ptr, oldsz);
|
||||||
|
|
||||||
|
return np;
|
||||||
|
}
|
||||||
|
|
||||||
void gfxSleepMilliseconds(delaytime_t ms) {
|
void gfxSleepMilliseconds(delaytime_t ms) {
|
||||||
switch(ms) {
|
switch(ms) {
|
||||||
case TIME_IMMEDIATE: chThdYield(); return;
|
case TIME_IMMEDIATE: chThdYield(); return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue