summaryrefslogtreecommitdiff
path: root/server/stat-file.c
diff options
context:
space:
mode:
Diffstat (limited to 'server/stat-file.c')
-rw-r--r--server/stat-file.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/server/stat-file.c b/server/stat-file.c
index 38c39338..68d095d7 100644
--- a/server/stat-file.c
+++ b/server/stat-file.c
@@ -39,6 +39,7 @@ struct RedStatFile {
SpiceStat *stat;
pthread_mutex_t lock;
unsigned int max_nodes;
+ uint16_t *refs;
};
RedStatFile *stat_file_new(unsigned int max_nodes)
@@ -48,6 +49,7 @@ RedStatFile *stat_file_new(unsigned int max_nodes)
RedStatFile *stat_file = g_new0(RedStatFile, 1);
stat_file->max_nodes = max_nodes;
+ stat_file->refs = g_new0(uint16_t, max_nodes);
stat_file->shm_name = g_strdup_printf(SPICE_STAT_SHM_NAME, getpid());
shm_unlink(stat_file->shm_name);
if ((fd = shm_open(stat_file->shm_name, O_CREAT | O_RDWR, 0444)) == -1) {
@@ -154,6 +156,7 @@ stat_file_add_node(RedStatFile *stat_file, StatNodeRef parent, const char *name,
while (ref != INVALID_STAT_REF) {
node = &stat_file->stat->nodes[ref];
if (strcmp(name, node->name) == 0) {
+ stat_file->refs[ref]++;
pthread_mutex_unlock(&stat_file->lock);
return ref;
}
@@ -166,6 +169,7 @@ stat_file_add_node(RedStatFile *stat_file, StatNodeRef parent, const char *name,
}
stat_file->stat->generation++;
stat_file->stat->num_of_nodes++;
+ stat_file->refs[ref] = 1;
node->value = 0;
node->flags = SPICE_STAT_NODE_FLAG_ENABLED |
(visible ? SPICE_STAT_NODE_FLAG_VISIBLE : 0);
@@ -199,6 +203,10 @@ static void stat_file_remove(RedStatFile *stat_file, SpiceStatNode *node)
StatNodeRef ref;
pthread_mutex_lock(&stat_file->lock);
+ if (--stat_file->refs[node_ref]) {
+ pthread_mutex_unlock(&stat_file->lock);
+ return;
+ }
node->flags &= ~SPICE_STAT_NODE_FLAG_ENABLED;
stat_file->stat->generation++;
stat_file->stat->num_of_nodes--;