diff --git a/base/src/refbase.cpp b/base/src/refbase.cpp index dff86ab0c9b60891eef96bfb0353a64d31ec3888..d7e007a5253f12901a8d1a985d084c53472f7190 100644 --- a/base/src/refbase.cpp +++ b/base/src/refbase.cpp @@ -395,7 +395,7 @@ bool RefCounter::AttemptIncStrong(const void *objectId) RefBase::RefBase() : refs_(new RefCounter()) { refs_->IncRefCount(); - refs_->SetCallback(std::bind(&RefBase::RefPtrCallback, this)); + refs_->SetCallback([this] { this->RefPtrCallback(); }); } RefBase::RefBase(const RefBase &) @@ -403,7 +403,7 @@ RefBase::RefBase(const RefBase &) refs_ = new (std::nothrow) RefCounter(); if (refs_ != nullptr) { refs_->IncRefCount(); - refs_->SetCallback(std::bind(&RefBase::RefPtrCallback, this)); + refs_->SetCallback([this] { this->RefPtrCallback(); }); } } @@ -428,7 +428,7 @@ RefBase &RefBase::operator=(const RefBase &) refs_ = new (std::nothrow) RefCounter(); if (refs_ != nullptr) { refs_->IncRefCount(); - refs_->SetCallback(std::bind(&RefBase::RefPtrCallback, this)); + refs_->SetCallback([this] { this->RefPtrCallback(); }); } return *this; diff --git a/base/src/thread_pool.cpp b/base/src/thread_pool.cpp index 2a2c2111749ee444f7719ae4a5356ce90fe5a271..8cfa83f6823fffbb779ff50fab66a1ef3ac49a97 100644 --- a/base/src/thread_pool.cpp +++ b/base/src/thread_pool.cpp @@ -47,7 +47,7 @@ uint32_t ThreadPool::Start(int numThreads) threads_.reserve(numThreads); for (int i = 0; i < numThreads; ++i) { - std::thread t(&ThreadPool::WorkInThread, this); + std::thread t([this] { this->WorkInThread(); }); // Give the name of ThreadPool to threads created by the ThreadPool. int err = pthread_setname_np(t.native_handle(), (myName_ + std::to_string(i)).c_str()); if (err != 0) { diff --git a/base/src/timer.cpp b/base/src/timer.cpp index 4d80e6783f3f672567f18cff5e9c80f1bf28e08b..e921a4110c7e9aa25fbb125024c461bf3c814b05 100644 --- a/base/src/timer.cpp +++ b/base/src/timer.cpp @@ -41,7 +41,7 @@ uint32_t Timer::Setup() return TIMER_ERR_INVALID_VALUE; } reactor_->SwitchOn(); - std::thread loop_thread(std::bind(&Timer::MainLoop, this)); + std::thread loop_thread([this] { this->MainLoop(); }); thread_.swap(loop_thread); return TIMER_ERR_OK; @@ -85,7 +85,7 @@ uint32_t Timer::Register(const TimerCallback& callback, uint32_t interval /* ms static std::atomic_uint32_t timerId = 1; int timerFd = once ? INVALID_TIMER_FD : GetTimerFd(interval); if (timerFd == INVALID_TIMER_FD) { - uint32_t ret = DoRegister(std::bind(&Timer::OnTimer, this, std::placeholders::_1), interval, once, timerFd); + uint32_t ret = DoRegister([this](int fd) { this->OnTimer(fd); }, interval, once, timerFd); if (ret != TIMER_ERR_OK) { UTILS_LOGE("do register interval timer %{public}d failed, return %{public}u", interval, ret); return TIMER_ERR_DEAL_FAILED; @@ -155,8 +155,7 @@ void Timer::MainLoop() uint32_t Timer::DoRegister(const TimerListCallback& callback, uint32_t interval, bool once, int &timerFd) { - using namespace std::placeholders; - std::function cb = std::bind(&Timer::DoTimerListCallback, this, callback, _1); + std::function cb = [this, callback](int fd) { this->DoTimerListCallback(callback, fd); }; uint32_t ret = reactor_->ScheduleTimer(cb, interval, timerFd, once); if ((ret != TIMER_ERR_OK) || (timerFd < 0)) { UTILS_LOGE("ScheduleTimer failed!ret:%{public}d, timerFd:%{public}d", ret, timerFd); diff --git a/base/src/timer_event_handler.cpp b/base/src/timer_event_handler.cpp index c18f4f45f287c1036501299089be1008eb1cef80..aa603ed50e7add9c4b8991a0500add6e29e79a6e 100644 --- a/base/src/timer_event_handler.cpp +++ b/base/src/timer_event_handler.cpp @@ -80,7 +80,7 @@ uint32_t TimerEventHandler::Initialize() return TIMER_ERR_DEAL_FAILED; } - SetReadCallback(std::bind(&TimerEventHandler::TimeOut, this)); + SetReadCallback([this] { this->TimeOut(); }); EnableRead(); return TIMER_ERR_OK; }