I can't say for the thing as a whole, but there are a few things that you may improve:
First, this macro:
#if defined(_DEBUG) && defined(_ROBUST_MUTEX_TRACE) #define IPC_DBG_TRACE(msg) { std::stringstream __str; __str << bipc::ipcdetail::get_current_system_highres_count() << " " << msg; xw::ipc::dbg_tracer::trace(__str); } #else #define IPC_DBG_TRACE(msg) #endif
It could use the
do { /* ... */ } while (0)
construct to avoid some rare but nasty problems with semi-colons and compiler warnings. The answers to this questionthis question provide more information. The macroXW_IPC_HANDLE_BROKEN_STATE
could also use some of those, just in case someone thinks it is a good idea to use the nameoldState
somewhere else.This expression seems a little bit overkill:
std::string mainFileName = (lockNameBase + "/main.lck").c_str();
Couldn't use simply write the following line instead? I suppose you have more chances to benefit from copy elision if you don't make several type transformations:
std::string mainFileName = lockNameBase + "/main.lck";
I know that the temporary created with
operator+
should exist until the end of the expression. I don't know however whether the initialization syntax using=
is part of the expression; I don't think that your code has undefined behaviour.Use the standard library algorithms when you can, especially if they lower the cognitive burden. For example, instead of this conditional:
_name[len < MAX_PATH ? len : MAX_PATH] = 0;
You can use
std::min
:_name[std::min(len, MAX_PATH)] = 0;
While it does not make a big difference, it really helps when you read it. I had to mentally parse the expression to know whether it did a
min
or amax
whilestd::min
makes it impossible to misread what's being done.