1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef _EXPIRY_TIMER_Impl_H_
22 #define _EXPIRY_TIMER_Impl_H_
24 // CHECKER_WAIT_TIME : checker thread waits new request for 10000 seconds
25 #define CHECKER_WAIT_TIME 10000
33 #include <condition_variable>
35 class ExpiryTimer_Impl
38 typedef unsigned int Id;
39 typedef std::function<void*(Id)> TimerCb;
41 typedef long long DelayMilliSec;
42 typedef std::chrono::milliseconds milliSeconds;
43 typedef std::chrono::duration<int64_t, std::milli> milliDelayTime;
44 typedef std::chrono::duration<int64_t, std::milli> ExpiredTime;
60 static ExpiryTimer_Impl* getInstance();
62 Id postTimer(DelayMilliSec, TimerCb);
68 void insertTimerCBInfo(ExpiredTime, TimerCb ,Id);
69 ExpiredTime countExpireTime(milliSeconds);
74 void doExecutor(ExpiredTime);
77 static ExpiryTimer_Impl* s_instance;
78 static std::once_flag mflag;
80 std::multimap<ExpiredTime, TimerCBInfo> mTimerCBList;
84 std::mutex cond_mutex;
85 std::condition_variable m_cond;
91 ExecutorThread(TimerCBInfo);
95 void executorFunc(TimerCBInfo);
102 #endif //_EXPIRY_TIMER_Impl_H_