Uncrustify maxscale

See script directory for method. The script to run in the top level
MaxScale directory is called maxscale-uncrustify.sh, which uses
another script, list-src, from the same directory (so you need to set
your PATH). The uncrustify version was 0.66.
This commit is contained in:
Niclas Antti
2018-09-09 22:26:19 +03:00
parent fa7ec95069
commit c447e5cf15
849 changed files with 35002 additions and 27238 deletions

View File

@ -17,93 +17,97 @@
* @file atomic.c - Implementation of atomic operations
*/
int atomic_add(int *variable, int value)
int atomic_add(int* variable, int value)
{
return __atomic_fetch_add(variable, value, __ATOMIC_SEQ_CST);
}
uint32_t atomic_add_uint32(uint32_t *variable, int32_t value)
uint32_t atomic_add_uint32(uint32_t* variable, int32_t value)
{
return __atomic_fetch_add(variable, value, __ATOMIC_SEQ_CST);
}
int64_t atomic_add_int64(int64_t *variable, int64_t value)
int64_t atomic_add_int64(int64_t* variable, int64_t value)
{
return __atomic_fetch_add(variable, value, __ATOMIC_SEQ_CST);
}
uint64_t atomic_add_uint64(uint64_t *variable, int64_t value)
uint64_t atomic_add_uint64(uint64_t* variable, int64_t value)
{
return __atomic_fetch_add(variable, value, __ATOMIC_SEQ_CST);
}
int atomic_load_int(const int *variable)
int atomic_load_int(const int* variable)
{
return __atomic_load_n(variable, __ATOMIC_SEQ_CST);
}
int32_t atomic_load_int32(const int32_t *variable)
int32_t atomic_load_int32(const int32_t* variable)
{
return __atomic_load_n(variable, __ATOMIC_SEQ_CST);
}
int64_t atomic_load_int64(const int64_t *variable)
int64_t atomic_load_int64(const int64_t* variable)
{
return __atomic_load_n(variable, __ATOMIC_SEQ_CST);
}
uint32_t atomic_load_uint32(const uint32_t *variable)
uint32_t atomic_load_uint32(const uint32_t* variable)
{
return __atomic_load_n(variable, __ATOMIC_SEQ_CST);
}
uint64_t atomic_load_uint64(const uint64_t *variable)
uint64_t atomic_load_uint64(const uint64_t* variable)
{
return __atomic_load_n(variable, __ATOMIC_SEQ_CST);
}
void* atomic_load_ptr(void * const *variable)
void* atomic_load_ptr(void* const* variable)
{
return __atomic_load_n(variable, __ATOMIC_SEQ_CST);
}
void atomic_store_int(int *variable, int value)
void atomic_store_int(int* variable, int value)
{
__atomic_store_n(variable, value, __ATOMIC_SEQ_CST);
}
void atomic_store_int32(int32_t *variable, int32_t value)
void atomic_store_int32(int32_t* variable, int32_t value)
{
__atomic_store_n(variable, value, __ATOMIC_SEQ_CST);
}
void atomic_store_int64(int64_t *variable, int64_t value)
void atomic_store_int64(int64_t* variable, int64_t value)
{
__atomic_store_n(variable, value, __ATOMIC_SEQ_CST);
}
void atomic_store_uint32(uint32_t *variable, uint32_t value)
void atomic_store_uint32(uint32_t* variable, uint32_t value)
{
__atomic_store_n(variable, value, __ATOMIC_SEQ_CST);
}
void atomic_store_uint64(uint64_t *variable, uint64_t value)
void atomic_store_uint64(uint64_t* variable, uint64_t value)
{
__atomic_store_n(variable, value, __ATOMIC_SEQ_CST);
}
void atomic_store_ptr(void **variable, void *value)
void atomic_store_ptr(void** variable, void* value)
{
__atomic_store_n(variable, value, __ATOMIC_SEQ_CST);
}
bool atomic_cas_ptr(void **variable, void** old_value, void *new_value)
bool atomic_cas_ptr(void** variable, void** old_value, void* new_value)
{
return __atomic_compare_exchange_n(variable, old_value, new_value,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
return __atomic_compare_exchange_n(variable,
old_value,
new_value,
false,
__ATOMIC_SEQ_CST,
__ATOMIC_SEQ_CST);
}
int atomic_exchange_int(int *variable, int new_value)
int atomic_exchange_int(int* variable, int new_value)
{
return __atomic_exchange_n(variable, new_value, __ATOMIC_SEQ_CST);
}

View File

@ -43,7 +43,7 @@ int CumulativeAverage::num_samples() const
return m_num_samples;
}
CumulativeAverage &CumulativeAverage::operator+=(const CumulativeAverage& rhs)
CumulativeAverage& CumulativeAverage::operator+=(const CumulativeAverage& rhs)
{
this->add(rhs.m_ave, rhs.m_num_samples);
return *this;
@ -61,10 +61,10 @@ void CumulativeAverage::reset()
m_num_last_added = 0;
}
EMAverage::EMAverage(double min_alpha, double max_alpha, int sample_max) :
m_min_alpha{min_alpha},
m_max_alpha{max_alpha},
m_sample_max{sample_max}
EMAverage::EMAverage(double min_alpha, double max_alpha, int sample_max)
: m_min_alpha{min_alpha}
, m_max_alpha{max_alpha}
, m_sample_max{sample_max}
{
}
@ -73,8 +73,8 @@ void EMAverage::add(double ave, int num_samples)
// Give more weight to initial samples.
int sample_max = std::min(m_num_samples ? m_num_samples : 1, m_sample_max);
double alpha = m_min_alpha + m_max_alpha *
std::min(double(num_samples) / sample_max, 1.0);
double alpha = m_min_alpha + m_max_alpha
* std::min(double(num_samples) / sample_max, 1.0);
m_num_samples += num_samples;
if (m_num_samples == num_samples)
@ -117,6 +117,4 @@ void EMAverage::reset()
m_ave = 0;
m_num_samples = 0;
}
} // maxbase
} // maxbase

