common: make 'emit_once', 'emit_once_reset' thread safe
This is an alternative to !4692
By using a global in a thread-unsafe way, this logic was a barrier to
introducing multi-threading here in future. Though it is not guaranteed that the
caller of emit_once will be printing their eventual warning/error to stderr,
this is generally the default configuration. Taking a lock on stderr here can
result in false sharing¹ but in the common case it will be uncontended.
This is an alternative to a prior proposed change that introduced a more conventional mutex for protecting this logic (!4692). The complexity of a platform-independent mutex does not seem to be worthwhile at this point.
¹ emit_once and emit_once_reset are not using stderr other than for this
lock. So it is possible for another thread doing unrelated printing to stderr
to block a thread calling emit_once/emit_once_reset, or vice versa. These
blocks unnecessarily degrade throughput (both operations could proceed
concurrently) but this scenario should be unusual.