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 10 seconds
25 #define CHECKER_WAIT_TIME 10
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;
55 ExpiryTimer_Impl(const ExpiryTimer_Impl&);
56 ExpiryTimer_Impl& operator=(const ExpiryTimer_Impl&);
60 static ExpiryTimer_Impl* getInstance();
63 Id postTimer(DelayMilliSec, TimerCb);
69 void insertTimerCBInfo(ExpiredTime, TimerCb ,Id);
70 ExpiredTime countExpireTime(milliSeconds);
75 void doExecutor(ExpiredTime);
78 static ExpiryTimer_Impl* s_instance;
79 static std::once_flag* mflag;
81 std::multimap<ExpiredTime, TimerCBInfo> mTimerCBList;
86 std::mutex cond_mutex;
87 std::condition_variable m_cond;
93 ExecutorThread(TimerCBInfo);
97 void executorFunc(TimerCBInfo);
104 #endif //_EXPIRY_TIMER_Impl_H_