summaryrefslogtreecommitdiff
path: root/src/basic/hashmap.c
Commit message (Collapse)AuthorAge
* tree-wide: drop copyright headers from frequent contributorsZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | Fixes #9320. for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms' done
* tree-wide: beautify remaining copyright statementsLennart Poettering2018-08-24
| | | | | | Let's unify an beautify our remaining copyright statements, with a unicode ©. This means our copyright statements are now always formatted the same way. Yay.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-08-24
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* Turn VALGRIND variable into a meson configuration switchZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | Configuration through environment variable is inconvenient with meson, because they cannot be convieniently changed and/or are not preserved during reconfiguration (https://github.com/mesonbuild/meson/issues/1503). This adds -Dvalgrind=true/false, which has the advantage that it can be set at any time with meson configure -Dvalgrind=... and ninja will rebuild targets as necessary. Additional minor advantages are better consistency with the options for hashmap debugging, and typo avoidance with '#if' instead of '#ifdef'.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* basic/hashmap: tweak code to avoid pointless gcc warningZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | | | | | | | | | | | gcc says: [196/1142] Compiling C object 'src/basic/basic@sta/hashmap.c.o'. ../src/basic/hashmap.c: In function ‘cachemem_maintain’: ../src/basic/hashmap.c:1913:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses] mem->active = r = true; ^~~ which conflates two things: the first is transitive assignent a = b = c = d; the second is assignment of the value of an expression, which happens to be a an assignment expression here, and boolean. While the second _should_ be parenthesized, the first should _not_, and it's more natural to understand our code as the first, and gcc should treat this as an exception and not emit the warning. But since it's a while until this will be fixed, let's update our code too.
* basic: implement the IteratedCacheVito Caputo2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adds the basics of the IteratedCache and constructor support for the Hashmap and OrderedHashmap types. iterated_cache_get() is responsible for synchronizing the cache with the associated Hashmap and making it available to the caller at the supplied result pointers. Since iterated_cache_get() may need to allocate memory, it may fail, so callers must check the return value. On success, pointer arrays containing pointers to the associated Hashmap's keys and values, in as-iterated order, are returned in res_keys and res_values, respectively. Either may be supplied as NULL to inhibit caching of the keys or values, respectively. Note that if the cached Hashmap hasn't changed since the previous call to iterated_cache_get(), and it's not a call activating caching of the values or keys, the cost is effectively zero as the resulting pointers will simply refer to the previously returned arrays as-is. A cleanup function has also been added, iterated_cache_free(). This only frees the IteratedCache container and related arrays. The associated Hashmap, its keys, and values are not affected. Also note that the associated Hashmap does not automatically free its associated IteratedCache when freed. One could, in theory, safely access the arrays returned by a successful iterated_cache_get() call after its associated Hashmap has been freed, including the referenced values and keys. Provided the iterated_cache_get() was performed prior to the hashmap free, and that the type of hashmap free performed didn't free keys and/or values as well.
* basic: track dirty state in HashmapBaseVito Caputo2018-05-30
| | | | | | | This only adds marking the HashmapBase as dirty, no clearing of the dirty state happens yet. No functional changes.
* Prep v236 : Add missing SPDX-License-Identifier (2/9) src/basicSven Eden2018-03-26
|
* basic/hashmap: add cleanup of memory pools (#7164)Zbigniew Jędrzejewski-Szmek2017-11-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It was dropped in 89439d4fc0d29f04ac68432fd06ab84bc4e36e20. As a result, every process that uses a hashmap allocates and then leaks the hashmap mempools. The mempools are only allocated in the main thread, but we don't know where the memory is used. So let's check if we are the last thread and free the mempools then. This is fairly heavy, because /proc/self/status has to be opened and parsed, but we do it only when compiled for valgrind, i.e. not by default, and compared to running under valgrind or asan, the extra cost is acceptable. The big advantage is that we don't have to think or filter out this false positive. As a micro-opt, cleanup is attempted only in the main thread. We could allow any thread to check if it is the last one and perform cleanup, but that'd mean that we'd have to _do_ the check in every thread. We don't use threads like that, our non-main threads are always short-lived, so let's just accept the possibility that we'll leak memory if a thread survives. The check is also non-atomic, but it's called in a destructor of the main thread _and_ we do cleanup only when there are no other threads, so the risk of some library suddenly spawning another thread is very low. All in all, this is not perfect, but should work in 999‰ of cases. Fixes the following valgrind warning: ==22564== HEAP SUMMARY: ==22564== in use at exit: 8,192 bytes in 2 blocks ==22564== total heap usage: 243 allocs, 241 frees, 151,905 bytes allocated ==22564== ==22564== 4,096 bytes in 1 blocks are still reachable in loss record 1 of 2 ==22564== at 0x4C2FB6B: malloc (vg_replace_malloc.c:299) ==22564== by 0x4F08A8C: mempool_alloc_tile (mempool.c:62) ==22564== by 0x4F08B16: mempool_alloc0_tile (mempool.c:81) ==22564== by 0x4EF8DE0: hashmap_base_new (hashmap.c:748) ==22564== by 0x4EF8ED9: internal_hashmap_new (hashmap.c:782) ==22564== by 0x11045D: test_hashmap_copy (test-hashmap-plain.c:87) ==22564== by 0x115722: test_hashmap_funcs (test-hashmap-plain.c:914) ==22564== by 0x10FC9D: main (test-hashmap.c:60) ==22564== ==22564== 4,096 bytes in 1 blocks are still reachable in loss record 2 of 2 ==22564== at 0x4C2FB6B: malloc (vg_replace_malloc.c:299) ==22564== by 0x4F08A8C: mempool_alloc_tile (mempool.c:62) ==22564== by 0x4F08B16: mempool_alloc0_tile (mempool.c:81) ==22564== by 0x4EF8DE0: hashmap_base_new (hashmap.c:748) ==22564== by 0x4EF8EF8: internal_ordered_hashmap_new (hashmap.c:786) ==22564== by 0x10A2A0: test_ordered_hashmap_copy (test-hashmap-ordered.c:89) ==22564== by 0x10F70F: test_ordered_hashmap_funcs (test-hashmap-ordered.c:916) ==22564== by 0x10FCA2: main (test-hashmap.c:61) ==22564== ==22564== LEAK SUMMARY: ==22564== definitely lost: 0 bytes in 0 blocks ==22564== indirectly lost: 0 bytes in 0 blocks ==22564== possibly lost: 0 bytes in 0 blocks ==22564== still reachable: 8,192 bytes in 2 blocks ==22564== suppressed: 0 bytes in 0 blocks v2: - check if we are the main thread v3: - check if there are no other threads
* Apply missing updates from upstreamSven Eden2017-12-08
|
* tree-wide: use IN_SET macro (#6977)Yu Watanabe2017-12-08
|
* build-sys: use #if Y instead of #ifdef Y everywhereZbigniew Jędrzejewski-Szmek2017-11-23
| | | | | | | | | | | | | | | The advantage is that is the name is mispellt, cpp will warn us. $ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/" $ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;' $ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g' $ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g' + manual changes to meson.build squash! build-sys: use #if Y instead of #ifdef Y everywhere v2: - fix incorrect setting of HAVE_LIBIDN2
* tree-wide: use IN_SET where possibleAndreas Rammhold2017-09-29
| | | | | In addition to the changes from #6933 this handles cases that could be matched with the included cocci file.
* Prep v233.3: Unmask various functions for future coverage tests.Sven Eden2017-07-19
| | | | | These functions, although not used by elogind itself, are mostly tiny and crucial for important tests to work.
* Prep v231: Apply missing fixes from upstream (1/6) src/basicSven Eden2017-06-16
|
* Prep v230: Apply missing upstream fixes and updates (2/8) src/basic.Sven Eden2017-06-16
|
* hashmap: use void* and uint8_t* for generic pointersLennart Poettering2017-06-16
| | | | | | As suggested by CODING_STYLE we should use "void*" as type for generic memory, and uint8_t* for generic bytes. Hence use that instead of "char*", which should really be used only for strings these days.
* Prep v229: Remove remaining emacs settings [1/6] src/basicSven Eden2017-05-17
|
* basic: split hash functions into their own header filesLennart Poettering2017-05-17
| | | | The hash operations are not really that specific to hashmaps, hence split them into a .c module of their own.
* basic: ENABLE_DEBUG_HASHMAP needs <pthread.h>Henrik Kaare Poulsen2017-05-17
| | | | this is a follow-up for commit 11c3a36649e5e5e77db499c92f3
* basic: include only what we useThomas Hindoe Paaboel Andersen2017-05-17
| | | | | This is a cleaned up result of running iwyu but without forward declarations on src/basic.
* Prep v228: Condense elogind source masks (1/5)Sven Eden2017-04-26
| | | | | | | | | | | | Although having a two line mask like /// UNNEEDED by elogind #if 0 it is much more easier to read (and patch!) if those two lines were condense into a one-line mask start like #if 0 /// UNNEEDED by elogind
* Prep v228: Add remaining updates from upstream (2/3)Sven Eden2017-04-26
| | | | | Apply remaining fixes and the performed move of utility functions into their own foo-util.[hc] files on libbasic.
* [1/5] Apply missing fixes from upstreamSven Eden2017-03-29
|
* Prep v224: Major cleanup of unneeded functions and some source files.Sven Eden2017-03-14
|
* Prep v221: Update and clean up build system to sync with upstreamSven Eden2017-03-14
This commit replays the moving around of source files that have been done between systemd-219 and systemd-221. Further the Makefile.am is synchronized with the upstream version and then "re-cleaned". A lot of functions, that are not used anywhere in elogind have been coated into #if 0/#endif directives to further shorten the list of dependencies. All unneeded files have been removed.