View File

@ -22,10 +22,10 @@
namespace maxbase
{
EventCount::EventCount(const std::string& event_id, Duration time_window, Duration granularity) :
m_event_id(event_id),
m_time_window(time_window),
m_granularity(granularity.count())
EventCount::EventCount(const std::string& event_id, Duration time_window, Duration granularity)
: m_event_id(event_id)
, m_time_window(time_window)
, m_granularity(granularity.count())
{
increment();
}
@ -55,7 +55,9 @@ namespace
struct TimePointLessEqual
{
TimePoint lhs;
TimePointLessEqual(TimePoint tp) : lhs(tp) {}
TimePointLessEqual(TimePoint tp) : lhs(tp)
{
}
bool operator()(const EventCount::Timestamp& rhs) const
{
return lhs <= rhs.time_point;
@ -72,7 +74,8 @@ void EventCount::purge() const
StopWatch sw;
auto windowBegin = Clock::now() - m_time_window;
auto ite = std::find_if(m_timestamps.begin(), m_timestamps.end(),
auto ite = std::find_if(m_timestamps.begin(),
m_timestamps.end(),
TimePointLessEqual(windowBegin));
m_timestamps.erase(m_timestamps.begin(), ite);
}
@ -89,7 +92,7 @@ int EventCount::count() const
return count;
}
void EventCount::dump(std::ostream &os) const
void EventCount::dump(std::ostream& os) const
{
os << m_event_id << ": " << count() << " " << m_timestamps.size();
}
@ -104,14 +107,17 @@ std::ostream& operator<<(std::ostream& os, const EventCount& EventCount)
// a client generates lots of events but rarely reads them back (purges).
const int CleanupCountdown = 10000;
SessionCount::SessionCount(const std::string& sess_id, Duration time_window,
Duration granularity) :
m_sess_id(sess_id), m_time_window(time_window), m_granularity(granularity),
m_cleanup_countdown(CleanupCountdown)
SessionCount::SessionCount(const std::string& sess_id,
Duration time_window,
Duration granularity)
: m_sess_id(sess_id)
, m_time_window(time_window)
, m_granularity(granularity)
, m_cleanup_countdown(CleanupCountdown)
{
}
const std::vector<EventCount> &SessionCount::event_counts() const
const std::vector<EventCount>& SessionCount::event_counts() const
{
purge();
return m_event_counts;
@ -128,7 +134,9 @@ namespace
struct MatchEventId
{
std::string event_id;
MatchEventId(const std::string& id) : event_id(id) {};
MatchEventId(const std::string& id) : event_id(id)
{
}
bool operator()(const EventCount& stats) const
{
return event_id == stats.event_id();
@ -143,7 +151,8 @@ void SessionCount::increment(const std::string& event_id)
// Find in reverse, the entry is more likely to be towards the end. Actually no,
// for some reason the normal search is slightly faster when measured.
auto ite = find_if(m_event_counts.begin(), m_event_counts.end(),
auto ite = find_if(m_event_counts.begin(),
m_event_counts.end(),
MatchEventId(event_id));
if (ite == m_event_counts.end())
{
@ -221,7 +230,7 @@ void dump(std::ostream& os, const std::vector<SessionCount>& sessions)
}
}
void dumpTotals(std::ostream& os, const std::vector<SessionCount> &sessions)
void dumpTotals(std::ostream& os, const std::vector<SessionCount>& sessions)
{
if (sessions.empty())
{
@ -251,15 +260,15 @@ void dumpTotals(std::ostream& os, const std::vector<SessionCount> &sessions)
// EXTRA
// This section needed for gcc 4.4, to use move semantics and variadics.
EventCount::EventCount(EventCount && ss) :
m_event_id(std::move(ss.m_event_id)),
m_time_window(std::move(ss.m_time_window)),
m_granularity(std::move(ss.m_granularity)),
m_timestamps(std::move(ss.m_timestamps))
EventCount::EventCount(EventCount&& ss)
: m_event_id(std::move(ss.m_event_id))
, m_time_window(std::move(ss.m_time_window))
, m_granularity(std::move(ss.m_granularity))
, m_timestamps(std::move(ss.m_timestamps))
{
}
EventCount &EventCount::operator=(EventCount && ss)
EventCount& EventCount::operator=(EventCount&& ss)
{
m_event_id = std::move(ss.m_event_id);
m_time_window = std::move(ss.m_time_window);
@ -268,16 +277,16 @@ EventCount &EventCount::operator=(EventCount && ss)
return *this;
}
SessionCount::SessionCount(SessionCount&& ss) :
m_sess_id(std::move(ss.m_sess_id)),
m_time_window(std::move(ss.m_time_window)),
m_granularity(std::move(ss.m_granularity)),
m_cleanup_countdown(std::move(ss.m_cleanup_countdown)),
m_event_counts(std::move(ss.m_event_counts))
SessionCount::SessionCount(SessionCount&& ss)
: m_sess_id(std::move(ss.m_sess_id))
, m_time_window(std::move(ss.m_time_window))
, m_granularity(std::move(ss.m_granularity))
, m_cleanup_countdown(std::move(ss.m_cleanup_countdown))
, m_event_counts(std::move(ss.m_event_counts))
{
}
SessionCount & SessionCount::operator=(SessionCount&& ss)
SessionCount& SessionCount::operator=(SessionCount&& ss)
{
m_sess_id = std::move(ss.m_sess_id);
m_time_window = std::move(ss.m_time_window);
@ -287,4 +296,4 @@ SessionCount & SessionCount::operator=(SessionCount&& ss)
return *this;
}
} // maxbase
} // maxbase

View File

@ -41,7 +41,7 @@ namespace
int DEFAULT_LOG_AUGMENTATION = 0;
// A message that is logged 10 times in 1 second will be suppressed for 10 seconds.
static MXB_LOG_THROTTLING DEFAULT_LOG_THROTTLING = { 10, 1000, 10000 };
static MXB_LOG_THROTTLING DEFAULT_LOG_THROTTLING = {10, 1000, 10000};
// BUFSIZ comes from the system. It equals with block size or its multiplication.
const int MAX_LOGSTRLEN = BUFSIZ;
@ -62,14 +62,26 @@ std::string get_timestamp(void)
struct tm tm;
localtime_r(&t, &tm);
static const char timestamp_formatstr[] = "%04d-%02d-%02d %02d:%02d:%02d ";
static int required = snprintf(NULL, 0, timestamp_formatstr,
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
tm.tm_min, tm.tm_sec);
static int required = snprintf(NULL,
0,
timestamp_formatstr,
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec);
char buf[required + 1];
snprintf(buf, sizeof(buf), timestamp_formatstr,
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
tm.tm_min, tm.tm_sec);
snprintf(buf,
sizeof(buf),
timestamp_formatstr,
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec);
return buf;
}
@ -84,33 +96,47 @@ std::string get_timestamp_hp(void)
int usec = tv.tv_usec / 1000;
static const char timestamp_formatstr_hp[] = "%04d-%02d-%02d %02d:%02d:%02d.%03d ";
static int required = snprintf(NULL, 0, timestamp_formatstr_hp,
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, usec);
static int required = snprintf(NULL,
0,
timestamp_formatstr_hp,
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
usec);
char buf[required + 1];
snprintf(buf, sizeof(buf), timestamp_formatstr_hp,
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, usec);
snprintf(buf,
sizeof(buf),
timestamp_formatstr_hp,
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
usec);
return buf;
}
struct LOG_PREFIX
{
const char* text; // The prefix, e.g. "error: "
int len; // The length of the prefix without the trailing NULL.
const char* text; // The prefix, e.g. "error: "
int len; // The length of the prefix without the trailing NULL.
};
const char PREFIX_EMERG[] = "emerg : ";
const char PREFIX_ALERT[] = "alert : ";
const char PREFIX_CRIT[] = "crit : ";
const char PREFIX_ERROR[] = "error : ";
const char PREFIX_EMERG[] = "emerg : ";
const char PREFIX_ALERT[] = "alert : ";
const char PREFIX_CRIT[] = "crit : ";
const char PREFIX_ERROR[] = "error : ";
const char PREFIX_WARNING[] = "warning: ";
const char PREFIX_NOTICE[] = "notice : ";
const char PREFIX_INFO[] = "info : ";
const char PREFIX_DEBUG[] = "debug : ";
const char PREFIX_NOTICE[] = "notice : ";
const char PREFIX_INFO[] = "info : ";
const char PREFIX_DEBUG[] = "debug : ";
LOG_PREFIX level_to_prefix(int level)
{
@ -167,16 +193,16 @@ LOG_PREFIX level_to_prefix(int level)
break;
}
--prefix.len; // Remove trailing NULL.
--prefix.len; // Remove trailing NULL.
return prefix;
}
enum message_suppression_t
{
MESSAGE_NOT_SUPPRESSED, // Message is not suppressed.
MESSAGE_SUPPRESSED, // Message is suppressed for the first time (for this round)
MESSAGE_STILL_SUPPRESSED // Message is still suppressed (for this round)
MESSAGE_NOT_SUPPRESSED, // Message is not suppressed.
MESSAGE_SUPPRESSED, // Message is suppressed for the first time (for this round)
MESSAGE_STILL_SUPPRESSED // Message is still suppressed (for this round)
};
class MessageRegistryKey
@ -200,9 +226,8 @@ public:
bool eq(const MessageRegistryKey& other) const
{
return
filename == other.filename && // Yes, we compare the pointer values and not the strings.
linenumber == other.linenumber;
return filename == other.filename // Yes, we compare the pointer values and not the strings.
&& linenumber == other.linenumber;
}
size_t hash() const
@ -212,7 +237,7 @@ public:
* https://en.wikipedia.org/wiki/Jenkins_hash_function
*/
uint64_t key1 = (uint64_t)filename;
uint16_t key2 = (uint16_t)linenumber; // The first 48 bits are likely to be 0.
uint16_t key2 = (uint16_t)linenumber; // The first 48 bits are likely to be 0.
uint32_t hash_value = 0;
size_t i;
@ -313,11 +338,10 @@ public:
private:
std::mutex m_lock;
uint64_t m_first_ms; /** The time when the error was logged the first time in this window. */
uint64_t m_last_ms; /** The time when the error was logged the last time. */
size_t m_count; /** How many times the error has been reported within this window. */
uint64_t m_first_ms; /** The time when the error was logged the first time in this window. */
uint64_t m_last_ms; /** The time when the error was logged the last time. */
size_t m_count; /** How many times the error has been reported within this window. */
};
}
namespace std
@ -347,7 +371,6 @@ struct equal_to<MessageRegistryKey>
return lhs.eq(rhs);
}
};
}
namespace
@ -357,21 +380,21 @@ class MessageRegistry;
struct this_unit
{
int augmentation; // Can change during the lifetime of log_manager.
bool do_highprecision; // Can change during the lifetime of log_manager.
bool do_syslog; // Can change during the lifetime of log_manager.
bool do_maxlog; // Can change during the lifetime of log_manager.
MXB_LOG_THROTTLING throttling; // Can change during the lifetime of log_manager.
int augmentation; // Can change during the lifetime of log_manager.
bool do_highprecision; // Can change during the lifetime of log_manager.
bool do_syslog; // Can change during the lifetime of log_manager.
bool do_maxlog; // Can change during the lifetime of log_manager.
MXB_LOG_THROTTLING throttling; // Can change during the lifetime of log_manager.
std::unique_ptr<mxb::Logger> sLogger;
std::unique_ptr<MessageRegistry> sMessage_registry;
size_t (*context_provider)(char* buffer, size_t len);
size_t (* context_provider)(char* buffer, size_t len);
} this_unit =
{
DEFAULT_LOG_AUGMENTATION, // augmentation
false, // do_highprecision
true, // do_syslog
true, // do_maxlog
DEFAULT_LOG_THROTTLING, // throttling
DEFAULT_LOG_AUGMENTATION, // augmentation
false, // do_highprecision
true, // do_syslog
true, // do_maxlog
DEFAULT_LOG_THROTTLING, // throttling
};
class MessageRegistry
@ -417,7 +440,6 @@ private:
std::mutex m_lock;
std::unordered_map<Key, Stats> m_registry;
};
}
bool mxb_log_init(const char* ident,
@ -457,22 +479,22 @@ bool mxb_log_init(const char* ident,
filepath = std::string(logdir) + "/" + suffix;
}
this_unit.sMessage_registry.reset(new (std::nothrow) MessageRegistry);
this_unit.sMessage_registry.reset(new( std::nothrow) MessageRegistry);
switch (target)
{
case MXB_LOG_TARGET_FS:
case MXB_LOG_TARGET_DEFAULT:
this_unit.sLogger = mxb::FileLogger::create(filepath);
break;
case MXB_LOG_TARGET_FS:
case MXB_LOG_TARGET_DEFAULT:
this_unit.sLogger = mxb::FileLogger::create(filepath);
break;
case MXB_LOG_TARGET_STDOUT:
this_unit.sLogger = mxb::StdoutLogger::create(filepath);
break;
case MXB_LOG_TARGET_STDOUT:
this_unit.sLogger = mxb::StdoutLogger::create(filepath);
break;
default:
assert(!true);
break;
default:
assert(!true);
break;
}
if (this_unit.sLogger && this_unit.sMessage_registry)
@ -552,9 +574,9 @@ void mxb_log_set_throttling(const MXB_LOG_THROTTLING* throttling)
// is used right when its values are modified.
this_unit.throttling = *throttling;
if ((this_unit.throttling.count == 0) ||
(this_unit.throttling.window_ms == 0) ||
(this_unit.throttling.suppress_ms == 0))
if ((this_unit.throttling.count == 0)
|| (this_unit.throttling.window_ms == 0)
|| (this_unit.throttling.suppress_ms == 0))
{
MXB_NOTICE("Log throttling has been disabled.");
}
@ -592,20 +614,28 @@ static const char* level_to_string(int level)
{
case LOG_EMERG:
return "emergency";
case LOG_ALERT:
return "alert";
case LOG_CRIT:
return "critical";
case LOG_ERR:
return "error";
case LOG_WARNING:
return "warning";
case LOG_NOTICE:
return "notice";
case LOG_INFO:
return "informational";
case LOG_DEBUG:
return "debug";
default:
assert(!true);
return "unknown";
@ -643,8 +673,11 @@ bool mxb_log_set_priority_enabled(int level, bool enable)
int mxb_log_message(int priority,
const char* modname,
const char* file, int line, const char* function,
const char* format, ...)
const char* file,
int line,
const char* function,
const char* format,
...)
{
int err = 0;
@ -653,7 +686,7 @@ int mxb_log_message(int priority,
int level = priority & LOG_PRIMASK;
if ((priority & ~(LOG_PRIMASK | LOG_FACMASK)) == 0) // Check that the priority is ok,
if ((priority & ~(LOG_PRIMASK | LOG_FACMASK)) == 0) // Check that the priority is ok,
{
message_suppression_t status = MESSAGE_NOT_SUPPRESSED;
@ -671,7 +704,7 @@ int mxb_log_message(int priority,
{
va_list valist;
char context[32]; // The documentation will guarantee a buffer of at least 32 bytes.
char context[32]; // The documentation will guarantee a buffer of at least 32 bytes.
int context_len = 0;
if (this_unit.context_provider)
@ -680,21 +713,21 @@ int mxb_log_message(int priority,
if (context_len != 0)
{
context_len += 3; // The added "() "
context_len += 3; // The added "() "
}
}
int modname_len = modname ? strlen(modname) + 3 : 0; // +3 due to "[...] "
int modname_len = modname ? strlen(modname) + 3 : 0; // +3 due to "[...] "
static const char SUPPRESSION[] =
" (subsequent similar messages suppressed for %lu milliseconds)";
static const char SUPPRESSION[]
= " (subsequent similar messages suppressed for %lu milliseconds)";
int suppression_len = 0;
size_t suppress_ms = this_unit.throttling.suppress_ms;
if (status == MESSAGE_SUPPRESSED)
{
suppression_len += sizeof(SUPPRESSION) - 1; // Remove trailing NULL
suppression_len -= 3; // Remove the %lu
suppression_len -= 3; // Remove the %lu
suppression_len += UINTLEN(suppress_ms);
}
@ -719,7 +752,7 @@ int mxb_log_message(int priority,
{
case MXB_LOG_AUGMENT_WITH_FUNCTION:
augmentation_len = sizeof(FORMAT_FUNCTION) - 1; // Remove trailing 0
augmentation_len -= 2; // Remove the %s
augmentation_len -= 2; // Remove the %s
augmentation_len += strlen(function);
break;
@ -740,18 +773,18 @@ int mxb_log_message(int priority,
message_len -= (buffer_len - MAX_LOGSTRLEN);
buffer_len = MAX_LOGSTRLEN;
assert(prefix.len + context_len + modname_len +
augmentation_len + message_len + suppression_len == buffer_len);
assert(prefix.len + context_len + modname_len
+ augmentation_len + message_len + suppression_len == buffer_len);
}
char buffer[buffer_len + 1];
char *prefix_text = buffer;
char *context_text = prefix_text + prefix.len;
char *modname_text = context_text + context_len;
char *augmentation_text = modname_text + modname_len;
char *message_text = augmentation_text + augmentation_len;
char *suppression_text = message_text + message_len;
char* prefix_text = buffer;
char* context_text = prefix_text + prefix.len;
char* modname_text = context_text + context_len;
char* augmentation_text = modname_text + modname_len;
char* message_text = augmentation_text + augmentation_len;
char* suppression_text = message_text + message_len;
strcpy(prefix_text, prefix.text);

View File

@ -30,7 +30,7 @@
*
* For obvious reasons, it cannot use its own functions for reporting errors.
*/
#define LOG_ERROR(format, ...) do { fprintf(stderr, format, ##__VA_ARGS__); } while (false)
#define LOG_ERROR(format, ...) do {fprintf(stderr, format, ##__VA_ARGS__);} while (false)
//
// Helper functions
@ -40,7 +40,8 @@ namespace
int open_fd(const std::string& filename)
{
int fd = open(filename.c_str(), O_WRONLY | O_APPEND | O_CREAT,
int fd = open(filename.c_str(),
O_WRONLY | O_APPEND | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
if (fd == -1)
@ -85,7 +86,6 @@ std::string get_ident()
return this_unit.ident;
}
}
namespace maxbase
@ -108,7 +108,7 @@ std::unique_ptr<Logger> FileLogger::create(const std::string& filename)
if (fd != -1)
{
logger.reset(new (std::nothrow) FileLogger(fd, filename));
logger.reset(new( std::nothrow) FileLogger(fd, filename));
if (logger)
{
@ -151,7 +151,7 @@ bool FileLogger::write(const char* msg, int len)
if (rc == -1)
{
if (should_log_error()) // Coarse error suppression
if (should_log_error()) // Coarse error suppression
{
LOG_ERROR("Failed to write to log: %d, %s\n", errno, mxb_strerror(errno));
}
@ -186,9 +186,9 @@ bool FileLogger::rotate()
// Private methods
//
FileLogger::FileLogger(int fd, const std::string& filename):
Logger(filename),
m_fd(fd)
FileLogger::FileLogger(int fd, const std::string& filename)
: Logger(filename)
, m_fd(fd)
{
}
@ -207,25 +207,27 @@ bool FileLogger::write_header()
localtime_r(&t, &tm);
std::string ident = get_ident();
char time_string[32]; // 26 would be enough, according to "man asctime".
char time_string[32]; // 26 would be enough, according to "man asctime".
asctime_r(&tm, time_string);
size_t size = ident.length() + 2 * sizeof(' ') + m_filename.length() + 2 * sizeof(' ') + strlen(time_string);
size_t size = ident.length() + 2 * sizeof(' ') + m_filename.length() + 2 * sizeof(' ') + strlen(
time_string);
char header[size + 2 + 1]; // For the 2 newlines and the trailing NULL.
char header[size + 2 + 1]; // For the 2 newlines and the trailing NULL.
sprintf(header, "\n\n%s %s %s", ident.c_str(), m_filename.c_str(), time_string);
char line[sizeof(header) - 1];
memset(line, '-', sizeof(line) - 1);
line[sizeof(line) - 1] = '\n';
bool ok = ::write(m_fd, header, sizeof(header) - 1) != -1 &&
::write(m_fd, line, sizeof(line)) != -1;
bool ok = ::write(m_fd, header, sizeof(header) - 1) != -1
&& ::write(m_fd, line, sizeof(line)) != -1;
if (!ok)
{
LOG_ERROR("Error: Writing log header failed due to %d, %s\n",
errno, mxb_strerror(errno));
errno,
mxb_strerror(errno));
}
return ok;
@ -239,10 +241,16 @@ bool FileLogger::write_footer(const char* suffix)
localtime_r(&t, &tm);
const char FORMAT[] = "%04d-%02d-%02d %02d:%02d:%02d";
char time_string[20]; // 19 chars + NULL.
char time_string[20]; // 19 chars + NULL.
sprintf(time_string, FORMAT,
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
sprintf(time_string,
FORMAT,
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec);
size_t size = sizeof(time_string) + 3 * sizeof(' ') + strlen(suffix) + sizeof('\n');
@ -253,16 +261,16 @@ bool FileLogger::write_footer(const char* suffix)
memset(line, '-', sizeof(line) - 1);
line[sizeof(line) - 1] = '\n';
bool ok = ::write(m_fd, header, sizeof(header) - 1) != -1 &&
::write(m_fd, line, sizeof(line)) != -1;
bool ok = ::write(m_fd, header, sizeof(header) - 1) != -1
&& ::write(m_fd, line, sizeof(line)) != -1;
if (!ok)
{
LOG_ERROR("Error: Writing log footer failed due to %d, %s\n",
errno, mxb_strerror(errno));
errno,
mxb_strerror(errno));
}
return ok;
}
}

View File

@ -65,8 +65,8 @@ public:
}
private:
typedef bool (*init_function_t)();
typedef void (*finish_function_t)();
typedef bool (* init_function_t)();
typedef void (* finish_function_t)();
struct component_t
{
@ -78,7 +78,7 @@ private:
static int s_nComponents;
};
#define MAXBASE_COMPONENT(X) { &X::init, &X::finish }
#define MAXBASE_COMPONENT(X) {&X::init, &X::finish}
Initer::component_t Initer::s_components[] =
{
@ -103,9 +103,9 @@ MaxBase::MaxBase(const char* zIdent,
if (!m_log_inited)
{
zMessage =
"The initialization of the MaxScale base library succeeded, but the "
"initialization of the MaxScale log failed.";
zMessage
= "The initialization of the MaxScale base library succeeded, but the "
"initialization of the MaxScale log failed.";
}
}
else
@ -160,7 +160,6 @@ void finish()
{
Initer::finish();
}
}
bool maxbase_init()

View File

@ -36,7 +36,7 @@ static struct
int get_pipe_max_size()
{
int size = 65536; // Default value from pipe(7)
int size = 65536; // Default value from pipe(7)
std::ifstream file("/proc/sys/fs/pipe-max-size");
if (file.good())
@ -46,7 +46,6 @@ int get_pipe_max_size()
return size;
}
}
namespace maxbase
@ -75,7 +74,7 @@ MessageQueue::~MessageQueue()
close(m_write_fd);
}
//static
// static
bool MessageQueue::init()
{
mxb_assert(!this_unit.initialized);
@ -86,14 +85,14 @@ bool MessageQueue::init()
return this_unit.initialized;
}
//static
// static
void MessageQueue::finish()
{
mxb_assert(this_unit.initialized);
this_unit.initialized = false;
}
//static
// static
MessageQueue* MessageQueue::create(Handler* pHandler)
{
mxb_assert(this_unit.initialized);
@ -148,10 +147,12 @@ MessageQueue* MessageQueue::create(Handler* pHandler)
if (fcntl(fds[0], F_SETPIPE_SZ, this_unit.pipe_max_size) == -1)
{
MXB_WARNING("Failed to increase pipe buffer size to '%d': %d, %s",
this_unit.pipe_max_size, errno, mxb_strerror(errno));
this_unit.pipe_max_size,
errno,
mxb_strerror(errno));
}
#endif
pThis = new (std::nothrow) MessageQueue(pHandler, read_fd, write_fd);
pThis = new( std::nothrow) MessageQueue(pHandler, read_fd, write_fd);
if (!pThis)
{
@ -303,7 +304,9 @@ uint32_t MessageQueue::handle_poll_events(Worker* pWorker, uint32_t events)
// mode we continue reading in order to empty the pipe as otherwise the
// thread may hang.
MXB_ERROR("MessageQueue could only read %ld bytes from pipe, although "
"expected %lu bytes.", n, sizeof(message));
"expected %lu bytes.",
n,
sizeof(message));
mxb_assert(!true);
}
}
@ -315,12 +318,11 @@ uint32_t MessageQueue::handle_poll_events(Worker* pWorker, uint32_t events)
return rc;
}
//static
// static
uint32_t MessageQueue::poll_handler(MXB_POLL_DATA* pData, MXB_WORKER* pWorker, uint32_t events)
{
MessageQueue* pThis = static_cast<MessageQueue*>(pData);
return pThis->handle_poll_events(static_cast<Worker*>(pWorker), events);
}
}

View File

@ -17,9 +17,9 @@
namespace maxbase
{
//static
// static
void Semaphore::get_current_timespec(time_t seconds,
long nseconds,
long nseconds,
timespec* pTs)
{
mxb_assert(nseconds <= 999999999);
@ -41,5 +41,4 @@ void Semaphore::get_current_timespec(time_t seconds,
ts.tv_nsec = nseconds_sum;
}
}

View File

@ -93,17 +93,21 @@ static void extract_file_and_line(const char* symbols, char* cmd, size_t size)
snprintf(offset, sizeof(offset), "%.*s", (int)(symname_end - addr_offset), addr_offset);
// Get the hexadecimal address of the symbol
get_command_output(cmd, size,
get_command_output(cmd,
size,
"nm %s |grep ' %s$'|sed -e 's/ .*//' -e 's/^/0x/'",
filename, symname);
filename,
symname);
long long symaddr = strtoll(cmd, NULL, 16);
long long offsetaddr = strtoll(offset, NULL, 16);
// Calculate the file and line now that we have the raw offset into
// the library
get_command_output(cmd, size,
get_command_output(cmd,
size,
"addr2line -e %s 0x%x",
filename, symaddr + offsetaddr);
filename,
symaddr + offsetaddr);
}
else
{
@ -114,7 +118,6 @@ static void extract_file_and_line(const char* symbols, char* cmd, size_t size)
}
}
}
}
namespace maxbase
@ -122,7 +125,7 @@ namespace maxbase
void dump_stacktrace(std::function<void(const char*, const char*)> handler)
{
void *addrs[128];
void* addrs[128];
int count = backtrace(addrs, 128);
char** symbols = backtrace_symbols(addrs, count);
@ -138,11 +141,12 @@ void dump_stacktrace(std::function<void(const char*, const char*)> handler)
}
}
void dump_stacktrace(void (*handler)(const char* symbol, const char* command))
void dump_stacktrace(void (* handler)(const char* symbol, const char* command))
{
dump_stacktrace([&](const char* symbol, const char* command){handler(symbol, command);});
dump_stacktrace([&](const char* symbol, const char* command) {
handler(symbol, command);
});
}
}
#else
@ -150,11 +154,10 @@ void dump_stacktrace(void (*handler)(const char* symbol, const char* command))
namespace maxbase
{
void dump_stacktrace(void (*handler)(const char*, const char*))
void dump_stacktrace(void (* handler)(const char*, const char*))
{
// We can't dump stacktraces on non-GLIBC systems
}
}
#endif

