Straighten fcore locking

parent ec06de08
...@@ -58,6 +58,8 @@ static unsigned tus_file_srvref(struct tus_file_core *); ...@@ -58,6 +58,8 @@ static unsigned tus_file_srvref(struct tus_file_core *);
static unsigned tus_file_unref(struct tus_file_core *); static unsigned tus_file_unref(struct tus_file_core *);
static void tus_touch(const struct tus_file_core *, VCL_DURATION); static void tus_touch(const struct tus_file_core *, VCL_DURATION);
#define Lck_AssertUnlocked(a) AZ(Lck__Held(a))
/* /*
* ------------------------------------------------------------ * ------------------------------------------------------------
* specific to TUS_CONCAT * specific to TUS_CONCAT
...@@ -211,6 +213,7 @@ tus_file_final_birth(struct tus_file_core **fcorep, ...@@ -211,6 +213,7 @@ tus_file_final_birth(struct tus_file_core **fcorep,
struct vsb *vsb; struct vsb *vsb;
TAKE_OBJ_NOTNULL(fcore, fcorep, VMOD_TUS_FILE_CORE_MAGIC); TAKE_OBJ_NOTNULL(fcore, fcorep, VMOD_TUS_FILE_CORE_MAGIC);
Lck_AssertHeld(&fcore->mtx);
CHECK_OBJ_NOTNULL(embryo, CONCAT_EMBRYO_MAGIC); CHECK_OBJ_NOTNULL(embryo, CONCAT_EMBRYO_MAGIC);
fdisk = fcore->disk; fdisk = fcore->disk;
CHECK_OBJ_NOTNULL(fdisk, VMOD_TUS_FILE_DISK_MAGIC); CHECK_OBJ_NOTNULL(fdisk, VMOD_TUS_FILE_DISK_MAGIC);
...@@ -258,6 +261,9 @@ tus_file_final_fini(struct tus_file_core *fcore) ...@@ -258,6 +261,9 @@ tus_file_final_fini(struct tus_file_core *fcore)
{ {
struct tus_concat *concat; struct tus_concat *concat;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
Lck_AssertHeld(&fcore->mtx);
if (fcore->ptr == NULL) if (fcore->ptr == NULL)
return; return;
...@@ -312,6 +318,9 @@ tus_file_final_urls(VRT_CTX, const struct tus_file_core *fcore, const char *pfx) ...@@ -312,6 +318,9 @@ tus_file_final_urls(VRT_CTX, const struct tus_file_core *fcore, const char *pfx)
struct vsb vsb[1]; struct vsb vsb[1];
unsigned i; unsigned i;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
Lck_AssertHeld(&fcore->mtx);
if (fcore->ptr == NULL) if (fcore->ptr == NULL)
return (NULL); return (NULL);
...@@ -343,6 +352,7 @@ tus_file_open(struct tus_file_core *fcore) ...@@ -343,6 +352,7 @@ tus_file_open(struct tus_file_core *fcore)
int basefd; int basefd;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC); CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
Lck_AssertHeld(&fcore->mtx);
if (fcore->fd < 0) { if (fcore->fd < 0) {
basefd = tus_server_basefd(fcore->server); basefd = tus_server_basefd(fcore->server);
...@@ -357,6 +367,7 @@ static void ...@@ -357,6 +367,7 @@ static void
tus_file_close(struct tus_file_core *fcore) tus_file_close(struct tus_file_core *fcore)
{ {
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC); CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
Lck_AssertHeld(&fcore->mtx);
if (fcore->fd == -1) if (fcore->fd == -1)
return; return;
...@@ -425,6 +436,7 @@ tus_file_complete(struct tus_file_core *fcore) ...@@ -425,6 +436,7 @@ tus_file_complete(struct tus_file_core *fcore)
struct tus_file_disk *fdisk; struct tus_file_disk *fdisk;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC); CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
Lck_AssertHeld(&fcore->mtx);
fdisk = fcore->disk; fdisk = fcore->disk;
CHECK_TUS_FILE_DISK(fdisk); CHECK_TUS_FILE_DISK(fdisk);
...@@ -451,6 +463,7 @@ tus_file_mmap(struct tus_file_core *fcore) ...@@ -451,6 +463,7 @@ tus_file_mmap(struct tus_file_core *fcore)
int prot = PROT_READ; int prot = PROT_READ;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC); CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
Lck_AssertHeld(&fcore->mtx);
fdisk = fcore->disk; fdisk = fcore->disk;
CHECK_TUS_FILE_DISK(fdisk); CHECK_TUS_FILE_DISK(fdisk);
...@@ -511,6 +524,9 @@ tus_file_fini(struct tus_file_core *fcore) ...@@ -511,6 +524,9 @@ tus_file_fini(struct tus_file_core *fcore)
{ {
struct tus_file_disk *fdisk; struct tus_file_disk *fdisk;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
Lck_AssertUnlocked(&fcore->mtx);
fdisk = fcore->disk; fdisk = fcore->disk;
CHECK_TUS_FILE_DISK(fdisk); CHECK_TUS_FILE_DISK(fdisk);
AZ(fcore->srvref); AZ(fcore->srvref);
...@@ -583,7 +599,10 @@ ref_transfer(struct tus_file_core *fcore) ...@@ -583,7 +599,10 @@ ref_transfer(struct tus_file_core *fcore)
{ {
unsigned r; unsigned r;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
tus_server_AssertLocked(fcore->server); tus_server_AssertLocked(fcore->server);
Lck_AssertHeld(&fcore->mtx);
r = fcore->srvref; r = fcore->srvref;
fcore->srvref = 0; fcore->srvref = 0;
...@@ -601,6 +620,7 @@ tus_file_del_shutdown(struct tus_file_core **fcorep) ...@@ -601,6 +620,7 @@ tus_file_del_shutdown(struct tus_file_core **fcorep)
TAKE_OBJ_NOTNULL(fcore, fcorep, VMOD_TUS_FILE_CORE_MAGIC); TAKE_OBJ_NOTNULL(fcore, fcorep, VMOD_TUS_FILE_CORE_MAGIC);
tus_server_AssertLocked(fcore->server); tus_server_AssertLocked(fcore->server);
Lck_AssertHeld(&fcore->mtx);
AN(ref_transfer(fcore)); AN(ref_transfer(fcore));
rm = VSPLAY_REMOVE(tus_files, tus_server_files(fcore->server), rm = VSPLAY_REMOVE(tus_files, tus_server_files(fcore->server),
...@@ -707,6 +727,7 @@ tus_file_unref_locked(struct tus_file_core *fcore) ...@@ -707,6 +727,7 @@ tus_file_unref_locked(struct tus_file_core *fcore)
int r; int r;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC); CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
Lck_AssertHeld(&fcore->mtx);
r = --fcore->ref + fcore->srvref; r = --fcore->ref + fcore->srvref;
Lck_Unlock(&fcore->mtx); Lck_Unlock(&fcore->mtx);
...@@ -810,7 +831,9 @@ tus_file_add(struct VPFX(tus_server) *srv, int basefd, const char *filename) ...@@ -810,7 +831,9 @@ tus_file_add(struct VPFX(tus_server) *srv, int basefd, const char *filename)
fcore = tus_file_core_new(srv, fd, filename, fdisk); fcore = tus_file_core_new(srv, fd, filename, fdisk);
if (fcore != NULL) { if (fcore != NULL) {
Lck_Lock(&fcore->mtx);
tus_file_close(fcore); tus_file_close(fcore);
Lck_Unlock(&fcore->mtx);
return; return;
} }
......
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