MCPcopy Create free account
hub / github.com/Tencent/phxsql / HasToken

Method HasToken

phxsqlclient/utils/leakybucket.cpp:134–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134bool MmapLeakyBucket::HasToken() {
135 if (NULL == m_poLock || NULL == m_ptBucket)
136 return -1;
137
138 m_poLock->WriteLockW(0);
139
140 unsigned int tLatestRefillTime = (unsigned int) time(NULL);
141 tLatestRefillTime = tLatestRefillTime - tLatestRefillTime % (m_tConfig.tRefillPeriod);
142
143 if (m_ptBucket->tLatestRefillTime != tLatestRefillTime) {
144 m_ptBucket->tLatestRefillTime = tLatestRefillTime;
145 m_ptBucket->iTokenCount = m_tConfig.iBucketSize;
146 }
147
148 bool ret = m_ptBucket->iTokenCount > 0;
149
150 m_poLock->Unlock(0);
151
152 return ret;
153}
154
155int MmapLeakyBucket::Apply(int iCount) {
156 if (NULL == m_poLock || NULL == m_ptBucket)

Callers 1

GetEndPointMethod · 0.45

Calls 2

WriteLockWMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected