天天看点

高性能高并发的生成唯一的Id

可以吗?

int TimeWheel::GenerateTimerID()
{
    int x = rand() % 0xffffffff;
    int cur_time = time(nullptr);
    return x | cur_time | _timer_count;
}
int TimeWheel::AddTimer(int interval)
{
    timer_id = GenerateTimerID();
    _timer_count++;
    return timer_id;
}      

继续阅读