View File

@ -38,7 +38,7 @@ Duration StopWatch::restart()
m_start = now;
return lap;
}
} // maxbase
} // maxbase
/********** OUTPUT ***********/
namespace
@ -46,21 +46,20 @@ namespace
using namespace maxbase;
struct TimeConvert
{
double div; // divide the value of the previous unit by this
std::string suffix; // milliseconds, hours etc.
double max_visual; // threashold to switch to the next unit
double div; // divide the value of the previous unit by this
std::string suffix; // milliseconds, hours etc.
double max_visual; // threashold to switch to the next unit
};
// Will never get to centuries because the duration is a long carrying nanoseconds
TimeConvert convert[]
{
{1, "ns", 1000}, {1000, "us", 1000}, {1000, "ms", 1000},
{1, "ns", 1000}, {1000, "us", 1000}, {1000, "ms", 1000},
{1000, "s", 60}, {60, "min", 60}, {60, "hours", 24},
{24, "days", 365.25}, {365.25, "years", 10000},
{100, "centuries", std::numeric_limits<double>::max()}
};
int convert_size = sizeof(convert) / sizeof(convert[0]);
}
namespace maxbase
@ -87,7 +86,7 @@ std::pair<double, std::string> dur_to_human_readable(Duration dur)
}
}
abort(); // should never get here
abort(); // should never get here
}
std::ostream& operator<<(std::ostream& os, Duration dur)
@ -101,13 +100,13 @@ std::ostream& operator<<(std::ostream& os, Duration dur)
// TODO: this will require some thought. time_point_to_string() for a system_clock is
// obvious, but not so for a steady_clock. Maybe TimePoint belongs to a system clock
// and sould be called something else here, and live in a time_measuring namespace.
std::string time_point_to_string(TimePoint tp, const std::string &fmt)
std::string time_point_to_string(TimePoint tp, const std::string& fmt)
{
using namespace std::chrono;
std::time_t timet = system_clock::to_time_t(system_clock::now()
+ (tp - Clock::now()));
struct tm * ptm;
struct tm* ptm;
ptm = gmtime (&timet);
const int sz = 1024;
char buf[sz];
@ -115,30 +114,30 @@ std::string time_point_to_string(TimePoint tp, const std::string &fmt)
return buf;
}
std::ostream & operator<<(std::ostream & os, TimePoint tp)
std::ostream& operator<<(std::ostream& os, TimePoint tp)
{
os << time_point_to_string(tp);
return os;
}
void test_stopwatch_output(std::ostream & os)
void test_stopwatch_output(std::ostream& os)
{
long long dur[] =
{
400, // 400ns
5 * 1000, // 5us
500 * 1000, // 500us
1 * 1000000, // 1ms
700 * 1000000LL, // 700ms
5 * 1000000000LL, // 5s
200 * 1000000000LL, // 200s
5 * 60 * 1000000000LL, // 5m
45 * 60 * 1000000000LL, // 45m
130 * 60 * 1000000000LL, // 130m
24 * 60 * 60 * 1000000000LL, // 24 hours
3 * 24 * 60 * 60 * 1000000000LL, // 72 hours
180 * 24 * 60 * 60 * 1000000000LL, // 180 days
1000 * 24 * 60 * 60 * 1000000000LL // 1000 days
400, // 400ns
5 * 1000, // 5us
500 * 1000, // 500us
1 * 1000000, // 1ms
700 * 1000000LL, // 700ms
5 * 1000000000LL, // 5s
200 * 1000000000LL, // 200s
5 * 60 * 1000000000LL, // 5m
45 * 60 * 1000000000LL, // 45m
130 * 60 * 1000000000LL, // 130m
24 * 60 * 60 * 1000000000LL, // 24 hours
3 * 24 * 60 * 60 * 1000000000LL, // 72 hours
180 * 24 * 60 * 60 * 1000000000LL, // 180 days
1000 * 24 * 60 * 60 * 1000000000LL // 1000 days
};
for (unsigned i = 0; i < sizeof(dur) / sizeof(dur[0]); ++i)
@ -146,4 +145,4 @@ void test_stopwatch_output(std::ostream & os)
os << Duration(dur[i]) << std::endl;
}
}
} // maxbase
} // maxbase

