Commit b4e2d0fd authored by tqcq's avatar tqcq
Browse files

feat update

parent d4deb0ae
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ target_sources(
          src/synchronization/mutex.cc
          src/synchronization/sequence_checker_internal.cc
          src/synchronization/thread_local.cc
          src/system/location.cc
          src/system/thread.cc
          src/task_queue/pending_task_safety_flag.cc
          src/task_queue/task_queue_base.cc
+11 −2
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@

#ifndef LOG_H
#define LOG_H
#include "sled/system/location.h"
#include <fmt/format.h>

namespace sled {
@@ -32,8 +33,16 @@ void Log(LogLevel level,
//     sled::Log(level, tag, fmt, __FILE__, __FUNCTION__, __VA_ARGS__)

#define _SLOG(level, tag, fmt_str, ...)                                        \
    sled::Log(level, tag, fmt::format(fmt_str, ##__VA_ARGS__).c_str(),         \
              __FILE__, __LINE__, __FUNCTION__)
    do {                                                                       \
        std::string __fmt_str;                                                 \
        try {                                                                  \
            __fmt_str = fmt::format(fmt_str, ##__VA_ARGS__);                   \
        } catch (const std::exception &e) {                                    \
            __fmt_str = " fmt error: " + std::string(e.what());                \
        }                                                                      \
        sled::Log(level, tag, __fmt_str.c_str(), __FILE__, __LINE__,           \
                  __FUNCTION__);                                               \
    } while (0)

#define SLOG(level, tag, fmt, ...) _SLOG(level, tag, fmt, ##__VA_ARGS__)
#define SLOG_TRACE(tag, fmt, ...)                                              \
+24 −0
Original line number Diff line number Diff line
/**
 * @file     : reflect
 * @created  : 星期一  2 26, 2024 09:55:19 CST
 * @license  : MIT
 **/

#ifndef SLED_REFLECT_REFLECT_H
#define SLED_REFLECT_REFLECT_H

#if !defined(__NO_META_PARSER__) && !defined(__META_PARSER__)
#define __META_PARSER__
#endif

#if defined(__META_PARSER__)
#define REFLECT_CLASS __attribute__((annotate("reflect-class")))
#define PROPERTY() __attribute__((annotate("reflect-property")))
#define METHOD() __attribute__((annotate("reflect-method")))
#else
#define REFLECT_CLASS
#define PROPERTY()
#define METHOD()
#endif

#endif// SLED_REFLECT_REFLECT_H
+19 −2
Original line number Diff line number Diff line
@@ -7,13 +7,30 @@
#ifndef LOCATION_H
#define LOCATION_H

#include <string>

namespace sled {

class Location {
class Location final {
public:
    static Location Current() { return Location(); }
    Location() = delete;

    static Location Current(const char *file_name = __builtin_FILE(),
                            int file_line = __builtin_LINE(),
                            const char *function = __builtin_FUNCTION());

    std::string ToString() const;

private:
    Location(const char *file_name, int file_line, const char *function);

    const char *file_name;
    int file_line;
    const char *function;
};

}// namespace sled

#define SLED_FROM_HERE sled::Location::Current();

#endif// LOCATION_H
+6 −3
Original line number Diff line number Diff line
@@ -13,9 +13,12 @@ namespace sled {
static const int64_t kNumMillisecsPerSec = 1000;
static const int64_t kNumMicrosecsPerSec = 1000000;
static const int64_t kNumNanosecsPerSec = 1000000000;
static const int64_t kNumMicrosecsPerMillisec = kNumMicrosecsPerSec / kNumMillisecsPerSec;
static const int64_t kNumNanosecsPerMillisec = kNumNanosecsPerSec / kNumMillisecsPerSec;
static const int64_t kNumNanosecsPerMicrosec = kNumNanosecsPerSec / kNumMicrosecsPerSec;
static const int64_t kNumMicrosecsPerMillisec =
    kNumMicrosecsPerSec / kNumMillisecsPerSec;
static const int64_t kNumNanosecsPerMillisec =
    kNumNanosecsPerSec / kNumMillisecsPerSec;
static const int64_t kNumNanosecsPerMicrosec =
    kNumNanosecsPerSec / kNumMicrosecsPerSec;
constexpr int64_t kNtpJan1970Millisecs = 2208988800 * kNumMillisecsPerSec;

class ClockInterface {
Loading