The aim here is to prevent a race conditions not appearing in debug mode
and but only in release mode (which would actually mak debugging
harder). The drawback is that in release mode subscription, which does
not occur too frequently, is now more expensive.
void
Subscriptor::subscribe(const char *id) const
{
-#ifdef DEBUG
if (object_info == nullptr)
object_info = &typeid(*this);
++counter;
else
it->second++;
-#else
- (void)id;
-#endif
}
void
Subscriptor::unsubscribe(const char *id) const
{
-#ifdef DEBUG
const char *name = (id != nullptr) ? id : unknown_subscriber;
AssertNothrow(counter > 0, ExcNoSubscriber(object_info->name(), name));
// This is for the case that we do
AssertNothrow(it->second > 0, ExcNoSubscriber(object_info->name(), name));
it->second--;
-#else
- (void)id;
-#endif
}
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams