本文整理汇总了C++中Transport::incuSleepTime方法的典型用法代码示例。如果您正苦于以下问题:C++ Transport::incuSleepTime方法的具体用法?C++ Transport::incuSleepTime怎么用?C++ Transport::incuSleepTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transport
的用法示例。
在下文中一共展示了Transport::incuSleepTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HHVM_FUNCTION
String HHVM_FUNCTION(uniqid, const String& prefix /* = null_string */,
bool more_entropy /* = false */) {
if (!more_entropy) {
Transport *transport = g_context->getTransport();
if (transport) {
transport->incuSleepTime(1);
}
usleep(1);
}
struct timeval tv;
gettimeofday((struct timeval *)&tv, NULL);
int sec = (int)tv.tv_sec;
int usec = (int)(tv.tv_usec % 0x100000);
String uniqid(prefix.size() + 64, ReserveString);
auto ptr = uniqid.mutableData();
// StringData::capacity() returns the buffer size without the null
// terminator. snprintf expects a the buffer capacity including room
// for the null terminator, writes the null termintor, and returns
// the full length not counting the null terminator.
auto capacity = uniqid.capacity() + 1;
int64_t len;
if (more_entropy) {
len = snprintf(ptr, capacity, "%s%08x%05x%.8F",
prefix.c_str(), sec, usec, math_combined_lcg() * 10);
} else {
len = snprintf(ptr, capacity, "%s%08x%05x",
prefix.c_str(), sec, usec);
}
uniqid.setSize(len);
return uniqid;
}
示例2: HHVM_FUNCTION
String HHVM_FUNCTION(uniqid, const String& prefix /* = null_string */,
bool more_entropy /* = false */) {
if (!more_entropy) {
Transport *transport = g_context->getTransport();
if (transport) {
transport->incuSleepTime(1);
}
usleep(1);
}
struct timeval tv;
gettimeofday((struct timeval *)&tv, NULL);
int sec = (int)tv.tv_sec;
int usec = (int)(tv.tv_usec % 0x100000);
String uniqid(prefix.size() + 64, ReserveString);
auto ptr = uniqid.bufferSlice().ptr;
auto capacity = uniqid.get()->capacity();
int64_t len;
if (more_entropy) {
len = snprintf(ptr, capacity, "%s%08x%05x%.8F",
prefix.c_str(), sec, usec, math_combined_lcg() * 10);
} else {
len = snprintf(ptr, capacity, "%s%08x%05x",
prefix.c_str(), sec, usec);
}
uniqid.setSize(len);
return uniqid;
}
示例3: f_uniqid
String f_uniqid(const String& prefix /* = null_string */,
bool more_entropy /* = false */) {
if (!more_entropy) {
Transport *transport = g_context->getTransport();
if (transport) {
transport->incuSleepTime(1);
}
usleep(1);
}
struct timeval tv;
gettimeofday((struct timeval *)&tv, NULL);
int sec = (int)tv.tv_sec;
int usec = (int)(tv.tv_usec % 0x100000);
char uniqid[256];
if (more_entropy) {
snprintf(uniqid, sizeof(uniqid), "%s%08x%05x%.8F",
prefix.c_str(), sec, usec, math_combined_lcg() * 10);
} else {
snprintf(uniqid, sizeof(uniqid), "%s%08x%05x",
prefix.c_str(), sec, usec);
}
return String(uniqid, CopyString);
}