View File

@ -18,8 +18,7 @@
namespace
{
thread_local char errbuf[512]; // Enough for all errors
thread_local char errbuf[512]; // Enough for all errors
}
const char* mxb_strerror(int error)

View File

@ -11,10 +11,10 @@
* Public License.
*/
#if !defined(SS_DEBUG)
#if !defined (SS_DEBUG)
#define SS_DEBUG
#endif
#if defined(NDEBUG)
#if defined (NDEBUG)
#undef NDEBUG
#endif
@ -181,7 +181,6 @@ void test_signal()
thread.join();
}
}
int main(int argc, char* argv[])

View File

@ -26,7 +26,7 @@ namespace
int64_t get_monotonic_time_ms()
{
struct timespec ts;
MXB_AT_DEBUG(int rv =) clock_gettime(CLOCK_MONOTONIC, &ts);
MXB_AT_DEBUG(int rv = ) clock_gettime(CLOCK_MONOTONIC, &ts);
mxb_assert(rv == 0);
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
@ -118,7 +118,6 @@ int run()
return EXIT_SUCCESS;
}
}
int main()

View File

@ -45,15 +45,15 @@ const int MXB_WORKER_MSG_DISPOSABLE_TASK = -2;
*/
struct this_unit
{
bool initialized; // Whether the initialization has been performed.
bool initialized; // Whether the initialization has been performed.
} this_unit =
{
false, // initialized
false, // initialized
};
thread_local struct this_thread
{
Worker* pCurrent_worker; // The current worker
Worker* pCurrent_worker; // The current worker
} this_thread =
{
nullptr
@ -64,11 +64,10 @@ thread_local struct this_thread
*/
typedef struct worker_message
{
uint32_t id; /*< Message id. */
intptr_t arg1; /*< Message specific first argument. */
intptr_t arg2; /*< Message specific second argument. */
uint32_t id; /*< Message id. */
intptr_t arg1; /*< Message specific first argument. */
intptr_t arg2; /*< Message specific second argument. */
} WORKER_MESSAGE;
}
static bool modules_thread_init();
@ -107,14 +106,14 @@ WorkerLoad::Average::~Average()
{
}
//static
// static
uint64_t WorkerLoad::get_time()
{
uint64_t now;
timespec t;
MXB_AT_DEBUG(int rv = )clock_gettime(CLOCK_MONOTONIC, &t);
MXB_AT_DEBUG(int rv = ) clock_gettime(CLOCK_MONOTONIC, &t);
mxb_assert(rv == 0);
return t.tv_sec * 1000 + (t.tv_nsec / 1000000);
@ -161,7 +160,8 @@ int create_timerfd()
else
{
MXB_ALERT("Could not create timer file descriptor even with no flags, system "
"will not work: %s", mxb_strerror(errno));
"will not work: %s",
mxb_strerror(errno));
mxb_assert(!true);
}
}
@ -175,7 +175,6 @@ int create_timerfd()
return fd;
}
}
WorkerTimer::WorkerTimer(Worker* pWorker)
@ -256,7 +255,7 @@ uint32_t WorkerTimer::handle(Worker* pWorker, uint32_t events)
return MXB_POLL_READ;
}
//static
// static
uint32_t WorkerTimer::handler(MXB_POLL_DATA* pThis, MXB_WORKER* pWorker, uint32_t events)
{
return static_cast<WorkerTimer*>(pThis)->handle(static_cast<Worker*>(pWorker), events);
@ -280,10 +279,9 @@ int create_epoll_instance()
return fd;
}
}
//static
// static
uint32_t Worker::s_next_delayed_call_id = 1;
Worker::Worker(int max_events)
@ -494,7 +492,7 @@ bool Worker::execute(function<void ()> func, mxb::Semaphore* pSem, execute_mode_
};
bool rval = false;
CustomTask* task = new (std::nothrow) CustomTask(func);
CustomTask* task = new( std::nothrow) CustomTask(func);
if (task)
{
@ -616,7 +614,7 @@ void Worker::shutdown()
*/
void Worker::handle_message(MessageQueue& queue, const MessageQueue::Message& msg)
{
switch (msg.id())
switch (msg.id())
{
case MXB_WORKER_MSG_SHUTDOWN:
{
@ -627,7 +625,7 @@ void Worker::handle_message(MessageQueue& queue, const MessageQueue::Message& ms
case MXB_WORKER_MSG_CALL:
{
void (*f)(MXB_WORKER*, void*) = (void (*)(MXB_WORKER*, void*))msg.arg1();
void (* f)(MXB_WORKER*, void*) = (void (*)(MXB_WORKER*, void*))msg.arg1();
f(this, (void*)msg.arg2());
}
@ -635,7 +633,7 @@ void Worker::handle_message(MessageQueue& queue, const MessageQueue::Message& ms
case MXB_WORKER_MSG_TASK:
{
Task *pTask = reinterpret_cast<Task*>(msg.arg1());
Task* pTask = reinterpret_cast<Task*>(msg.arg1());
mxb::Semaphore* pSem = reinterpret_cast<mxb::Semaphore*>(msg.arg2());
pTask->execute(*this);
@ -649,7 +647,7 @@ void Worker::handle_message(MessageQueue& queue, const MessageQueue::Message& ms
case MXB_WORKER_MSG_DISPOSABLE_TASK:
{
DisposableTask *pTask = reinterpret_cast<DisposableTask*>(msg.arg1());
DisposableTask* pTask = reinterpret_cast<DisposableTask*>(msg.arg1());
pTask->execute(*this);
pTask->dec_ref();
}
@ -665,7 +663,7 @@ void Worker::handle_message(MessageQueue& queue, const MessageQueue::Message& ms
*
* @param arg A worker.
*/
//static
// static
void Worker::thread_main(Worker* pThis, mxb::Semaphore* pSem)
{
pThis->run(pSem);
@ -698,7 +696,8 @@ void Worker::resolve_poll_error(int fd, int errornum, int op)
if (ENOSPC == errornum)
{
MXB_ERROR("The limit imposed by /proc/sys/fs/epoll/max_user_watches was "
"reached when trying to add file descriptor %d to an epoll instance.", fd);
"reached when trying to add file descriptor %d to an epoll instance.",
fd);
return;
}
}
@ -741,14 +740,13 @@ namespace
long time_in_100ms_ticks()
{
using TenthSecondDuration = std::chrono::duration<long, std::ratio<1,10>>;
using TenthSecondDuration = std::chrono::duration<long, std::ratio<1, 10>>;
auto dur = std::chrono::steady_clock::now().time_since_epoch();
auto tenth = std::chrono::duration_cast<TenthSecondDuration>(dur);
return tenth.count();
}
}
/**
@ -844,7 +842,7 @@ void Worker::poll_waitevents()
m_statistics.maxqtime = std::max(m_statistics.maxqtime, qtime);
MXB_POLL_DATA *data = (MXB_POLL_DATA*)events[i].data.ptr;
MXB_POLL_DATA* data = (MXB_POLL_DATA*)events[i].data.ptr;
uint32_t actions = data->handler(data, this, events[i].events);
@ -891,7 +889,7 @@ void Worker::poll_waitevents()
epoll_tick();
m_state = IDLE;
} /*< while(1) */
} /*< while(1) */
}
namespace
@ -905,7 +903,6 @@ int64_t get_current_time_ms()
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
}
}
void Worker::tick()
@ -1051,7 +1048,6 @@ bool Worker::cancel_delayed_call(uint32_t id)
return found;
}
}

View File

@ -51,5 +51,4 @@ void WorkerDisposableTask::dec_ref()
delete this;
}
}
}