Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions include/tscpp/util/TsSharedMutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,19 @@ class Strerror
public:
Strerror(int err_num)
{
_c_str = strerror_r(err_num, _buf, 256);
if (!_c_str) {
// Handle either GNU or XSI version of strerror_r().
//
if (!_success(strerror_r(err_num, _buf, 256))) {
_c_str = "strerror_r() call failed";
} else {
_buf[255] = '\0';
_c_str = _buf;
}

// Make sure there are no unused function warnings.
//
static_cast<void>(_success(0));
static_cast<void>(_success(nullptr));
}

char const *
Expand All @@ -76,6 +83,18 @@ class Strerror
private:
char _buf[256];
char const *_c_str;

bool
_success(int retval)
{
return retval == 0;
}

bool
_success(char *retval)
{
return retval != nullptr;
}
};

// A class with the same interface as std::shared_mutex, but which is not prone to writer starvation.
Expand Down Expand Up @@ -200,7 +219,7 @@ class shared_mutex
#endif
#endif

void
static void
_call_fatal(char const *func_name, void *ptr, int errnum)
{
TSFatal("%s(%p) failed: %s (%d)", func_name, ptr, Strerror(errnum).c_str(), errnum);
Expand Down