Skip to content

Commit

Permalink
fix compile in mac
Browse files Browse the repository at this point in the history
  • Loading branch information
lihuiba committed Sep 13, 2023
1 parent 5043029 commit 8bef227
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 8 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
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

5 changes: 2 additions & 3 deletions thread/thread11.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ 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)...);
Expand Down Expand Up @@ -103,7 +102,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 8bef227

Please sign in to comment.