update(cherrymp): use own osal
This commit is contained in:
45
third_party/cherrymp/chry_mempool.c
vendored
45
third_party/cherrymp/chry_mempool.c
vendored
@@ -11,37 +11,41 @@ int chry_mempool_create(struct chry_mempool *pool, void *block, uint32_t block_s
|
||||
uint8_t *ringbuf1;
|
||||
uint8_t *ringbuf2;
|
||||
|
||||
ringbuf1 = usb_osal_malloc(sizeof(uintptr_t) * block_count);
|
||||
ringbuf1 = chry_mempool_osal_malloc(sizeof(uintptr_t) * block_count);
|
||||
if (ringbuf1 == NULL) {
|
||||
return -1;
|
||||
}
|
||||
memset(ringbuf1, 0, sizeof(uintptr_t) * block_count);
|
||||
|
||||
if (chry_ringbuffer_init(&pool->in, ringbuf1, sizeof(uintptr_t) * block_count) == -1) {
|
||||
usb_osal_free(ringbuf1);
|
||||
chry_mempool_osal_free(ringbuf1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ringbuf2 = usb_osal_malloc(sizeof(uintptr_t) * block_count);
|
||||
ringbuf2 = chry_mempool_osal_malloc(sizeof(uintptr_t) * block_count);
|
||||
if (ringbuf2 == NULL) {
|
||||
usb_osal_free(ringbuf1);
|
||||
chry_mempool_osal_free(ringbuf1);
|
||||
return -1;
|
||||
}
|
||||
memset(ringbuf2, 0, sizeof(uintptr_t) * block_count);
|
||||
|
||||
if (chry_ringbuffer_init(&pool->out, ringbuf2, sizeof(uintptr_t) * block_count) == -1) {
|
||||
usb_osal_free(ringbuf1);
|
||||
usb_osal_free(ringbuf2);
|
||||
chry_mempool_osal_free(ringbuf1);
|
||||
chry_mempool_osal_free(ringbuf2);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pool->out_sem = usb_osal_sem_create(block_count);
|
||||
pool->out_sem = chry_mempool_osal_sem_create(block_count);
|
||||
if (pool->out_sem == NULL) {
|
||||
usb_osal_free(ringbuf1);
|
||||
usb_osal_free(ringbuf2);
|
||||
chry_mempool_osal_free(ringbuf1);
|
||||
chry_mempool_osal_free(ringbuf2);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pool->block = block;
|
||||
pool->block_size = block_size;
|
||||
pool->block_count = block_count;
|
||||
|
||||
for (uint32_t i = 0; i < block_count; i++) {
|
||||
addr = ((uintptr_t)block + i * block_size);
|
||||
chry_ringbuffer_write(&pool->in, &addr, sizeof(uintptr_t));
|
||||
@@ -52,11 +56,11 @@ int chry_mempool_create(struct chry_mempool *pool, void *block, uint32_t block_s
|
||||
|
||||
void chry_mempool_delete(struct chry_mempool *pool)
|
||||
{
|
||||
usb_osal_sem_delete(pool->out_sem);
|
||||
chry_mempool_osal_sem_delete(pool->out_sem);
|
||||
chry_ringbuffer_reset(&pool->in);
|
||||
chry_ringbuffer_reset(&pool->out);
|
||||
usb_osal_free(pool->in.pool);
|
||||
usb_osal_free(pool->out.pool);
|
||||
chry_mempool_osal_free(pool->in.pool);
|
||||
chry_mempool_osal_free(pool->out.pool);
|
||||
}
|
||||
|
||||
uintptr_t *chry_mempool_alloc(struct chry_mempool *pool)
|
||||
@@ -86,7 +90,7 @@ int chry_mempool_send(struct chry_mempool *pool, uintptr_t *item)
|
||||
|
||||
addr = (uintptr_t)item;
|
||||
chry_ringbuffer_write(&pool->out, &addr, sizeof(uintptr_t));
|
||||
return usb_osal_sem_give(pool->out_sem);
|
||||
return chry_mempool_osal_sem_give(pool->out_sem);
|
||||
}
|
||||
|
||||
int chry_mempool_recv(struct chry_mempool *pool, uintptr_t **item, uint32_t timeout)
|
||||
@@ -94,7 +98,7 @@ int chry_mempool_recv(struct chry_mempool *pool, uintptr_t **item, uint32_t time
|
||||
uint32_t len;
|
||||
int ret;
|
||||
|
||||
ret = usb_osal_sem_take(pool->out_sem, timeout);
|
||||
ret = chry_mempool_osal_sem_take(pool->out_sem, timeout);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -105,4 +109,17 @@ int chry_mempool_recv(struct chry_mempool *pool, uintptr_t **item, uint32_t time
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void chry_mempool_reset(struct chry_mempool *pool)
|
||||
{
|
||||
uintptr_t addr;
|
||||
|
||||
chry_ringbuffer_reset(&pool->in);
|
||||
chry_ringbuffer_reset(&pool->out);
|
||||
|
||||
for (uint32_t i = 0; i < pool->block_count; i++) {
|
||||
addr = ((uintptr_t)pool->block + i * pool->block_size);
|
||||
chry_ringbuffer_write(&pool->in, &addr, sizeof(uintptr_t));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user