]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - scrub/counter.c
4344492763c13f02aeec81436af0a7a046f9d556
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
12 #include "libfrog/ptvar.h"
18 * This is a global counter object that uses per-thread counters to
19 * count things without having to content for a single shared lock.
20 * Provided we know the number of threads that will be accessing the
21 * counter, each thread gets its own thread-specific counter variable.
22 * Changing the value is fast, though retrieving the value is expensive
29 /* Initialize per-thread counter. */
36 p
= malloc(sizeof(struct ptcounter
));
39 p
->var
= ptvar_init(nr
, sizeof(uint64_t));
47 /* Free per-thread counter. */
50 struct ptcounter
*ptc
)
56 /* Add a quantity to the counter. */
59 struct ptcounter
*ptc
,
64 p
= ptvar_get(ptc
->var
);
74 uint64_t *sum
= foreach_arg
;
75 uint64_t *count
= data
;
81 /* Return the approximate value of this counter. */
84 struct ptcounter
*ptc
)
88 ptvar_foreach(ptc
->var
, ptcounter_val_helper
, &sum
);