Add assertions on srv lock held

parent 3a18bfbd
......@@ -384,6 +384,8 @@ tus_file_core_new(struct VPFX(tus_server) *srv,
{
struct tus_file_core *fcore;
tus_server_AssertLocked(srv);
ALLOC_OBJ(fcore, VMOD_TUS_FILE_CORE_MAGIC);
AN(fcore);
fcore->server = srv;
......@@ -581,6 +583,7 @@ ref_transfer(struct tus_file_core *fcore)
{
unsigned r;
tus_server_AssertLocked(fcore->server);
r = fcore->srvref;
fcore->srvref = 0;
......@@ -597,6 +600,7 @@ tus_file_del_shutdown(struct tus_file_core **fcorep)
const struct tus_file_core *rm;
TAKE_OBJ_NOTNULL(fcore, fcorep, VMOD_TUS_FILE_CORE_MAGIC);
tus_server_AssertLocked(fcore->server);
AN(ref_transfer(fcore));
rm = VSPLAY_REMOVE(tus_files, tus_server_files(fcore->server),
......@@ -675,6 +679,7 @@ tus_file_srvref(struct tus_file_core *fcore)
int r;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
tus_server_AssertLocked(fcore->server);
r = fcore->srvref++;
// as long as the object can be found, it has one srvref at least
assert(r > 0);
......@@ -731,6 +736,8 @@ tus_file_add(struct VPFX(tus_server) *srv, int basefd, const char *filename)
const char *err;
ssize_t sz;
tus_server_AssertLocked(srv);
if (fstatat(basefd, filename, &st, AT_SYMLINK_NOFOLLOW)) {
fprintf(stderr, "tus add stat %s: %d\n", filename, errno);
goto err;
......@@ -824,6 +831,8 @@ tus_file_load(struct VPFX(tus_server) *srv)
DIR *dir;
struct dirent *ent;
tus_server_AssertLocked(srv);
dir = fdopendir(dup(basefd));
AN(dir);
while ((ent = readdir(dir)) != NULL) {
......
......@@ -43,6 +43,10 @@ const char * tus_server_basedir(const struct VPFX(tus_server) *);
VCL_DURATION tus_server_expires(const struct VPFX(tus_server) *);
void tus_server_lock(struct VPFX(tus_server) *);
void tus_server_unlock(struct VPFX(tus_server) *);
void tus_server__assertlocked(struct VPFX(tus_server) *s, const char *func,
const char *file, int line);
#define tus_server_AssertLocked(s) \
tus_server__assertlocked(s, __func__, __FILE__, __LINE__)
VCL_BYTES tus_server_max(const struct VPFX(tus_server) *s);
VCL_BYTES tus_server_multipart(const struct VPFX(tus_server) *s);
struct vmod_blobdigest_digest * tus_server_digest(
......
......@@ -95,6 +95,18 @@ tus_server_unlock(struct VPFX(tus_server) *s)
Lck_Unlock(&s->mtx);
}
void
tus_server__assertlocked(struct VPFX(tus_server) *s, const char *func,
const char *file, int line)
{
CHECK_OBJ_NOTNULL(s, VMOD_TUS_SERVER_MAGIC);
if (! Lck__Held(&s->mtx))
VAS_Fail(func, file, line, "Lck__Held(&s->mtx)", VAS_ASSERT);
if (! Lck__Owned(&s->mtx))
VAS_Fail(func, file, line, "Lck__Owned(&s->mtx)", VAS_ASSERT);
}
VCL_BYTES
tus_server_max(const struct VPFX(tus_server) *s)
{
......
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