1
0
Fork 0
mirror of https://github.com/kakwa/uts-server synced 2025-07-04 20:47:09 +02:00

enabling multi-threads support

as TS_RESP_CTX is not thread safe, this commit implement a pool of
TS_RESP_CTX in which a thread can pick one in a thread safe maner.

* implement a ts_resp_ctx_wrapper containing a TS_RESP_CTX and a
  lock and bool to mark the availability of the TS_RESP_CTX
* implement the get_ctxw to recover a given TS_RESP_CTX in a thread safe
   maner
* adapt the rest of the code to accomodate the new way of doing things
* set the default number of threads to 10 as it's now safe to do so
This commit is contained in:
kakwa 2016-09-08 23:21:53 +02:00
parent de4f796b33
commit 14852855b9
6 changed files with 56 additions and 12 deletions

View file

@ -264,6 +264,7 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) {
chdir(conf_wd);
int ret = 1;
int http_counter = 0;
int numthreads = 42;
NCONF_free(ct->conf);
ct->conf = load_config_file(ct, conf_file);
@ -317,6 +318,8 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) {
ct->http_options[http_counter] = value;
http_counter++;
}
if (strcmp(name, "num_threads") == 0)
numthreads = atoi(value);
break;
;
case TSA_OPTIONS:
@ -328,9 +331,14 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) {
if (!add_oid_section(ct, ct->conf))
ret = 0;
ct->ts_ctx = create_tsctx(ct, ct->conf, NULL, NULL);
if (ct->ts_ctx == NULL)
ret = 0;
ct->ts_ctx_pool = calloc(numthreads, sizeof(ts_resp_ctx_wrapper));
ct->numthreads = numthreads;
for (int i = 0; i < numthreads; i++) {
ct->ts_ctx_pool[i].ts_ctx = create_tsctx(ct, ct->conf, NULL, NULL);
ct->ts_ctx_pool[i].available = 1;
if (ct->ts_ctx_pool[i].ts_ctx == NULL)
ret = 0;
}
chdir("/");
return ret;
@ -339,8 +347,11 @@ end:
return 0;
}
void free_uts_context(rfc3161_context *context) {
TS_RESP_CTX_free(context->ts_ctx);
NCONF_free(context->conf);
free(context);
void free_uts_context(rfc3161_context *ct) {
for (int i = 0; i < ct->numthreads; i++) {
TS_RESP_CTX_free(ct->ts_ctx_pool[i].ts_ctx);
}
free(ct->ts_ctx_pool);
NCONF_free(ct->conf);
free(ct);
}