So I'm having a bit of trouble working out how to integrate the queue_8h into a Lua library,
Maybe I'm getting hung up on the wrong things here, I looked at the code and it's using heap memory for the queue, this could pose a problem if the Lua stack closes and doesn't clean up. I have my Lua stacks running in there own heaps so cleanup is simple in case of failure.
To this end I've started to write the init function I think it looks right.
The idea is to have the two Lua instances running call them Manager and Worker. Manager can send the messages to Worker and Worker will have a shared memory where it can set statuses. So Manager starts up first and initialises the queue, then somehow Work needs to get the queue and start checking for messages.
I'm thinking the check message will look to see if the queue is enabled and if not it will return nil So Worker doesn't call queue_init
Maybe I'm getting hung up on the wrong things here, I looked at the code and it's using heap memory for the queue, this could pose a problem if the Lua stack closes and doesn't clean up. I have my Lua stacks running in there own heaps so cleanup is simple in case of failure.
To this end I've started to write the init function I think it looks right.
Code:
static queue_t *q = NULL;static int node_queue_init(lua_State *L){ // Grab all memory in one go. uint16_t QUEUE_COUNT = (uint16_t)luaL_optinteger(L,1,NODE_QUEUE_COUNT); uint16_t QUEUE_SIZE = (uint16_t)luaL_optinteger(L,2,NODE_QUEUE_SIZE); q = lua_newuserdata(L, sizeof(queue_t) + ((QUEUE_COUNT + 1) * QUEUE_SIZE)); memset((uint8_t *)q + sizeof(queue_t), 0, ((QUEUE_COUNT + 1) * QUEUE_SIZE)); // Basically call this // queue_init(q, NODE_QUEUE_SIZE, NODE_QUEUE_COUNT); // use Lua's memory instead of global memory if (q->data == NULL) return 0; lock_init(&q->core, next_striped_spin_lock_num()); q->data = (uint8_t *)q + sizeof(queue_t); q->element_count = QUEUE_COUNT; q->element_size = QUEUE_SIZE; q->wptr = 0; q->rptr = 0; return 1;}
I'm thinking the check message will look to see if the queue is enabled and if not it will return nil So Worker doesn't call queue_init
Statistics: Posted by DarkElvenAngel — Thu Jan 11, 2024 1:18 am