本文整理汇总了C++中std::queue::size方法的典型用法代码示例。如果您正苦于以下问题:C++ queue::size方法的具体用法?C++ queue::size怎么用?C++ queue::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::queue
的用法示例。
在下文中一共展示了queue::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: push
/**
* Push an element onto the queue. If the queue has a max size,
* this call will block if the queue is full.
*/
void push(T value) {
constexpr const std::chrono::milliseconds max_wait{10};
#ifdef OSMIUM_DEBUG_QUEUE_SIZE
++m_push_counter;
#endif
if (m_max_size) {
while (size() >= m_max_size) {
std::unique_lock<std::mutex> lock{m_mutex};
m_space_available.wait_for(lock, max_wait, [this] {
return m_queue.size() < m_max_size;
});
#ifdef OSMIUM_DEBUG_QUEUE_SIZE
++m_full_counter;
#endif
}
}
std::lock_guard<std::mutex> lock{m_mutex};
m_queue.push(std::move(value));
#ifdef OSMIUM_DEBUG_QUEUE_SIZE
if (m_largest_size < m_queue.size()) {
m_largest_size = m_queue.size();
}
#endif
m_data_available.notify_one();
}
示例2: consumeToLog
void consumeToLog()
{
while (true)
{
try
{
typename LogObject::SmartPtr logObj;
{
boost::mutex::scoped_lock lock(_qMutex);
while (_queue.size() == 0)
{
if (_isStopping)
{
std::cout << " Stopping consumeToLog Thread. " << std::endl;
return;
}
_qCondVar.wait(lock);
}
// Get the entry
logObj = _queue.front();
_queue.pop();
}
printLogObject(logObj);
}
catch (const boost::thread_interrupted& err)
{
std::cout << " Log::consumeToLog() - Got Interrupt Signal. " << _queue.size() << std::endl;
}
}//while
}
示例3: match
bool Market::match( std::queue < Order > & orders )
{
while ( true )
{
if ( !m_bidOrders.size() || !m_askOrders.size() )
return orders.size() != 0;
BidOrders::iterator iBid = m_bidOrders.begin();
AskOrders::iterator iAsk = m_askOrders.begin();
if ( iBid->second.getPrice() >= iAsk->second.getPrice() )
{
Order & bid = iBid->second;
Order& ask = iAsk->second;
match( bid, ask );
orders.push( bid );
orders.push( ask );
if ( bid.isClosed() ) m_bidOrders.erase( iBid );
if ( ask.isClosed() ) m_askOrders.erase( iAsk );
}
else
return orders.size() != 0;
}
}
示例4: Read
// Returns FALSE if message not read, TRUE if it was read. Will always return TRUE if "blocking" is set.
// Will throw MDFN_Error if the read message code is CDIF_MSG_FATAL_ERROR
bool CDIF_Queue::Read(CDIF_Message *message, bool blocking)
{
bool ret = true;
slock_lock((slock_t*)ze_mutex);
if(blocking)
{
while(ze_queue.size() == 0) // while, not just if.
scond_wait((scond_t*)ze_cond, (slock_t*)ze_mutex);
}
if(ze_queue.size() == 0)
ret = false;
else
{
*message = ze_queue.front();
ze_queue.pop();
}
slock_unlock((slock_t*)ze_mutex);
if(ret && message->message == CDIF_MSG_FATAL_ERROR)
throw MDFN_Error(0, "%s", message->str_message.c_str());
return(ret);
}
示例5: Queue
void Queue (int size, Type sample, std::queue<Type> &queue)
{ // number of parameters use to get the mean value.
// Fill the queue with n samples
if (queue.size() < size)
{ //add a new element in the queue
queue.push (sample);
}
if (queue.size() > size && !queue.empty())
{ //add a new element in the queue while reduce its size by two till the the queue reach a smaller size
//remove last element
queue.pop ();
//insert new element
queue.push (sample);
//remove last element
queue.pop ();
}
if (queue.size() == size && !queue.empty())
{ //remove last element
queue.pop();
//insert new element
queue.push (sample);
}
}
开发者ID:Brazilian-Institute-of-Robotics,项目名称:adap_parameters_estimator,代码行数:27,代码来源:adap_parameters.hpp
示例6: useFrame
void useFrame(cv::Mat& mRgba){
int64 now = cv::getTickCount();
int64 then;
time_queue.push(now);
// Process frame
if(mRgba.cols != 0) {
processFrame(mRgba);
char buffer[256];
sprintf(buffer, "Display performance: %dx%d @ %.3f", mRgba.cols, mRgba.rows, fps);
cv::putText(mRgba, std::string(buffer), cv::Point(8,64),
cv::FONT_HERSHEY_COMPLEX_SMALL, 1, cv::Scalar(0,255,255,255));
}
if (time_queue.size() >= 2)
then = time_queue.front();
else
then = 0;
if (time_queue.size() >= 25)
time_queue.pop();
fps = time_queue.size() * (float)cv::getTickFrequency() / (now-then);
}
示例7: GetDeviceData
//In morrowind this only got called for keyboards when typing into the console. Probably no point in overriding it
//And so it turns out that oblivion uses this whever it's in menumode instead of just consoles. Figures.
HRESULT _stdcall GetDeviceData(DWORD a,DIDEVICEOBJECTDATA* b,DWORD* c,DWORD d) {
if (bufferedPresses.empty())
return RealDevice->GetDeviceData(a,b,c,d);
if(!b) {
DWORD temp=*c;
HRESULT hr = RealDevice->GetDeviceData(a,b,c,d);
if(c) *c=min(bufferedPresses.size(),temp);
if(!(d|DIGDD_PEEK)) while(!bufferedPresses.empty()) bufferedPresses.pop();
return hr;
}
int count=0;
while (bufferedPresses.size()) {
//Stricktly speaking, should return a buffer overflow by here, but if you do it breaks?
//Presumably, if you could mash your keyboard fast enough, no keypresses would register...
if(count==*c) return DI_OK; //DI_BUFFEROVERFLOW;
//This will not work correctly if DIGDD_PEEK is specified. afaik, it's only ever used if b == NULL
*b=bufferedPresses.front();
bufferedPresses.pop();
b+=sizeof(void*);
count++;
}
if(count==*c) return DI_OK;
//Can probably just return DI_OK here, because afaik *c is only ever 1 unless oblivion is trying to empty the buffer
*c-=count;
HRESULT hr=RealDevice->GetDeviceData(a,b,c,d);
*c+=count;
return hr;
}
示例8: main
int main(int argc, const char * argv[])
{
scanf("%s%s", s1, s2);
if(strlen(s1) != strlen(s2)){
puts("-1");
}else{
for(int i = 0;s1[i];++i){
if(s1[i] == '+')
a.push(i);
if(s2[i] == '+')
b.push(i);
}
if(a.size() != b.size()){
//puts("diff size");
puts("-1");
}else{
int ans = 0;
while(!a.empty()){
ans += abs(a.front() - b.front());
a.pop();
b.pop();
}
printf("%d\n", ans);
}
}
return 0;
}
示例9: thread_save_image
void* thread_save_image(void*) {
timespec time_save0, time_save1, t_sleep, t_rem;
t_sleep.tv_sec = 0;
t_sleep.tv_nsec = 10;
for (;;) {
// Wait for image capture
if (save_frame_buffer.size() > 0) {
clock_gettime( CLOCK_REALTIME, &time_save0);
write_jpeg(save_frame_buffer.front());
// write_png(save_frame_buffer.front());
if (save_frame_buffer.size() > 4) {
int bufsize = save_frame_buffer.front().width *
save_frame_buffer.front().height *
save_frame_buffer.size() / 1024.0;
std::cout << "\rBuffer queue: "
<< bufsize << " kB " << std::flush;
}
std::cout << "d" << std::flush;
pthread_mutex_lock( &save_buffer_mutex );
save_frame_buffer.pop();
pthread_mutex_unlock( &save_buffer_mutex );
clock_gettime(CLOCK_REALTIME, &time_save1);
double twrite = tdiff(time_save1, time_save0);
} else {
nanosleep(&t_sleep, &t_rem);
}
}
}
示例10: Read
// Returns false if message not read, true if it was read. Will always return true if "blocking" is set.
// Will throw MDFN_Error if the read message code is CDIF_MSG_FATAL_ERROR
bool CDIF_Queue::Read(CDIF_Message *message, bool blocking)
{
bool ret = true;
//
//
//
MDFND_LockMutex(ze_mutex);
if(blocking)
{
while(ze_queue.size() == 0) // while, not just if.
{
MDFND_WaitCond(ze_cond, ze_mutex);
}
}
if(ze_queue.size() == 0)
ret = false;
else
{
*message = ze_queue.front();
ze_queue.pop();
}
MDFND_UnlockMutex(ze_mutex);
//
//
//
//if(ret && message->message == CDIF_MSG_FATAL_ERROR)
// throw MDFN_Error(0, "%s", message->str_message.c_str());
return(ret);
}
示例11: print
/** print queues */
void print(){
std::cout << "\n" << std::endl;
int i;
for(i=0; i<master.size(); ++i){
struct Qu t = master.front();
std::cout << "master: " << t.proc_num << std::endl;
master.pop();
master.push(t);
}
for(i=0; i<ready.size(); ++i){
struct Qu t = ready.front();
std::cout << "ready: " << t.proc_num << std::endl;
ready.pop();
ready.push(t);
}
for(i=0; i<waiting.size(); ++i){
struct Qu t = waiting.front();
std::cout << "waiting: " << t.proc_num << std::endl;
waiting.pop();
waiting.push(t);
}
for(i=0; i<completed.size(); ++i){
struct Qu t = completed.front();
std::cout << "completed: " << t.proc_num << std::endl;
completed.pop();
completed.push(t);
}
for(i=0; i<priority.size(); ++i){
struct Qu t = priority.front();
std::cout << "priority " << t.proc_num << std::endl;
priority.pop_front();
priority.push_back(t);
}
}
示例12: check
void check()
{
BOOST_REQUIRE(queue);
BOOST_CHECK_EQUAL((u_int32_t) ids.size(), queue->getMessageCount());
while (pop()) ;//keeping popping 'till all messages are dequeued
BOOST_CHECK_EQUAL((u_int32_t) 0, queue->getMessageCount());
BOOST_CHECK_EQUAL((size_t) 0, ids.size());
}
示例13: waitThreads
void TaskEngine::waitThreads() {
if (tasks.size() > 0) {
SDL_LockMutex(threadLock);
while (tasks.size() != 0) {
SDL_CondWait(taskAvailable, threadLock);
}
SDL_UnlockMutex(threadLock);
}
}
示例14: LogThread
UINT CALLBACK LogThread(void* param)
{
TCHAR fileName[MAX_PATH];
LogPath(fileName, _T("log"));
while ( m_bLoggerRunning || (m_logQueue.size() > 0) )
{
if ( m_logQueue.size() > 0 )
{
SYSTEMTIME systemTime;
GetLocalTime(&systemTime);
WIN32_FILE_ATTRIBUTE_DATA fileInformation;
GetFileAttributesEx(fileName, GetFileExInfoStandard, &fileInformation);
if(logFileParsed != systemTime.wDay || fileInformation.nFileSizeLow > 10485760)
{
LogRotate();
logFileParsed=systemTime.wDay;
LogPath(fileName, _T("log"));
}
CAutoLock lock(&m_logFileLock);
FILE* fp = _tfopen(fileName, _T("a+"));
if (fp!=NULL)
{
SYSTEMTIME systemTime;
GetLocalTime(&systemTime);
wstring line = GetLogLine();
while (!line.empty())
{
fwprintf_s(fp, L"%s", line.c_str());
line = GetLogLine();
}
fclose(fp);
}
else //discard data
{
wstring line = GetLogLine();
while (!line.empty())
{
line = GetLogLine();
}
}
}
if (m_bLoggerRunning)
{
m_EndLoggingEvent.Wait(1000); //Sleep for 1000ms, unless thread is ending
}
else
{
Sleep(1);
}
}
_endthreadex(0);
return 0;
}
示例15: merge_thread
void merge_thread(void *arg) {
merge_arg_t a, b, c;
bool cont, quit;
while (true) {
cont = false;
quit = false;
size_t waiting = 0, remaining = 0;
while (true) {
pthread_mutex_lock(&parts_mutex);
waiting = pending_parts.size();
remaining = remaining_parts;
pthread_mutex_unlock(&parts_mutex);
if (waiting >= 2) {
pthread_mutex_lock(&parts_mutex);
a = pending_parts.front();
pending_parts.pop();
b = pending_parts.front();
pending_parts.pop();
remaining_parts -= 1;
pthread_mutex_unlock(&parts_mutex);
break;
} else if (waiting + remaining >= 2) {
if (pthread_mutex_trylock(&parts_exist_mutex) != 0) {
return;
}
} else {
return;
}
}
c.data = merge_sorted(a, b);
c.begin = 0;
c.end = c.data->size();
c.delete_data_when_done = true;
pthread_mutex_lock(&parts_mutex);
pending_parts.push(c);
if (pending_parts.size() <= 2) {
pthread_mutex_trylock(&parts_exist_mutex);
pthread_mutex_unlock(&parts_exist_mutex);
}
pthread_mutex_unlock(&parts_mutex);
}
}