-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from cole-miller/revamp
More revamp work: preparing to send requests to the DB thread
- Loading branch information
Showing
3 changed files
with
98 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,49 @@ | ||
#include "revamp.h" | ||
|
||
int dbContextInit(struct db_context *ctx, struct config *config) | ||
{ | ||
int rv; | ||
rv = pthread_mutex_init(&ctx->mutex, NULL); | ||
assert(rv == 0); | ||
rv = pthread_cond_init(&ctx->cond, NULL); | ||
assert(rv == 0); | ||
registry__init(&ctx->registry, config); | ||
ctx->shutdown = false; | ||
return 0; | ||
} | ||
|
||
int postExecSqlReq(struct db_context *ctx, | ||
struct exec_sql_req req, | ||
void *data, | ||
void (*cb)(struct exec_sql_req, int, void *)) | ||
{ | ||
(void)ctx; | ||
(void)req; | ||
(void)data; | ||
(void)cb; | ||
return 0; | ||
} | ||
|
||
void dbContextClose(struct db_context *ctx) | ||
{ | ||
registry__close(&ctx->registry); | ||
pthread_cond_destroy(&ctx->cond); | ||
pthread_mutex_destroy(&ctx->mutex); | ||
} | ||
|
||
void *dbTask(void *arg) | ||
{ | ||
struct db_context *ctx = arg; | ||
int rv; | ||
|
||
rv = pthread_mutex_lock(&ctx->mutex); | ||
assert(rv == 0); | ||
for (;;) { | ||
rv = pthread_cond_wait(&ctx->cond, &ctx->mutex); | ||
assert(rv == 0); | ||
if (ctx->shutdown) { | ||
break; | ||
} | ||
} | ||
return NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
#ifndef DQLITE_REVAMP_H | ||
#define DQLITE_REVAMP_H | ||
#ifndef DQLITE_REVAMP_H_ | ||
#define DQLITE_REVAMP_H_ | ||
|
||
#include <semaphore.h> | ||
#include "lib/queue.h" | ||
#include "registry.h" | ||
#include "tuple.h" | ||
|
||
#include <pthread.h> | ||
#include <stdbool.h> | ||
|
||
struct db_context | ||
{ | ||
sem_t sem; | ||
pthread_mutex_t mutex; | ||
pthread_cond_t cond; | ||
struct registry registry; | ||
queue exec_sql_reqs; | ||
bool shutdown; | ||
}; | ||
|
||
struct exec_sql_req | ||
{ | ||
char *db_name; | ||
char *sql; | ||
struct value *params; | ||
queue queue; | ||
}; | ||
|
||
int dbContextInit(struct db_context *ctx, struct config *config); | ||
|
||
int postExecSqlReq(struct db_context *ctx, | ||
struct exec_sql_req req, | ||
void *data, | ||
void (*cb)(struct exec_sql_req, int, void *)); | ||
|
||
void dbContextClose(struct db_context *ctx); | ||
|
||
void *dbTask(void *arg); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters