Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a lockedMap type which implements tag.Map interface. The implementation contains tagMap instance and a mutex, so all the operations are forwarded to the tagMap under the locked mutex. An additional care was needed for the functions returning contents of the map, because core.Value contains a byte slice, which has pointer like semantics. So to avoid accidental changes, we copy the value if it is of BYTES type. This likely should be handled by the core.Value itself, e.g. through some Copy function. The downside of locking here is that the users of Foreach function need to be careful to not call into the same map, otherwise deadlock will happen. While writing this code I think I have got an understanding of the issue at hand - the implementation of the tag.Map should basically be immutable (so the modification of the map actually produces a new map, instead of doing in-place updates, thus making the map threadsafe), but that is not easy (or even possible) to enforce. So maybe it's indeed better to avoid providing the ability of having a different, vendor-specific implementation of tag.Map and have a good-by-default implemetation as a part of API. Still, to preserve the immutability of the map, the core.Value structs need to be deep-copied. Fixes #59
- Loading branch information