Use a varnish lock for struct fcore

to be able to use Lck_AssertHeld()
parent 945e754f
......@@ -58,7 +58,6 @@ static unsigned tus_file_srvref(struct tus_file_core *);
static unsigned tus_file_unref(struct tus_file_core *);
static void tus_touch(const struct tus_file_core *, VCL_DURATION);
/*
* ------------------------------------------------------------
* specific to TUS_CONCAT
......@@ -123,7 +122,6 @@ tus_file_final_concat(struct VPFX(tus_server) *srv,
const struct tus_file_disk *pdisk;
struct vsb *vsb;
unsigned i, n = 0;
struct timespec ts;
ssize_t length = 0;
size_t l, ml;
......@@ -153,9 +151,6 @@ tus_file_final_concat(struct VPFX(tus_server) *srv,
if (n == 0)
goto err;
// wait for parts to become ready
AZ(clock_gettime(CLOCK_REALTIME, &ts));
ts.tv_sec += READY_TIMEOUT;
for (i = 0; i < n; i++) {
part = parts[i];
AN(part);
......@@ -167,13 +162,13 @@ tus_file_final_concat(struct VPFX(tus_server) *srv,
continue;
}
AZ(pthread_mutex_lock(&part->mtx));
Lck_Lock(&part->mtx);
errno = EINTR;
while (part->ptr == NULL && errno == EINTR) {
errno = pthread_cond_timedwait(&part->cond,
&part->mtx, &ts);
errno = Lck_CondWaitTimeout(&part->cond,
&part->mtx, READY_TIMEOUT);
}
AZ(pthread_mutex_unlock(&part->mtx));
Lck_Unlock(&part->mtx);
if (part->ptr == NULL)
goto err;
assert(TFCP_READABLE(part->ptr_type));
......@@ -394,7 +389,7 @@ tus_file_core_new(struct VPFX(tus_server) *srv,
fcore->server = srv;
fcore->fd = fd;
REPLACE(fcore->filename, filename);
AZ(pthread_mutex_init(&fcore->mtx, NULL));
Lck_New(&fcore->mtx, lck_fcore);
AZ(pthread_cond_init(&fcore->cond, NULL));
fcore->disk = fdisk;
fcore->srvref = 1;
......@@ -404,7 +399,7 @@ tus_file_core_new(struct VPFX(tus_server) *srv,
return (fcore);
}
AZ(pthread_mutex_destroy(&fcore->mtx));
Lck_Delete(&fcore->mtx);
AZ(pthread_cond_destroy(&fcore->cond));
REPLACE(fcore->filename, NULL);
FREE_OBJ(fcore);
......@@ -541,7 +536,7 @@ tus_file_fini(struct tus_file_core *fcore)
AZ(fdisk);
assert(fcore->fd == -1);
AZ(pthread_mutex_destroy(&fcore->mtx));
Lck_Delete(&fcore->mtx);
AZ(pthread_cond_destroy(&fcore->cond));
REPLACE(fcore->filename, NULL);
FREE_OBJ(fcore);
......@@ -561,7 +556,7 @@ tus_file_trylock(struct tus_file_core **fcorep)
CHECK_OBJ(fcore, VMOD_TUS_FILE_CORE_MAGIC);
do {
err = pthread_mutex_trylock(&fcore->mtx);
err = Lck_Trylock(&fcore->mtx);
if (err == 0)
return (err);
} while (err == EINTR);
......@@ -577,7 +572,7 @@ tus_file_unlock(struct tus_file_core **fcorep)
struct tus_file_core *fcore;
TAKE_OBJ_NOTNULL(fcore, fcorep, VMOD_TUS_FILE_CORE_MAGIC);
AZ(pthread_mutex_unlock(&fcore->mtx));
Lck_Unlock(&fcore->mtx);
}
/* under both fcore and server mtx */
......@@ -651,7 +646,7 @@ tus_file_exp(struct tus_file_core **fcorep)
TAKE_OBJ_NOTNULL(fcore, fcorep, VMOD_TUS_FILE_CORE_MAGIC);
AZ(pthread_mutex_lock(&fcore->mtx));
Lck_Lock(&fcore->mtx);
tus_file_remove(fcore);
(void) tus_file_unref_locked(fcore);
}
......@@ -666,7 +661,7 @@ tus_file_shutdown(struct VPFX(tus_server) *srv)
tus_server_lock(srv);
VSPLAY_FOREACH(fcore, tus_files, files) {
REPLACE(fcore->filename, NULL); // prevent unlink
AZ(pthread_mutex_lock(&fcore->mtx));
Lck_Lock(&fcore->mtx);
tus_file_del_shutdown(&fcore);
AZ(fcore);
}
......@@ -693,9 +688,9 @@ tus_file_ref(struct tus_file_core *fcore)
int r;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
AZ(pthread_mutex_lock(&fcore->mtx));
Lck_Lock(&fcore->mtx);
r = fcore->ref++ + fcore->srvref;
AZ(pthread_mutex_unlock(&fcore->mtx));
Lck_Unlock(&fcore->mtx);
assert(r >= 0);
return (r);
}
......@@ -709,7 +704,7 @@ tus_file_unref_locked(struct tus_file_core *fcore)
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
r = --fcore->ref + fcore->srvref;
AZ(pthread_mutex_unlock(&fcore->mtx));
Lck_Unlock(&fcore->mtx);
assert (r >= 0);
if (r == 0)
tus_file_fini(fcore);
......@@ -721,7 +716,7 @@ tus_file_unref(struct tus_file_core *fcore)
{
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
AZ(pthread_mutex_lock(&fcore->mtx));
Lck_Lock(&fcore->mtx);
return (tus_file_unref_locked(fcore));
}
......
......@@ -35,6 +35,11 @@
#include "tus_server.h"
/* ============================================================
* vmod shared object globals in vmod_tus.c
*/
extern struct VSC_lck *lck_fcore;
#define TUS_PATH_MAX PATH_MAX
#define TUS_METADATA_MAX 2048u // ballpark of AWS S3 metadata
......@@ -84,7 +89,7 @@ struct tus_file_core {
VSPLAY_ENTRY(tus_file_core) entry;
pthread_mutex_t mtx;
struct lock mtx;
pthread_cond_t cond;
struct tus_file_disk *disk;
unsigned exp_idx;
......
......@@ -33,8 +33,7 @@
#include <unistd.h>
#include <stdio.h>
#include "vdef.h"
#include "vrt.h"
#include "cache/cache.h" // for struct lock
#include "miniobj.h"
#include "vas.h"
#include "vbh.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment