56 lines
848 B
C
56 lines
848 B
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "sql.h"
|
|
#include "job_queue.h"
|
|
|
|
struct msg_t **slot;
|
|
int total_queues;
|
|
|
|
int start_msg_queue(void)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < total_queues; i++) {
|
|
if (slot[i] == NULL) {
|
|
slot[i] = (struct msg_t *)calloc(100, sizeof(struct msg_t));
|
|
if (slot[i] == NULL)
|
|
return -1;
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void free_queue(int id)
|
|
{
|
|
free(slot[id]);
|
|
}
|
|
|
|
int start_job_queue(int poolsize)
|
|
{
|
|
slot = (struct msg_t **)calloc(poolsize, sizeof(struct msg_t *));
|
|
if (slot == NULL)
|
|
return -1;
|
|
total_queues = poolsize;
|
|
return 0;
|
|
}
|
|
|
|
int add_msg_to_queue(int id, struct msg_t buf)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < 100; i++) {
|
|
if (slot[id][i].meta.is_recv) {
|
|
memcpy(&slot[id][i], &buf, sizeof(struct msg_t));
|
|
return 0;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void create_job(struct msg_t buf)
|
|
{
|
|
// add_job_in_db();
|
|
|
|
}
|