From fb3cb0d3ae8ef392024c6e9598b2a59bf92f2277 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 21 Dec 2016 13:58:28 +0100 Subject: [PATCH] server: Move ->size from mmd to struct vss_task. This field stores the size of the memory mapping of the current audio file, if any. No command handler ever changes the value, and the value is not read from com_stat(), so there is no reason for ->size to be part of the mmd shared memory area. Unlike ->size, the pointer to the mapping is stored in struct vss_task. Given that vss.c is the only file which reads ->map or ->size, it makes sense to store both values together in the vss task struct. --- server.h | 2 -- vss.c | 14 ++++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server.h b/server.h index 8de691ca..7f276ab9 100644 --- a/server.h +++ b/server.h @@ -48,8 +48,6 @@ struct sender_command_data { * propagate to the stat command handlers. */ struct misc_meta_data { - /** The size of the current audio file in bytes. */ - size_t size; /** The "old" status flags -- commands may only read them. */ unsigned int vss_status_flags; /** The new status flags -- commands may set them. */ diff --git a/vss.c b/vss.c index 5484db9d..792a7393 100644 --- a/vss.c +++ b/vss.c @@ -88,6 +88,8 @@ struct vss_task { enum afs_socket_status afsss; /** The memory mapped audio file. */ char *map; + /** The size of the memory mapping. */ + size_t mapsize; /** Used by the scheduler. */ struct task *task; /** Pointer to the header of the mapped audio file. */ @@ -846,7 +848,7 @@ static void vss_eof(struct vss_task *vsst) set_eof_barrier(vsst); afh_free_header(vsst->header_buf, mmd->afd.audio_format_id); vsst->header_buf = NULL; - para_munmap(vsst->map, mmd->size); + para_munmap(vsst->map, vsst->mapsize); vsst->map = NULL; mmd->chunks_sent = 0; //mmd->offset = 0; @@ -855,7 +857,7 @@ static void vss_eof(struct vss_task *vsst) mmd->afd.afhi.chunk_tv.tv_usec = 0; free(mmd->afd.afhi.chunk_table); mmd->afd.afhi.chunk_table = NULL; - mmd->size = 0; + vsst->mapsize = 0; mmd->events++; } @@ -973,11 +975,11 @@ static void recv_afs_result(struct vss_task *vsst, fd_set *rfds) ret = -ERRNO_TO_PARA_ERROR(errno); goto err; } - mmd->size = statbuf.st_size; - ret = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, + ret = para_mmap(statbuf.st_size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, passed_fd, 0, &vsst->map); if (ret < 0) goto err; + vsst->mapsize = statbuf.st_size; close(passed_fd); mmd->chunks_sent = 0; mmd->current_chunk = 0; @@ -986,7 +988,7 @@ static void recv_afs_result(struct vss_task *vsst, fd_set *rfds) mmd->num_played++; mmd->new_vss_status_flags &= (~VSS_NEXT); afh_get_header(&mmd->afd.afhi, mmd->afd.audio_format_id, - vsst->map, mmd->size, &vsst->header_buf, &vsst->header_len); + vsst->map, vsst->mapsize, &vsst->header_buf, &vsst->header_len); return; err: free(mmd->afd.afhi.chunk_table); @@ -1076,7 +1078,7 @@ static void vss_send(struct vss_task *vsst) */ if (mmd->current_chunk > 0) { /* chunk 0 might be on the heap */ buf += len; - for (i = 0; i < 5 && buf < vsst->map + mmd->size; i++) { + for (i = 0; i < 5 && buf < vsst->map + vsst->mapsize; i++) { __a_unused volatile char x = *buf; buf += 4096; } -- 2.39.2