Skip to content

Commit

Permalink
fix compile on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
lihuiba authored and beef9999 committed Sep 20, 2023
1 parent 8515e14 commit 56fb370
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 16 deletions.
10 changes: 5 additions & 5 deletions common/test/test_alog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class LogOutputTest : public ILogOutput {
}
const char* log_start() const {
auto ls = _log_buf;
for (int i = 0; i < 4; i++)
for (int i = 0; i < 4; i++)
ls = strchr(ls, '|') + 1;
ls = strchr(ls, ':') + 1;
return ls;
Expand Down Expand Up @@ -493,7 +493,7 @@ void testnull_func() {
}

void segfault() {
char *pc = nullptr;
volatile char *pc = nullptr;
*pc = 'w'; //this must trigger sigfault
}

Expand Down Expand Up @@ -522,21 +522,21 @@ TEST(ALog, LOG_LIMIT) {
auto x = 0;
for (int i=0; i< 1000000;i++) {
// every 60 secs print only once
LOG_EVERY_T(60, LOG_INFO("LOG once every 60 second ...", x++));
LOG_EVERY_T(60, LOG_INFO("LOG once every 60 second ...", x++));
}
// suppose to print and evaluate 1 times
EXPECT_EQ(1, x);
x = 0;
for (int i=0; i< 1000000;i++) {
// every 100`000 times logs only only once
LOG_EVERY_N(100000, LOG_INFO("LOG once every 100000 logs ...", x++));
LOG_EVERY_N(100000, LOG_INFO("LOG once every 100000 logs ...", x++));
}
// suppose to print and evaluate 1`000`000 / 100`000 = 10 times
EXPECT_EQ(10, x);
x = 0;
for (int i=0; i< 1000000;i++) {
// logs only 10 records.
LOG_FIRST_N(10, LOG_INFO("LOG first 10 logs ...", x++));
LOG_FIRST_N(10, LOG_INFO("LOG first 10 logs ...", x++));
}
// suppose to print and evaluate 10 times
EXPECT_EQ(10, x);
Expand Down
8 changes: 4 additions & 4 deletions common/tuple-assistance.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct callable<F&> : public callable<F> {};
template <class F>
struct callable<F&&> : public callable<F> {};

#if __cplusplus < 201700
// #if __cplusplus < 201700
template <typename F, typename Tuple, std::size_t... I>
constexpr inline decltype(auto) apply_impl(F&& f, Tuple&& t,
std::index_sequence<I...>) {
Expand All @@ -90,9 +90,9 @@ constexpr inline decltype(auto) apply(F&& f, Tuple&& t) {
std::tuple_size<std::remove_reference_t<Tuple>>::value>{});
}

#else
using std::apply;
#endif
// #else
// using std::apply;
// #endif

template <typename P, size_t I, typename... Ts>
struct do_enumerate;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions thread/test/build-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
g++ -std=c++17 -I ../../include/ -I../../third_party/include -DThreadUT test.cpp x.cpp \
../thread-pool.cpp ../workerpool.cpp ../thread-key.cpp \
../../common/identity-pool.cpp ../../common/alog.cpp -lgtest -lgflags -O2

1 change: 0 additions & 1 deletion thread/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ inline int posix_memalign(void** memptr, size_t alignment, size_t size) {
by target vcpu in resume_thread(), when its runq becomes empty;
*/


#define SCOPED_MEMBER_LOCK(x) SCOPED_LOCK(&(x)->lock, ((bool)x) * 2)

// Define assembly section header for clang and gcc
Expand Down
12 changes: 6 additions & 6 deletions thread/thread11.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ namespace photon {
return th;
}

template<typename FUNCTOR>
template<typename FUNCTOR, typename...ARGUMENTS>
struct FunctorWrapper {
typename std::decay<FUNCTOR>::type _obj;
template<typename...ARGUMENTS>
__attribute__((always_inline))
void operator()(ARGUMENTS&&...args) {
_obj(std::forward<ARGUMENTS>(args)...);
// __attribute__((always_inline))
int operator()(ARGUMENTS&...args) {
_obj(std::move(args)...);
return 0;
}
};

Expand Down Expand Up @@ -103,7 +103,7 @@ namespace photon {
template<typename FUNCTOR, typename...ARGUMENTS>
inline _ENABLE_IF((is_functor<FUNCTOR, ARGUMENTS...>::value))
thread_create11(uint64_t stack_size, FUNCTOR&& f, ARGUMENTS&&...args) {
using Wrapper = FunctorWrapper<FUNCTOR>;
using Wrapper = FunctorWrapper<FUNCTOR, ARGUMENTS...>;
using SavedArgs = std::tuple<typename std::decay<ARGUMENTS>::type ...>;
return __thread_create11<Wrapper, SavedArgs, ARGUMENTS...>(
stack_size, Wrapper{std::forward<FUNCTOR>(f)},
Expand Down

0 comments on commit 56fb370

Please sign in to comment.