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:
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/cdefs.h>
|
||||
#include <signal.h>
|
||||
@ -21,19 +21,31 @@
|
||||
MXB_BEGIN_DECLS
|
||||
|
||||
// TODO: Provide an MXB_DEBUG with the same meaning.
|
||||
#if defined(SS_DEBUG)
|
||||
#if defined (SS_DEBUG)
|
||||
|
||||
#define mxb_assert(exp) do { if(!(exp)){\
|
||||
const char *debug_expr = #exp; /** The MXB_ERROR marco doesn't seem to like stringification */ \
|
||||
#define mxb_assert(exp) \
|
||||
do {if (!(exp)) { \
|
||||
const char* debug_expr = #exp; /** The MXB_ERROR marco doesn't seem to like stringification
|
||||
* */ \
|
||||
MXB_ERROR("debug assert at %s:%d failed: %s\n", (char*)__FILE__, __LINE__, debug_expr); \
|
||||
fprintf(stderr, "debug assert at %s:%d failed: %s\n", (char*)__FILE__, __LINE__, debug_expr); \
|
||||
raise(SIGABRT);} } while (false)
|
||||
raise(SIGABRT);}} while (false)
|
||||
|
||||
#define mxb_assert_message(exp,message) do { if(!(exp)){ \
|
||||
const char *debug_expr = #exp; \
|
||||
MXB_ERROR("debug assert at %s:%d failed: %s (%s)\n", (char*)__FILE__, __LINE__, message, debug_expr); \
|
||||
fprintf(stderr, "debug assert at %s:%d failed: %s (%s)\n", (char*)__FILE__, __LINE__, message, debug_expr); \
|
||||
raise(SIGABRT);} } while (false)
|
||||
#define mxb_assert_message(exp, message) \
|
||||
do {if (!(exp)) { \
|
||||
const char* debug_expr = #exp; \
|
||||
MXB_ERROR("debug assert at %s:%d failed: %s (%s)\n", \
|
||||
(char*)__FILE__, \
|
||||
__LINE__, \
|
||||
message, \
|
||||
debug_expr); \
|
||||
fprintf(stderr, \
|
||||
"debug assert at %s:%d failed: %s (%s)\n", \
|
||||
(char*)__FILE__, \
|
||||
__LINE__, \
|
||||
message, \
|
||||
debug_expr); \
|
||||
raise(SIGABRT);}} while (false)
|
||||
|
||||
#define MXB_AT_DEBUG(exp) exp
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @file atomic.h Atomic operations on integers.
|
||||
@ -43,10 +43,10 @@ MXB_BEGIN_DECLS
|
||||
* @param value Value to be added
|
||||
* @return The value of variable before the add occurred
|
||||
*/
|
||||
int atomic_add(int *variable, int value);
|
||||
uint32_t atomic_add_uint32(uint32_t *variable, int32_t value);
|
||||
int64_t atomic_add_int64(int64_t *variable, int64_t value);
|
||||
uint64_t atomic_add_uint64(uint64_t *variable, int64_t value);
|
||||
int atomic_add(int* variable, int value);
|
||||
uint32_t atomic_add_uint32(uint32_t* variable, int32_t value);
|
||||
int64_t atomic_add_int64(int64_t* variable, int64_t value);
|
||||
uint64_t atomic_add_uint64(uint64_t* variable, int64_t value);
|
||||
|
||||
/**
|
||||
* Implementation of an atomic load operation for the GCC environment.
|
||||
@ -57,12 +57,12 @@ uint64_t atomic_add_uint64(uint64_t *variable, int64_t value);
|
||||
* @param variable Pointer the the variable to load from
|
||||
* @return The stored value
|
||||
*/
|
||||
int atomic_load_int(const int *variable);
|
||||
int32_t atomic_load_int32(const int32_t *variable);
|
||||
int64_t atomic_load_int64(const int64_t *variable);
|
||||
uint32_t atomic_load_uint32(const uint32_t *variable);
|
||||
uint64_t atomic_load_uint64(const uint64_t *variable);
|
||||
void* atomic_load_ptr(void * const *variable);
|
||||
int atomic_load_int(const int* variable);
|
||||
int32_t atomic_load_int32(const int32_t* variable);
|
||||
int64_t atomic_load_int64(const int64_t* variable);
|
||||
uint32_t atomic_load_uint32(const uint32_t* variable);
|
||||
uint64_t atomic_load_uint64(const uint64_t* variable);
|
||||
void* atomic_load_ptr(void* const* variable);
|
||||
|
||||
/**
|
||||
* Implementation of an atomic store operation for the GCC environment.
|
||||
@ -73,12 +73,12 @@ void* atomic_load_ptr(void * const *variable);
|
||||
* @param variable Pointer the the variable to store to
|
||||
* @param value Value to be stored
|
||||
*/
|
||||
void atomic_store_int(int *variable, int value);
|
||||
void atomic_store_int32(int32_t *variable, int32_t value);
|
||||
void atomic_store_int64(int64_t *variable, int64_t value);
|
||||
void atomic_store_uint32(uint32_t *variable, uint32_t value);
|
||||
void atomic_store_uint64(uint64_t *variable, uint64_t value);
|
||||
void atomic_store_ptr(void **variable, void *value);
|
||||
void atomic_store_int(int* variable, int value);
|
||||
void atomic_store_int32(int32_t* variable, int32_t value);
|
||||
void atomic_store_int64(int64_t* variable, int64_t value);
|
||||
void atomic_store_uint32(uint32_t* variable, uint32_t value);
|
||||
void atomic_store_uint64(uint64_t* variable, uint64_t value);
|
||||
void atomic_store_ptr(void** variable, void* value);
|
||||
|
||||
/**
|
||||
* @brief Impose a full memory barrier
|
||||
@ -98,7 +98,7 @@ static inline void atomic_synchronize()
|
||||
#ifdef MXB_USE_ATOMIC_BUILTINS
|
||||
__atomic_thread_fence(__ATOMIC_SEQ_CST);
|
||||
#else
|
||||
__sync_synchronize(); /* Memory barrier. */
|
||||
__sync_synchronize(); /* Memory barrier. */
|
||||
#endif
|
||||
|
||||
#else
|
||||
@ -119,7 +119,7 @@ static inline void atomic_synchronize()
|
||||
* written to @c old_value if the two are not equal. Do not rely on this behavior
|
||||
* and always do a separate read before attempting a compare-and-swap.
|
||||
*/
|
||||
bool atomic_cas_ptr(void **variable, void** old_value, void *new_value);
|
||||
bool atomic_cas_ptr(void** variable, void** old_value, void* new_value);
|
||||
|
||||
/**
|
||||
* Atomic read-and-write. Writes new value into the given memory address and returns the old value.
|
||||
@ -128,6 +128,6 @@ bool atomic_cas_ptr(void **variable, void** old_value, void *new_value);
|
||||
* @param new_value The value to write
|
||||
* @return The value before writing
|
||||
*/
|
||||
int atomic_exchange_int(int *variable, int new_value);
|
||||
int atomic_exchange_int(int* variable, int new_value);
|
||||
|
||||
MXB_END_DECLS
|
||||
|
@ -23,10 +23,10 @@ class CumulativeAverage
|
||||
{
|
||||
public:
|
||||
// add an average made of num_samples
|
||||
void add(double ave, int num_samples = 1);
|
||||
double average() const;
|
||||
int num_samples() const;
|
||||
void reset();
|
||||
void add(double ave, int num_samples = 1);
|
||||
double average() const;
|
||||
int num_samples() const;
|
||||
void reset();
|
||||
CumulativeAverage& operator+=(const CumulativeAverage& rhs);
|
||||
private:
|
||||
double m_ave = 0;
|
||||
@ -43,8 +43,8 @@ public:
|
||||
EMAverage(double min_alpha, double max_alpha, int sample_max);
|
||||
|
||||
/* add an average made of num_samples
|
||||
* alpha = m_min_alpha + m_max_alpha * std::min(double(num_samples) / sample_max, 1.0);
|
||||
* ave = alpha * ave + (1 - alpha) * sample; */
|
||||
* alpha = m_min_alpha + m_max_alpha * std::min(double(num_samples) / sample_max, 1.0);
|
||||
* ave = alpha * ave + (1 - alpha) * sample; */
|
||||
void add(double ave, int num_samples = 1);
|
||||
void add(const CumulativeAverage& ca);
|
||||
double average() const;
|
||||
@ -53,11 +53,10 @@ public:
|
||||
int sample_max() const;
|
||||
void reset();
|
||||
private:
|
||||
const double m_min_alpha;
|
||||
const double m_max_alpha;
|
||||
int m_sample_max;
|
||||
int m_num_samples = 0;
|
||||
double m_ave = 0;
|
||||
const double m_min_alpha;
|
||||
const double m_max_alpha;
|
||||
int m_sample_max;
|
||||
int m_num_samples = 0;
|
||||
double m_ave = 0;
|
||||
};
|
||||
|
||||
} // maxbase
|
||||
} // maxbase
|
||||
|
@ -19,7 +19,7 @@
|
||||
* This file is to be included first by all C++ headers.
|
||||
*/
|
||||
|
||||
#if !defined(__cplusplus)
|
||||
#if !defined (__cplusplus)
|
||||
#error This file is only to be included by C++ code.
|
||||
#endif
|
||||
|
||||
|
@ -61,7 +61,7 @@
|
||||
* The function attributes are compiler specific.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#define mxb_attribute(a) __attribute__(a)
|
||||
#define mxb_attribute(a) __attribute__ (a)
|
||||
#else
|
||||
#define mxb_attribute(a)
|
||||
#endif
|
||||
@ -76,11 +76,11 @@
|
||||
/**
|
||||
* thread_local
|
||||
*/
|
||||
#if !defined(__cplusplus)
|
||||
#if !defined (__cplusplus)
|
||||
|
||||
#if __STDC_VERSION__ >= 201112
|
||||
|
||||
#if defined(__STDC_NO_THREADS__)
|
||||
#if defined (__STDC_NO_THREADS__)
|
||||
#define thread_local _Thread_local
|
||||
#else
|
||||
#include <threads.h>
|
||||
@ -88,7 +88,7 @@
|
||||
|
||||
#else // __STDC_VERSION >= 201112
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined (__GNUC__)
|
||||
#define thread_local __thread
|
||||
#else
|
||||
#error Do not know how to define thread_local on this compiler/OS platform.
|
||||
@ -101,7 +101,7 @@
|
||||
// GCC 4.8 added support for native thread_local.
|
||||
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined (__GNUC__)
|
||||
#define thread_local __thread
|
||||
#else
|
||||
#error Do not know how to define thread_local on this compiler/OS platform.
|
||||
|
@ -35,10 +35,11 @@ class EventCount
|
||||
public:
|
||||
EventCount(const EventCount&) = delete;
|
||||
EventCount& operator=(const EventCount&) = delete;
|
||||
explicit EventCount(const std::string& event_id, Duration time_window,
|
||||
explicit EventCount(const std::string& event_id,
|
||||
Duration time_window,
|
||||
Duration granularity = Duration(std::chrono::milliseconds(10)));
|
||||
EventCount(EventCount&&); // can't be defaulted in gcc 4.4
|
||||
EventCount& operator=(EventCount&&); // can't be defaulted in gcc 4.4
|
||||
EventCount(EventCount&&); // can't be defaulted in gcc 4.4
|
||||
EventCount& operator=(EventCount&&);// can't be defaulted in gcc 4.4
|
||||
|
||||
const std::string& event_id() const
|
||||
{
|
||||
@ -49,22 +50,25 @@ public:
|
||||
return m_time_window;
|
||||
}
|
||||
void dump(std::ostream& os) const;
|
||||
int count() const;
|
||||
int count() const;
|
||||
void increment();
|
||||
|
||||
// these defs need not be public once lambdas are available
|
||||
struct Timestamp
|
||||
{
|
||||
TimePoint time_point;
|
||||
int count;
|
||||
Timestamp(TimePoint p, int c) : time_point(p), count(c) {}
|
||||
int count;
|
||||
Timestamp(TimePoint p, int c) : time_point(p)
|
||||
, count(c)
|
||||
{
|
||||
}
|
||||
};
|
||||
private:
|
||||
void purge() const; // remove out of window stats
|
||||
void purge() const; // remove out of window stats
|
||||
|
||||
std::string m_event_id;
|
||||
Duration m_time_window;
|
||||
Duration::rep m_granularity;
|
||||
std::string m_event_id;
|
||||
Duration m_time_window;
|
||||
Duration::rep m_granularity;
|
||||
mutable std::vector<Timestamp> m_timestamps;
|
||||
};
|
||||
|
||||
@ -76,10 +80,11 @@ class SessionCount
|
||||
public:
|
||||
SessionCount(const SessionCount&) = delete;
|
||||
SessionCount& operator=(const SessionCount&) = delete;
|
||||
SessionCount(const std::string& sess_id, Duration time_window,
|
||||
SessionCount(const std::string& sess_id,
|
||||
Duration time_window,
|
||||
Duration granularity = Duration(std::chrono::milliseconds(10)));
|
||||
SessionCount(SessionCount &&); // can't be defaulted in gcc 4.4
|
||||
SessionCount& operator=(SessionCount&&); // can't be defaulted in gcc 4.4
|
||||
SessionCount(SessionCount&&); // can't be defaulted in gcc 4.4
|
||||
SessionCount& operator=(SessionCount&&);// can't be defaulted in gcc 4.4
|
||||
|
||||
const std::string& session_id() const
|
||||
{
|
||||
@ -90,23 +95,22 @@ public:
|
||||
return m_time_window;
|
||||
}
|
||||
const std::vector<EventCount>& event_counts() const;
|
||||
void dump(std::ostream& os) const;
|
||||
bool empty() const; // no stats
|
||||
void dump(std::ostream& os) const;
|
||||
bool empty() const; // no stats
|
||||
|
||||
void increment(const std::string& event_id);
|
||||
private:
|
||||
void purge() const; // remove out of window stats
|
||||
void purge() const; // remove out of window stats
|
||||
|
||||
std::string m_sess_id;
|
||||
Duration m_time_window;
|
||||
Duration m_granularity;
|
||||
mutable int m_cleanup_countdown;
|
||||
std::string m_sess_id;
|
||||
Duration m_time_window;
|
||||
Duration m_granularity;
|
||||
mutable int m_cleanup_countdown;
|
||||
mutable std::vector<EventCount> m_event_counts;
|
||||
};
|
||||
|
||||
// conveniece. Any real formatted output should go elsewhere.
|
||||
std::ostream& operator<<(std::ostream& os, const SessionCount& stats);
|
||||
void dump(std::ostream& os, const std::vector<SessionCount>& sessions);
|
||||
void dumpTotals(std::ostream& os, const std::vector<SessionCount> &sessions);
|
||||
|
||||
} // maxbase
|
||||
void dump(std::ostream& os, const std::vector<SessionCount>& sessions);
|
||||
void dumpTotals(std::ostream& os, const std::vector<SessionCount>& sessions);
|
||||
} // maxbase
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/cdefs.h>
|
||||
#include <jansson.h>
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/cdefs.h>
|
||||
|
||||
@ -45,7 +45,7 @@ MXB_BEGIN_DECLS
|
||||
* Any file that is compiled into maxscale-common should *not* have
|
||||
* MXB_MODULE_NAME defined.
|
||||
*/
|
||||
#if !defined(MXB_MODULE_NAME)
|
||||
#if !defined (MXB_MODULE_NAME)
|
||||
#define MXB_MODULE_NAME NULL
|
||||
#endif
|
||||
|
||||
@ -54,13 +54,13 @@ extern int mxb_log_enabled_priorities;
|
||||
typedef enum mxb_log_target_t
|
||||
{
|
||||
MXB_LOG_TARGET_DEFAULT,
|
||||
MXB_LOG_TARGET_FS, // File system
|
||||
MXB_LOG_TARGET_STDOUT, // Standard output
|
||||
MXB_LOG_TARGET_FS, // File system
|
||||
MXB_LOG_TARGET_STDOUT, // Standard output
|
||||
} mxb_log_target_t;
|
||||
|
||||
typedef enum mxb_log_augmentation_t
|
||||
{
|
||||
MXB_LOG_AUGMENT_WITH_FUNCTION = 1, // Each logged line is suffixed with [function-name]
|
||||
MXB_LOG_AUGMENT_WITH_FUNCTION = 1, // Each logged line is suffixed with [function-name]
|
||||
MXB_LOG_AUGMENTATION_MASK = (MXB_LOG_AUGMENT_WITH_FUNCTION)
|
||||
} mxb_log_augmentation_t;
|
||||
|
||||
@ -83,7 +83,7 @@ typedef struct MXB_LOG_THROTTLING
|
||||
*
|
||||
* @return Length of data written to buffer.
|
||||
*/
|
||||
typedef size_t (*mxb_log_context_provider_t)(char* buffer, size_t len);
|
||||
typedef size_t (* mxb_log_context_provider_t)(char* buffer, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Initialize the log
|
||||
@ -241,8 +241,11 @@ void mxb_log_get_throttling(MXB_LOG_THROTTLING* throttling);
|
||||
*/
|
||||
int mxb_log_message(int priority,
|
||||
const char* modname,
|
||||
const char* file, int line, const char* function,
|
||||
const char* format, ...) mxb_attribute((format(printf, 6, 7)));
|
||||
const char* file,
|
||||
int line,
|
||||
const char* function,
|
||||
const char* format,
|
||||
...) mxb_attribute((format(printf, 6, 7)));
|
||||
|
||||
/**
|
||||
* Log an Out-Of-Memory message.
|
||||
@ -267,10 +270,10 @@ int mxb_log_oom(const char* message);
|
||||
* @attention Should typically not be called directly. Use some of the
|
||||
* MXB_ERROR, MXB_WARNING, etc. macros instead.
|
||||
*/
|
||||
#define MXB_LOG_MESSAGE(priority, format, ...)\
|
||||
(mxb_log_is_priority_enabled(priority) ? \
|
||||
mxb_log_message(priority, MXB_MODULE_NAME, __FILE__, __LINE__, __func__, format, ##__VA_ARGS__) :\
|
||||
0)
|
||||
#define MXB_LOG_MESSAGE(priority, format, ...) \
|
||||
(mxb_log_is_priority_enabled(priority) \
|
||||
? mxb_log_message(priority, MXB_MODULE_NAME, __FILE__, __LINE__, __func__, format, ##__VA_ARGS__) \
|
||||
: 0)
|
||||
|
||||
/**
|
||||
* Log an alert, error, warning, notice, info, or debug message.
|
||||
@ -288,14 +291,14 @@ int mxb_log_oom(const char* message);
|
||||
*
|
||||
* @return 0 for success, non-zero otherwise.
|
||||
*/
|
||||
#define MXB_ALERT(format, ...) MXB_LOG_MESSAGE(LOG_ALERT, format, ##__VA_ARGS__)
|
||||
#define MXB_ERROR(format, ...) MXB_LOG_MESSAGE(LOG_ERR, format, ##__VA_ARGS__)
|
||||
#define MXB_ALERT(format, ...) MXB_LOG_MESSAGE(LOG_ALERT, format, ##__VA_ARGS__)
|
||||
#define MXB_ERROR(format, ...) MXB_LOG_MESSAGE(LOG_ERR, format, ##__VA_ARGS__)
|
||||
#define MXB_WARNING(format, ...) MXB_LOG_MESSAGE(LOG_WARNING, format, ##__VA_ARGS__)
|
||||
#define MXB_NOTICE(format, ...) MXB_LOG_MESSAGE(LOG_NOTICE, format, ##__VA_ARGS__)
|
||||
#define MXB_INFO(format, ...) MXB_LOG_MESSAGE(LOG_INFO, format, ##__VA_ARGS__)
|
||||
#define MXB_NOTICE(format, ...) MXB_LOG_MESSAGE(LOG_NOTICE, format, ##__VA_ARGS__)
|
||||
#define MXB_INFO(format, ...) MXB_LOG_MESSAGE(LOG_INFO, format, ##__VA_ARGS__)
|
||||
|
||||
#if defined(SS_DEBUG)
|
||||
#define MXB_DEBUG(format, ...) MXB_LOG_MESSAGE(LOG_DEBUG, format, ##__VA_ARGS__)
|
||||
#if defined (SS_DEBUG)
|
||||
#define MXB_DEBUG(format, ...) MXB_LOG_MESSAGE(LOG_DEBUG, format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define MXB_DEBUG(format, ...)
|
||||
#endif
|
||||
@ -326,7 +329,7 @@ int mxb_log_oom(const char* message);
|
||||
*
|
||||
* @return 0 for success, non-zero otherwise.
|
||||
*/
|
||||
#define MXB_OOM_IFNULL(p) do { if (!p) { MXB_OOM(); } } while (false)
|
||||
#define MXB_OOM_IFNULL(p) do {if (!p) {MXB_OOM();}} while (false)
|
||||
|
||||
/**
|
||||
* Log an out of memory error using custom message, if the
|
||||
@ -337,6 +340,6 @@ int mxb_log_oom(const char* message);
|
||||
*
|
||||
* @return 0 for success, non-zero otherwise.
|
||||
*/
|
||||
#define MXB_OOM_MESSAGE_IFNULL(p, message) do { if (!p) { MXB_OOM_MESSAGE(message); } } while (false)
|
||||
#define MXB_OOM_MESSAGE_IFNULL(p, message) do {if (!p) {MXB_OOM_MESSAGE(message);}} while (false)
|
||||
|
||||
MXB_END_DECLS
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/ccdefs.hh>
|
||||
#include <stdexcept>
|
||||
@ -70,5 +70,4 @@ public:
|
||||
mxb_log_finish();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/ccdefs.hh>
|
||||
|
||||
@ -73,15 +73,15 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
Logger(const std::string& filename):
|
||||
m_filename(filename)
|
||||
Logger(const std::string& filename)
|
||||
: m_filename(filename)
|
||||
{
|
||||
}
|
||||
|
||||
std::string m_filename;
|
||||
};
|
||||
|
||||
class FileLogger: public Logger
|
||||
class FileLogger : public Logger
|
||||
{
|
||||
public:
|
||||
FileLogger(const FileLogger&) = delete;
|
||||
@ -122,8 +122,8 @@ public:
|
||||
bool rotate();
|
||||
|
||||
private:
|
||||
int m_fd;
|
||||
std::mutex m_lock;
|
||||
int m_fd;
|
||||
std::mutex m_lock;
|
||||
|
||||
FileLogger(int fd, const std::string& filename);
|
||||
bool write_header();
|
||||
@ -131,7 +131,7 @@ private:
|
||||
void close(const char* msg);
|
||||
};
|
||||
|
||||
class StdoutLogger: public Logger
|
||||
class StdoutLogger : public Logger
|
||||
{
|
||||
public:
|
||||
StdoutLogger(const StdoutLogger&) = delete;
|
||||
@ -170,13 +170,12 @@ public:
|
||||
bool rotate()
|
||||
{
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
StdoutLogger(const std::string& filename):
|
||||
Logger(filename)
|
||||
StdoutLogger(const std::string& filename)
|
||||
: Logger(filename)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/cdefs.h>
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/ccdefs.hh>
|
||||
#include <stdexcept>
|
||||
@ -105,5 +105,4 @@ public:
|
||||
private:
|
||||
bool m_log_inited;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/ccdefs.hh>
|
||||
#include <maxbase/poll.hh>
|
||||
@ -28,7 +28,7 @@ class Worker;
|
||||
* the caller's and recipient's responsibility to manage the lifetime and
|
||||
* concurrent access of anything possibly pointed to from the message.
|
||||
*/
|
||||
class MessageQueueMessage /* final */
|
||||
class MessageQueueMessage /* final */
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@ -110,7 +110,7 @@ public:
|
||||
class MessageQueue : private mxb::PollData
|
||||
{
|
||||
MessageQueue(const MessageQueue&);
|
||||
MessageQueue& operator = (const MessageQueue&);
|
||||
MessageQueue& operator=(const MessageQueue&);
|
||||
|
||||
public:
|
||||
typedef MessageQueueHandler Handler;
|
||||
@ -193,5 +193,4 @@ private:
|
||||
int m_write_fd;
|
||||
Worker* m_pWorker;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/cdefs.h>
|
||||
#include <sys/epoll.h>
|
||||
@ -43,7 +43,7 @@ typedef struct MXB_WORKER
|
||||
*
|
||||
* @return A combination of mxb_poll_action_t enumeration values.
|
||||
*/
|
||||
typedef uint32_t (*mxb_poll_handler_t)(struct MXB_POLL_DATA* data, MXB_WORKER* worker, uint32_t events);
|
||||
typedef uint32_t (* mxb_poll_handler_t)(struct MXB_POLL_DATA* data, MXB_WORKER* worker, uint32_t events);
|
||||
|
||||
typedef struct MXB_POLL_DATA
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/ccdefs.hh>
|
||||
#include <maxbase/poll.h>
|
||||
@ -33,5 +33,4 @@ public:
|
||||
owner = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @file semaphore.h Semaphores used by MaxScale.
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/ccdefs.hh>
|
||||
#include <cerrno>
|
||||
@ -24,13 +24,13 @@ namespace maxbase
|
||||
class Semaphore
|
||||
{
|
||||
Semaphore(const Semaphore&) = delete;
|
||||
Semaphore& operator = (const Semaphore&) = delete;
|
||||
Semaphore& operator=(const Semaphore&) = delete;
|
||||
|
||||
public:
|
||||
enum signal_approach_t
|
||||
{
|
||||
HONOUR_SIGNALS, /* Honour signals and return when interrupted. */
|
||||
IGNORE_SIGNALS /* Ignore signals and re-issue the comment when signals occur. */
|
||||
HONOUR_SIGNALS, /* Honour signals and return when interrupted. */
|
||||
IGNORE_SIGNALS /* Ignore signals and re-issue the comment when signals occur. */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -48,7 +48,7 @@ public:
|
||||
initial_count = SEM_VALUE_MAX;
|
||||
}
|
||||
|
||||
MXB_AT_DEBUG(int rc =) sem_init(&m_sem, 0, initial_count);
|
||||
MXB_AT_DEBUG(int rc = ) sem_init(&m_sem, 0, initial_count);
|
||||
mxb_assert(rc == 0);
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public:
|
||||
mxb_assert(rc == 0);
|
||||
mxb_assert(count == 0);
|
||||
#endif
|
||||
MXB_AT_DEBUG(rc =) sem_destroy(&m_sem);
|
||||
MXB_AT_DEBUG(rc = ) sem_destroy(&m_sem);
|
||||
mxb_assert(rc == 0);
|
||||
}
|
||||
|
||||
@ -181,9 +181,9 @@ public:
|
||||
}
|
||||
while ((rc != 0) && ((errno == EINTR) && (signal_approach == IGNORE_SIGNALS)));
|
||||
|
||||
mxb_assert((rc == 0) ||
|
||||
(errno == EAGAIN) ||
|
||||
((errno == EINTR) && (signal_approach == HONOUR_SIGNALS)));
|
||||
mxb_assert((rc == 0)
|
||||
|| (errno == EAGAIN)
|
||||
|| ((errno == EINTR) && (signal_approach == HONOUR_SIGNALS)));
|
||||
|
||||
return rc == 0;
|
||||
}
|
||||
@ -217,9 +217,9 @@ public:
|
||||
}
|
||||
while ((rc != 0) && ((errno == EINTR) && (signal_approach == IGNORE_SIGNALS)));
|
||||
|
||||
mxb_assert((rc == 0) ||
|
||||
(errno == ETIMEDOUT) ||
|
||||
((errno == EINTR) && (signal_approach == HONOUR_SIGNALS)));
|
||||
mxb_assert((rc == 0)
|
||||
|| (errno == ETIMEDOUT)
|
||||
|| ((errno == EINTR) && (signal_approach == HONOUR_SIGNALS)));
|
||||
|
||||
return rc == 0;
|
||||
}
|
||||
@ -285,7 +285,7 @@ public:
|
||||
* and in the latter `EINTR.
|
||||
*/
|
||||
bool timedwait(time_t seconds,
|
||||
long nseconds,
|
||||
long nseconds,
|
||||
signal_approach_t signal_approach = IGNORE_SIGNALS) const
|
||||
{
|
||||
timespec ts;
|
||||
@ -316,7 +316,7 @@ public:
|
||||
*/
|
||||
size_t timedwait_n(size_t n_wait,
|
||||
time_t seconds,
|
||||
long nseconds,
|
||||
long nseconds,
|
||||
signal_approach_t signal_approach = IGNORE_SIGNALS) const
|
||||
{
|
||||
timespec ts;
|
||||
@ -380,5 +380,4 @@ private:
|
||||
private:
|
||||
mutable sem_t m_sem;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/ccdefs.hh>
|
||||
#include <unistd.h>
|
||||
@ -27,6 +27,5 @@ static inline void default_stacktrace_handler(const char* symbol, const char* co
|
||||
write(STDOUT_FILENO, "\n", 1);
|
||||
}
|
||||
|
||||
void dump_stacktrace(void (*handler)(const char* symbol, const char* command) = default_stacktrace_handler);
|
||||
|
||||
void dump_stacktrace(void (* handler)(const char* symbol, const char* command) = default_stacktrace_handler);
|
||||
}
|
||||
|
@ -22,15 +22,20 @@ namespace maxbase
|
||||
|
||||
using Clock = std::chrono::steady_clock;
|
||||
|
||||
struct Duration : public Clock::duration // for ADL
|
||||
struct Duration : public Clock::duration // for ADL
|
||||
{
|
||||
using Clock::duration::duration;
|
||||
Duration() = default;
|
||||
Duration(Clock::duration d) : Clock::duration(d) {}
|
||||
Duration(long long l) : Clock::duration(l) {} // FIXME. Get rid of this.
|
||||
Duration(Clock::duration d) : Clock::duration(d)
|
||||
{
|
||||
}
|
||||
Duration(long long l) : Clock::duration(l)
|
||||
{
|
||||
} // FIXME. Get rid of this.
|
||||
|
||||
explicit Duration(double secs) : Duration{rep(secs * period::den / period::num)}
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
double secs()
|
||||
{
|
||||
@ -60,7 +65,6 @@ std::pair<double, std::string> dur_to_human_readable(Duration dur);
|
||||
std::ostream& operator<<(std::ostream&, Duration dur);
|
||||
|
||||
// TimePoint
|
||||
std::string time_point_to_string(TimePoint tp, const std::string& fmt = "%F %T");
|
||||
std::string time_point_to_string(TimePoint tp, const std::string& fmt = "%F %T");
|
||||
std::ostream& operator<<(std::ostream&, TimePoint tp);
|
||||
|
||||
} // maxbase
|
||||
} // maxbase
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/cdefs.h>
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxscale/cdefs.h>
|
||||
#include <maxbase/poll.h>
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/ccdefs.hh>
|
||||
|
||||
@ -40,22 +40,22 @@ struct WORKER_STATISTICS
|
||||
|
||||
enum
|
||||
{
|
||||
MAXNFDS = 10,
|
||||
MAXNFDS = 10,
|
||||
N_QUEUE_TIMES = 30
|
||||
};
|
||||
|
||||
int64_t n_read; /*< Number of read events */
|
||||
int64_t n_write; /*< Number of write events */
|
||||
int64_t n_error; /*< Number of error events */
|
||||
int64_t n_hup; /*< Number of hangup events */
|
||||
int64_t n_accept; /*< Number of accept events */
|
||||
int64_t n_polls; /*< Number of poll cycles */
|
||||
int64_t n_pollev; /*< Number of polls returning events */
|
||||
int64_t n_nbpollev; /*< Number of polls returning events */
|
||||
int64_t n_fds[MAXNFDS]; /*< Number of wakeups with particular n_fds value */
|
||||
int64_t evq_avg; /*< Average event queue length */
|
||||
int64_t evq_max; /*< Maximum event queue length */
|
||||
int64_t blockingpolls; /*< Number of epoll_waits with a timeout specified */
|
||||
int64_t n_read; /*< Number of read events */
|
||||
int64_t n_write; /*< Number of write events */
|
||||
int64_t n_error; /*< Number of error events */
|
||||
int64_t n_hup; /*< Number of hangup events */
|
||||
int64_t n_accept; /*< Number of accept events */
|
||||
int64_t n_polls; /*< Number of poll cycles */
|
||||
int64_t n_pollev; /*< Number of polls returning events */
|
||||
int64_t n_nbpollev; /*< Number of polls returning events */
|
||||
int64_t n_fds[MAXNFDS]; /*< Number of wakeups with particular n_fds value */
|
||||
int64_t evq_avg; /*< Average event queue length */
|
||||
int64_t evq_max; /*< Maximum event queue length */
|
||||
int64_t blockingpolls; /*< Number of epoll_waits with a timeout specified */
|
||||
uint32_t qtimes[N_QUEUE_TIMES + 1];
|
||||
uint32_t exectimes[N_QUEUE_TIMES + 1];
|
||||
int64_t maxqtime;
|
||||
@ -76,7 +76,7 @@ struct WORKER_STATISTICS
|
||||
class WorkerLoad
|
||||
{
|
||||
WorkerLoad(const WorkerLoad&) = delete;
|
||||
WorkerLoad& operator = (const WorkerLoad&) = delete;
|
||||
WorkerLoad& operator=(const WorkerLoad&) = delete;
|
||||
|
||||
public:
|
||||
enum counter_t
|
||||
@ -157,7 +157,7 @@ public:
|
||||
default:
|
||||
mxb_assert(!true);
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,7 +187,7 @@ private:
|
||||
class Average
|
||||
{
|
||||
Average(const Average&) = delete;
|
||||
Average& operator = (const Average&) = delete;
|
||||
Average& operator=(const Average&) = delete;
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -198,7 +198,8 @@ private:
|
||||
Average(Average* pDependant = NULL)
|
||||
: m_pDependant(pDependant)
|
||||
, m_value(0)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Average();
|
||||
|
||||
@ -238,8 +239,8 @@ private:
|
||||
}
|
||||
|
||||
protected:
|
||||
Average* m_pDependant; /*< The optional dependant Average. */
|
||||
uint32_t m_value; /*< The current average value. */
|
||||
Average* m_pDependant; /*< The optional dependant Average. */
|
||||
uint32_t m_value; /*< The current average value. */
|
||||
|
||||
protected:
|
||||
void set_value(uint32_t value)
|
||||
@ -314,7 +315,7 @@ private:
|
||||
}
|
||||
|
||||
*m_i = value;
|
||||
m_sum += *m_i; // Update the sum of all values.
|
||||
m_sum += *m_i; // Update the sum of all values.
|
||||
|
||||
m_i = next(m_i);
|
||||
|
||||
@ -409,19 +410,19 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t m_begin[N]; /*< Buffer containing values from which the average is calculated. */
|
||||
uint8_t* m_end; /*< Points to one past the end of the buffer. */
|
||||
uint8_t* m_i; /*< Current position in the buffer. */
|
||||
uint32_t m_sum; /*< Sum of all values in the buffer. */
|
||||
uint32_t m_nValues; /*< How many values the buffer contains. */
|
||||
uint8_t m_begin[N]; /*< Buffer containing values from which the average is calculated. */
|
||||
uint8_t* m_end; /*< Points to one past the end of the buffer. */
|
||||
uint8_t* m_i; /*< Current position in the buffer. */
|
||||
uint32_t m_sum; /*< Sum of all values in the buffer. */
|
||||
uint32_t m_nValues; /*< How many values the buffer contains. */
|
||||
};
|
||||
|
||||
uint64_t m_start_time; /*< When was the current 1-second period started. */
|
||||
uint64_t m_wait_start; /*< The time when the worker entered epoll_wait(). */
|
||||
uint64_t m_wait_time; /*< How much time the worker has spent in epoll_wait(). */
|
||||
AverageN<60> m_load_1_hour; /*< The average load during the last hour. */
|
||||
AverageN<60> m_load_1_minute; /*< The average load during the last minute. */
|
||||
Average1 m_load_1_second; /*< The load during the last 1-second period. */
|
||||
uint64_t m_start_time; /*< When was the current 1-second period started. */
|
||||
uint64_t m_wait_start; /*< The time when the worker entered epoll_wait(). */
|
||||
uint64_t m_wait_time; /*< How much time the worker has spent in epoll_wait(). */
|
||||
AverageN<60> m_load_1_hour; /*< The average load during the last hour. */
|
||||
AverageN<60> m_load_1_minute; /*< The average load during the last minute. */
|
||||
Average1 m_load_1_second; /*< The load during the last 1-second period. */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -434,7 +435,7 @@ private:
|
||||
class WorkerTimer : private MXB_POLL_DATA
|
||||
{
|
||||
WorkerTimer(const WorkerTimer&) = delete;
|
||||
WorkerTimer& operator = (const WorkerTimer&) = delete;
|
||||
WorkerTimer& operator=(const WorkerTimer&) = delete;
|
||||
|
||||
public:
|
||||
virtual ~WorkerTimer();
|
||||
@ -474,8 +475,8 @@ private:
|
||||
static uint32_t handler(MXB_POLL_DATA* pThis, MXB_WORKER* pWorker, uint32_t events);
|
||||
|
||||
private:
|
||||
int m_fd; /**< The timerfd descriptor. */
|
||||
Worker* m_pWorker; /**< The worker in whose context the timer runs. */
|
||||
int m_fd; /**< The timerfd descriptor. */
|
||||
Worker* m_pWorker; /**< The worker in whose context the timer runs. */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -487,14 +488,14 @@ class Worker : public MXB_WORKER
|
||||
, private MessageQueue::Handler
|
||||
{
|
||||
Worker(const Worker&) = delete;
|
||||
Worker& operator = (const Worker&) = delete;
|
||||
Worker& operator=(const Worker&) = delete;
|
||||
|
||||
public:
|
||||
typedef WORKER_STATISTICS STATISTICS;
|
||||
typedef WorkerTask Task;
|
||||
typedef WorkerDisposableTask DisposableTask;
|
||||
typedef WorkerLoad Load;
|
||||
typedef WorkerTimer Timer;
|
||||
typedef WORKER_STATISTICS STATISTICS;
|
||||
typedef WorkerTask Task;
|
||||
typedef WorkerDisposableTask DisposableTask;
|
||||
typedef WorkerLoad Load;
|
||||
typedef WorkerTimer Timer;
|
||||
|
||||
/**
|
||||
* A delegating timer that delegates the timer tick handling
|
||||
@ -504,10 +505,10 @@ public:
|
||||
class DelegatingTimer : public Timer
|
||||
{
|
||||
DelegatingTimer(const DelegatingTimer&) = delete;
|
||||
DelegatingTimer& operator = (const DelegatingTimer&) = delete;
|
||||
DelegatingTimer& operator=(const DelegatingTimer&) = delete;
|
||||
|
||||
public:
|
||||
typedef void (T::*PMethod)();
|
||||
typedef void (T::* PMethod)();
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
@ -525,7 +526,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void tick() /* final */
|
||||
void tick() /* final */
|
||||
{
|
||||
(m_pDelegatee->*m_pMethod)();
|
||||
}
|
||||
@ -546,16 +547,16 @@ public:
|
||||
|
||||
enum execute_mode_t
|
||||
{
|
||||
EXECUTE_AUTO, /**< Execute tasks immediately */
|
||||
EXECUTE_QUEUED /**< Only queue tasks for execution */
|
||||
EXECUTE_AUTO, /**< Execute tasks immediately */
|
||||
EXECUTE_QUEUED /**< Only queue tasks for execution */
|
||||
};
|
||||
|
||||
struct Call
|
||||
{
|
||||
enum action_t
|
||||
{
|
||||
EXECUTE, /**< Execute the call */
|
||||
CANCEL /**< Cancel the call */
|
||||
EXECUTE, /**< Execute the call */
|
||||
CANCEL /**< Cancel the call */
|
||||
};
|
||||
};
|
||||
|
||||
@ -704,7 +705,7 @@ public:
|
||||
* @param mode Execution mode
|
||||
*
|
||||
* @return True if the task could be posted to the worker (i.e. not executed yet),
|
||||
false otherwise.
|
||||
* false otherwise.
|
||||
*
|
||||
* @attention The instance must remain valid for as long as it takes for the
|
||||
* task to be transferred to the worker and its `execute` function
|
||||
@ -823,7 +824,7 @@ public:
|
||||
* be called again.
|
||||
*/
|
||||
uint32_t delayed_call(int32_t delay,
|
||||
bool (*pFunction)(Worker::Call::action_t action))
|
||||
bool (* pFunction)(Worker::Call::action_t action))
|
||||
{
|
||||
return add_delayed_call(new DelayedCallFunctionVoid(delay, pFunction));
|
||||
}
|
||||
@ -850,7 +851,7 @@ public:
|
||||
*/
|
||||
template<class D>
|
||||
uint32_t delayed_call(int32_t delay,
|
||||
bool (*pFunction)(Worker::Call::action_t action, D data),
|
||||
bool (* pFunction)(Worker::Call::action_t action, D data),
|
||||
D data)
|
||||
{
|
||||
return add_delayed_call(new DelayedCallFunction<D>(delay, pFunction, data));
|
||||
@ -877,7 +878,7 @@ public:
|
||||
*/
|
||||
template<class T>
|
||||
uint32_t delayed_call(int32_t delay,
|
||||
bool (T::*pMethod)(Worker::Call::action_t action),
|
||||
bool (T::* pMethod)(Worker::Call::action_t action),
|
||||
T* pT)
|
||||
{
|
||||
return add_delayed_call(new DelayedCallMethodVoid<T>(delay, pMethod, pT));
|
||||
@ -905,7 +906,7 @@ public:
|
||||
*/
|
||||
template<class T, class D>
|
||||
uint32_t delayed_call(int32_t delay,
|
||||
bool (T::*pMethod)(Worker::Call::action_t action, D data),
|
||||
bool (T::* pMethod)(Worker::Call::action_t action, D data),
|
||||
T* pT,
|
||||
D data)
|
||||
{
|
||||
@ -926,8 +927,8 @@ public:
|
||||
bool cancel_delayed_call(uint32_t id);
|
||||
|
||||
protected:
|
||||
const int m_epoll_fd; /*< The epoll file descriptor. */
|
||||
state_t m_state; /*< The state of the worker */
|
||||
const int m_epoll_fd; /*< The epoll file descriptor. */
|
||||
state_t m_state; /*< The state of the worker */
|
||||
|
||||
static void inc_ref(WorkerDisposableTask* pTask)
|
||||
{
|
||||
@ -993,8 +994,8 @@ private:
|
||||
|
||||
class DelayedCall
|
||||
{
|
||||
DelayedCall(const DelayedCall&) = delete;;
|
||||
DelayedCall& operator = (const DelayedCall&) = delete;
|
||||
DelayedCall(const DelayedCall&) = delete;
|
||||
DelayedCall& operator=(const DelayedCall&) = delete;
|
||||
|
||||
public:
|
||||
virtual ~DelayedCall()
|
||||
@ -1044,27 +1045,28 @@ private:
|
||||
mxb_assert(delay > 0);
|
||||
|
||||
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 delay + (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_id; // The id of the delayed call.
|
||||
int32_t m_delay; // The delay in milliseconds.
|
||||
int64_t m_at; // The next time the function should be invoked.
|
||||
uint32_t m_id; // The id of the delayed call.
|
||||
int32_t m_delay; // The delay in milliseconds.
|
||||
int64_t m_at; // The next time the function should be invoked.
|
||||
};
|
||||
|
||||
template<class D>
|
||||
class DelayedCallFunction : public DelayedCall
|
||||
{
|
||||
DelayedCallFunction(const DelayedCallFunction&) = delete;
|
||||
DelayedCallFunction& operator = (const DelayedCallFunction&) = delete;
|
||||
DelayedCallFunction& operator=(const DelayedCallFunction&) = delete;
|
||||
|
||||
public:
|
||||
DelayedCallFunction(int32_t delay,
|
||||
bool (*pFunction)(Worker::Call::action_t action, D data), D data)
|
||||
bool (*pFunction)(Worker::Call::action_t action, D data),
|
||||
D data)
|
||||
: DelayedCall(delay)
|
||||
, m_pFunction(pFunction)
|
||||
, m_data(data)
|
||||
@ -1078,15 +1080,15 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
bool (*m_pFunction)(Worker::Call::action_t, D);
|
||||
D m_data;
|
||||
bool (* m_pFunction)(Worker::Call::action_t, D);
|
||||
D m_data;
|
||||
};
|
||||
|
||||
// Explicit specialization requires namespace scope
|
||||
class DelayedCallFunctionVoid : public DelayedCall
|
||||
{
|
||||
DelayedCallFunctionVoid(const DelayedCallFunctionVoid&) = delete;
|
||||
DelayedCallFunctionVoid& operator = (const DelayedCallFunctionVoid&) = delete;
|
||||
DelayedCallFunctionVoid& operator=(const DelayedCallFunctionVoid&) = delete;
|
||||
|
||||
public:
|
||||
DelayedCallFunctionVoid(int32_t delay,
|
||||
@ -1103,18 +1105,18 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
bool (*m_pFunction)(Worker::Call::action_t action);
|
||||
bool (* m_pFunction)(Worker::Call::action_t action);
|
||||
};
|
||||
|
||||
template<class T, class D>
|
||||
class DelayedCallMethod : public DelayedCall
|
||||
{
|
||||
DelayedCallMethod(const DelayedCallMethod&) = delete;
|
||||
DelayedCallMethod& operator = (const DelayedCallMethod&) = delete;
|
||||
DelayedCallMethod& operator=(const DelayedCallMethod&) = delete;
|
||||
|
||||
public:
|
||||
DelayedCallMethod(int32_t delay,
|
||||
bool (T::*pMethod)(Worker::Call::action_t action, D data),
|
||||
bool (T::* pMethod)(Worker::Call::action_t action, D data),
|
||||
T* pT,
|
||||
D data)
|
||||
: DelayedCall(delay)
|
||||
@ -1131,20 +1133,20 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
bool (T::*m_pMethod)(Worker::Call::action_t, D);
|
||||
bool (T::* m_pMethod)(Worker::Call::action_t, D);
|
||||
T* m_pT;
|
||||
D m_data;
|
||||
D m_data;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class DelayedCallMethodVoid : public DelayedCall
|
||||
{
|
||||
DelayedCallMethodVoid(const DelayedCallMethodVoid&) = delete;
|
||||
DelayedCallMethodVoid& operator = (const DelayedCallMethodVoid&) = delete;
|
||||
DelayedCallMethodVoid& operator=(const DelayedCallMethodVoid&) = delete;
|
||||
|
||||
public:
|
||||
DelayedCallMethodVoid(int32_t delay,
|
||||
bool (T::*pMethod)(Worker::Call::action_t),
|
||||
bool (T::* pMethod)(Worker::Call::action_t),
|
||||
T* pT)
|
||||
: DelayedCall(delay)
|
||||
, m_pMethod(pMethod)
|
||||
@ -1159,14 +1161,14 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
bool (T::*m_pMethod)(Worker::Call::action_t);
|
||||
bool (T::* m_pMethod)(Worker::Call::action_t);
|
||||
T* m_pT;
|
||||
};
|
||||
|
||||
uint32_t add_delayed_call(DelayedCall* pDelayed_call);
|
||||
void adjust_timer();
|
||||
void adjust_timer();
|
||||
|
||||
void handle_message(MessageQueue& queue, const MessageQueue::Message& msg); // override
|
||||
void handle_message(MessageQueue& queue, const MessageQueue::Message& msg); // override
|
||||
|
||||
static void thread_main(Worker* pThis, mxb::Semaphore* pSem);
|
||||
|
||||
@ -1178,7 +1180,7 @@ private:
|
||||
class LaterAt : public std::binary_function<const DelayedCall*, const DelayedCall*, bool>
|
||||
{
|
||||
public:
|
||||
bool operator () (const DelayedCall* pLhs, const DelayedCall* pRhs)
|
||||
bool operator()(const DelayedCall* pLhs, const DelayedCall* pRhs)
|
||||
{
|
||||
return pLhs->at() > pRhs->at();
|
||||
}
|
||||
@ -1186,25 +1188,24 @@ private:
|
||||
|
||||
void run(mxb::Semaphore* pSem);
|
||||
|
||||
typedef DelegatingTimer<Worker> PrivateTimer;
|
||||
typedef std::multimap<int64_t, DelayedCall*> DelayedCallsByTime;
|
||||
typedef std::unordered_map<uint32_t, DelayedCall*> DelayedCallsById;
|
||||
typedef DelegatingTimer<Worker> PrivateTimer;
|
||||
typedef std::multimap<int64_t, DelayedCall*> DelayedCallsByTime;
|
||||
typedef std::unordered_map<uint32_t, DelayedCall*> DelayedCallsById;
|
||||
|
||||
uint32_t m_max_events; /*< Maximum numer of events in each epoll_wait call. */
|
||||
STATISTICS m_statistics; /*< Worker statistics. */
|
||||
MessageQueue* m_pQueue; /*< The message queue of the worker. */
|
||||
std::thread m_thread; /*< The thread object of the worker. */
|
||||
bool m_started; /*< Whether the thread has been started or not. */
|
||||
bool m_should_shutdown; /*< Whether shutdown should be performed. */
|
||||
bool m_shutdown_initiated; /*< Whether shutdown has been initated. */
|
||||
uint32_t m_nCurrent_descriptors; /*< Current number of descriptors. */
|
||||
uint64_t m_nTotal_descriptors; /*< Total number of descriptors. */
|
||||
Load m_load; /*< The worker load. */
|
||||
PrivateTimer* m_pTimer; /*< The worker's own timer. */
|
||||
DelayedCallsByTime m_sorted_calls; /*< Current delayed calls sorted by time. */
|
||||
DelayedCallsById m_calls; /*< Current delayed calls indexed by id. */
|
||||
uint32_t m_max_events; /*< Maximum numer of events in each epoll_wait call. */
|
||||
STATISTICS m_statistics; /*< Worker statistics. */
|
||||
MessageQueue* m_pQueue; /*< The message queue of the worker. */
|
||||
std::thread m_thread; /*< The thread object of the worker. */
|
||||
bool m_started; /*< Whether the thread has been started or not. */
|
||||
bool m_should_shutdown; /*< Whether shutdown should be performed. */
|
||||
bool m_shutdown_initiated; /*< Whether shutdown has been initated. */
|
||||
uint32_t m_nCurrent_descriptors; /*< Current number of descriptors. */
|
||||
uint64_t m_nTotal_descriptors; /*< Total number of descriptors. */
|
||||
Load m_load; /*< The worker load. */
|
||||
PrivateTimer* m_pTimer; /*< The worker's own timer. */
|
||||
DelayedCallsByTime m_sorted_calls; /*< Current delayed calls sorted by time. */
|
||||
DelayedCallsById m_calls; /*< Current delayed calls indexed by id. */
|
||||
|
||||
static uint32_t s_next_delayed_call_id; /*< The next delayed call id. */
|
||||
static uint32_t s_next_delayed_call_id; /*< The next delayed call id. */
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <maxbase/ccdefs.hh>
|
||||
|
||||
@ -80,5 +80,4 @@ private:
|
||||
private:
|
||||
int32_t m_count;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user