NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
neforce::http::token_bucket结构体 参考

令牌桶数据结构 更多...

#include <rate_limiter.hpp>

Public 成员函数

bool try_consume (uint64_t now_ms)
 尝试消耗一个令牌
void refill (uint64_t now_ms)
 补充令牌(基于时间差)

Public 属性

double tokens {0.}
 当前令牌数
uint64_t last_refill_ms {0}
 上次补充时间(毫秒时间戳)
double refill_rate {1.}
 每秒补充令牌数
double capacity {1.}
 桶容量
mutex mutex_
 保护内部状态

详细描述

令牌桶数据结构

使用原子操作实现无锁的令牌消耗和补充。

在文件 rate_limiter.hpp32 行定义.

成员函数说明

◆ refill()

void neforce::http::token_bucket::refill ( uint64_t now_ms)

补充令牌(基于时间差)

参数
now_ms当前时间

◆ try_consume()

bool neforce::http::token_bucket::try_consume ( uint64_t now_ms)

尝试消耗一个令牌

参数
now_ms当前时间(毫秒时间戳)
返回
消耗成功返回true(频次未超限)

先补充令牌(基于时间差),再尝试消耗。


该结构体的文档由以下文件生成: