queue_impl_t queue_impl_filter_out(queue_impl_t q, bool (*pred)(void*, void*), void *user) { auto sat_pred = tbb::concurrent_queue<void*>(); auto unsat_pred = tbb::concurrent_queue<void*>(); void* elem; while (queue_impl_dequeue(q, &elem)) { if (pred(elem, user)) { sat_pred.push(elem); } else { unsat_pred.push(elem); } } auto filtered = queue_impl_new(unsat_pred.unsafe_size()+1); while (unsat_pred.try_pop(elem)) queue_impl_enqueue(filtered, elem); while (sat_pred.try_pop(elem)) queue_impl_enqueue(q, elem); return filtered; }
pointer synchronized_try_pop(Mutex& mtx, CondVar& cv, const TimePoint& abs_time) { auto res = try_pop(); if (!res && synchronized_await(mtx, cv, abs_time)) { res = try_pop(); } return res; }
pointer synchronized_pop(Mutex& mtx, CondVar& cv) { auto res = try_pop(); if (!res) { synchronized_await(mtx, cv); res = try_pop(); } return res; }
value_type pop(){ value_type oRet; while (!try_pop(oRet)){ _WaitPolicy(); } return oRet; }
void try_checked_pop(struct pico_mqtt_list* list, uint32_t index, uint32_t length_after) { uint32_t length = 0; struct pico_mqtt_message* message = NULL; try_length(pico_mqtt_list_length(list, &length)); ck_assert_msg( length == length_after+1, "The length is not changed correctly\n"); try_pop(pico_mqtt_list_pop(list, &message)); ck_assert_msg( message->message_id == index, "Failed to pop the top of the message\n"); try_length(pico_mqtt_list_length(list, &length)); ck_assert_msg( length == length_after, "The length is not changed correctly\n"); }
/*! * Destructor */ ~threadsafe_queue() { // Clear the queue if (!unsafe_empty()) { value_type value; while (try_pop(value)); } // Remove the last dummy node node* p = static_cast< node* >(m_pImpl->reset_last_node()); p->~node(); base_type::deallocate(p, 1); delete m_pImpl; }
~destroy_producer_proxy() { static auto destroyers = std::make_shared<tbb::concurrent_bounded_queue<std::shared_ptr<executor>>>(); static tbb::atomic<int> destroyer_count; try { std::shared_ptr<executor> destroyer; if(!destroyers->try_pop(destroyer)) { destroyer.reset(new executor(L"destroyer")); destroyer->set_priority_class(below_normal_priority_class); if(++destroyer_count > 16) CASPAR_LOG(warning) << L"Potential destroyer dead-lock detected."; CASPAR_LOG(trace) << "Created destroyer: " << destroyer_count; } auto producer = producer_.release(); auto pool = destroyers; destroyer->begin_invoke([=] { std::unique_ptr<std::shared_ptr<frame_producer>> producer2(producer); auto str = (*producer2)->print(); try { if(!producer->unique()) CASPAR_LOG(trace) << str << L" Not destroyed on asynchronous destruction thread: " << producer->use_count(); else CASPAR_LOG(trace) << str << L" Destroying on asynchronous destruction thread."; } catch(...){} producer2.reset(); pool->push(destroyer); }); } catch(...) { CASPAR_LOG_CURRENT_EXCEPTION(); try { producer_.reset(); } catch(...){} } }
py::object unpack() { for( ;; ) { if( auto obj = next() ) { obj = try_pop( obj ); if( obj ) { return py::object( py::handle<>( obj ) ); } } } return py::object(); }
typename intrusive_lockfree_stack<T, E>::pointer intrusive_lockfree_stack<T, E>::pop() { pointer out(NULL); while(true) { switch(try_pop(out)) { case SUCCESS : return out; case EMPTY : return NULL; case CAS_FAILED : if(eliminate_pop(out)) return out; break; default: assert(false); } } }
bool pop(T* &target) { #if defined SLEEP_NO_YIELD const unsigned cnt_rnd(3); unsigned cnt(0); #endif for(;;) { if (try_pop(target)) return true; #if defined SLEEP_NO_YIELD if ((++cnt %= cnt_rnd) == 0) hypersleep<h_nanoseconds>(SLEEP_NO_YIELD); else #endif sched_yield(); } return false; }
END_TEST START_TEST(push_peek_length_and_pop_test) { struct pico_mqtt_list* list; struct pico_mqtt_message* message; int result = 0; uint32_t length = 0; result = pico_mqtt_list_create(&list); ck_assert_msg( result == SUCCES, "Failed to create the list\n"); try_length(pico_mqtt_list_length(list, &length)); ck_assert_msg( length == 0, "Failed to get the length of the list\n"); try_push(pico_mqtt_list_push(list, &test_messages[0])); try_length(pico_mqtt_list_length(list, &length)); ck_assert_msg( length == 1, "The length is not changed correctly\n"); try_peek(pico_mqtt_list_peek(list, &message)); ck_assert_msg( message->message_id == 0, "Failed to peek at the top of the message\n"); message = NULL; try_length(pico_mqtt_list_length(list, &length)); ck_assert_msg( length == 1, "The length should not have changed\n"); try_pop(pico_mqtt_list_pop(list, &message)); ck_assert_msg( message->message_id == 0, "Failed to pop the top of the message\n"); try_length(pico_mqtt_list_length(list, &length)); ck_assert_msg( length == 0, "The length is not changed correctly\n"); result = pico_mqtt_list_destroy(&list); ck_assert_msg( result == SUCCES, "Failed to destory the list\n"); }
inline mailbox_element* try_pop(const timeout_type& abs_time) { return (timed_wait_for_data(abs_time)) ? try_pop() : nullptr; }
mailbox_element* pop() { wait_for_data(); return try_pop(); }
mailbox_element* await_message(const timeout_type& abs_time) { return try_pop(abs_time); }
bool try_pop(Type &item) { // NOLINT return try_pop(item, core::always); }
//TODO at other end bool try_steal(JOB& job) { return try_pop(job); }