#ifndef GM_WORKER_DB
#define GM_WORKER_DB
#include <pthread.h>
#define DB_TABLES 5
#define DB_NUM_BUFFERS 3 // must be >= 3 or dead lock may occur
#define DB_MAX_BUFFER 50
struct worker_db_load {
void *data; //pointer to data (type is determined by table)
int type; //parameter (delete/update/insert/etc)
bool *lock; //pointer to approriate lock on data (stop scanner of updating till update is complete
};
struct worker_db {
pthread_mutex_t write_mutex; //write to buffer
pthread_mutex_t stack_mutex; //stack/loadBuffer pointer changes
pthread_cond_t full_buffer; //when a buffer is ready to be sent to db
//work buffered
worker_db_load loadBuffer[DB_TABLES][DB_NUM_BUFFERS][DB_MAX_BUFFER];
//what id currently writing to / size of buffer
int loadBufferIndex[DB_TABLES][DB_NUM_BUFFERS];
//buffer id write or sql is on
int write_buffer[DB_TABLES];
int sql_buffer[DB_TABLES];
//pointers to current write buffers
worker_db_load **writeLoadBuffer[DB_TABLES];
int **writeLoadBufferIndex[DB_TABLES];
};
#endif