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

Method Apply

phxsqlclient/utils/leakybucket.cpp:155–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155int MmapLeakyBucket::Apply(int iCount) {
156 if (NULL == m_poLock || NULL == m_ptBucket)
157 return -1;
158
159 m_poLock->WriteLockW(0);
160
161 unsigned int tLatestRefillTime = (unsigned int) time(NULL);
162 tLatestRefillTime = tLatestRefillTime - tLatestRefillTime % (m_tConfig.tRefillPeriod);
163
164 if (m_ptBucket->tLatestRefillTime != tLatestRefillTime) {
165 m_ptBucket->tLatestRefillTime = tLatestRefillTime;
166 m_ptBucket->iTokenCount = m_tConfig.iBucketSize;
167 }
168
169 int ret = -1;
170 if (m_ptBucket->iTokenCount >= iCount) {
171 m_ptBucket->iTokenCount -= iCount;
172 ret = 0;
173 }
174
175 m_poLock->Unlock(0);
176
177 return ret;
178}
179
180void MmapLeakyBucket::SetConfig(Config_t &config) {
181 if (NULL == m_poLock)

Callers 1

ReportEndPointMethod · 0.45

Calls 2

WriteLockWMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected