当前位置: 首页>>代码示例>>C++>>正文


C++ conditional类代码示例

本文整理汇总了C++中conditional的典型用法代码示例。如果您正苦于以下问题:C++ conditional类的具体用法?C++ conditional怎么用?C++ conditional使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了conditional类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: stop_blocking

 /** Wakes up all threads waiting on the queue whether 
     or not an element is available. Once this function is called,
     all existing and future dequeue operations will return with failure.
     Note that there could be elements remaining in the queue after 
     stop_blocking() is called. 
 */
 inline void stop_blocking() {
   m_mutex.lock();
   m_alive = false;
   m_conditional.broadcast();
   m_empty_conditional.broadcast();
   m_mutex.unlock();
 }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:13,代码来源:blocking_queue.hpp

示例2: operator

void repr_printer::operator()(const conditional &n) {
    m_os << "Conditional(";
    boost::apply_visitor(*this, n.cond());
    m_os << ", ";
    boost::apply_visitor(*this, n.then());
    m_os << ", ";
    boost::apply_visitor(*this, n.orelse());
    m_os << ")";
}
开发者ID:bryancatanzaro,项目名称:copperhead-compiler,代码行数:9,代码来源:repr_printer.cpp

示例3: enqueue_conditional_signal

 inline void enqueue_conditional_signal(const T& elem, size_t signal_at_size) {
   m_mutex.lock();
   m_queue.push_back(elem);
   // Signal threads waiting on the queue
   if (sleeping && m_queue.size() >= signal_at_size) m_conditional.signal();
   m_mutex.unlock();
 }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:7,代码来源:blocking_queue.hpp

示例4: enqueue_to_head

 //! Add an element to the blocking queue
 inline void enqueue_to_head(const T& elem) {
   m_mutex.lock();
   m_queue.push_front(elem);
   // Signal threads waiting on the queue
   if (sleeping) m_conditional.signal();
   m_mutex.unlock();
 }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:8,代码来源:blocking_queue.hpp

示例5: swap

 void swap(queue_type &q) {
   m_mutex.lock();
   q.swap(m_queue);
   if (m_queue.empty() && sleeping_on_empty) {
     m_empty_conditional.signal();
   }
   m_mutex.unlock();
 }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:8,代码来源:blocking_queue.hpp

示例6: dequeue_and_begin_critical_section_on_success

 inline std::pair<T, bool> dequeue_and_begin_critical_section_on_success() {
   m_mutex.lock();
   T elem = T();
   bool success = false;
   // Wait while the queue is empty and this queue is alive
   while(m_queue.empty() && m_alive) {
     sleeping++;
     m_conditional.wait(m_mutex);
     sleeping--;
   }
   // An element has been added or a signal was raised
   if(!m_queue.empty()) {
     success = true;
     elem = m_queue.front();
     m_queue.pop_front();
     if (m_queue.empty() && sleeping_on_empty) {
       m_empty_conditional.signal();
     }
   }
   if (!success) m_mutex.unlock(); 
   return std::make_pair(elem, success);
 }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:22,代码来源:blocking_queue.hpp

示例7: wait_until_empty

 /**
  * The conceptual "reverse" of dequeue().
  * This function will block until the queue becomes empty, or 
  * until stop_blocking() is called.
  * Returns true on success. 
  * Returns false if the queue is no longer alive
 */
 bool wait_until_empty() {
   m_mutex.lock();
   // if the queue still has elements in it while I am still alive, wait
   while (m_queue.empty() == false && m_alive == true) {
     sleeping_on_empty++;
     m_empty_conditional.wait(m_mutex);
     sleeping_on_empty--;
   }
   m_mutex.unlock();
   // if I am alive, the queue must be empty. i.e. success
   // otherwise I am dead
   return m_alive;
 }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:20,代码来源:blocking_queue.hpp

示例8: zk_callback

void zk_callback(zookeeper_util::server_list* slist,
                std::string name_space,
                std::vector<std::string> servers,
                std::vector<std::string>& result,
                size_t num_to_watch_for,
                mutex& result_lock,
                conditional& result_cond) {
  if (servers.size() == num_to_watch_for) {
    result_lock.lock();
    result = servers;
    slist->stop_watching("graphlab");
    result_cond.signal();
    result_lock.unlock();
  }
}
开发者ID:DreamStudio2015,项目名称:SFrame,代码行数:15,代码来源:dc_init_from_zookeeper.cpp

示例9: try_dequeue_in_critical_section

 inline std::pair<T, bool> try_dequeue_in_critical_section() {
   T elem = T();
   // Wait while the queue is empty and this queue is alive
   if (m_queue.empty() || m_alive == false) {
     return std::make_pair(elem, false);
   }
   else {
     elem = m_queue.front();
     m_queue.pop_front();
     if (m_queue.empty() && sleeping_on_empty) {
       m_empty_conditional.signal();
     }
     return std::make_pair(elem, true);
   }
 }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:15,代码来源:blocking_queue.hpp

示例10: wait_for_data

    inline bool wait_for_data() {

      m_mutex.lock();
      bool success = false;
      // Wait while the queue is empty and this queue is alive
      while(m_queue.empty() && m_alive) {
        sleeping++;
        m_conditional.wait(m_mutex);
        sleeping--;
      }
      // An element has been added or a signal was raised
      if(!m_queue.empty()) {
        success = true;
      } 
      m_mutex.unlock();

      return success; 
    }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:18,代码来源:blocking_queue.hpp

示例11: try_timed_wait_for_data

    /// Returns immediately of queue size is >= immedeiate_size
    /// Otherwise, it will poll over 'ns' nanoseconds or on a signal
    /// until queue is not empty.
    inline bool try_timed_wait_for_data(size_t ns, size_t immediate_size) {
      m_mutex.lock();
      bool success = false;
      // Wait while the queue is empty and this queue is alive
      if (m_queue.size() < immediate_size) {
        if (m_queue.empty() && m_alive) {
          sleeping++;
          m_conditional.timedwait_ns(m_mutex, ns);
          sleeping--;
        }
      }
      // An element has been added or a signal was raised
      if(!m_queue.empty()) {
        success = true;
      }
      m_mutex.unlock();

      return success; 
    }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:22,代码来源:blocking_queue.hpp

示例12: try_dequeue

    /**
    * Returns an element if the queue has an entry.
    * returns [item, false] otherwise.
    */
    inline std::pair<T, bool> try_dequeue() {
      if (m_queue.empty() || m_alive == false) return std::make_pair(T(), false);
      m_mutex.lock();
      T elem = T();
      // Wait while the queue is empty and this queue is alive
      if (m_queue.empty() || m_alive == false) {
        m_mutex.unlock();
        return std::make_pair(elem, false);
      }
      else {
        elem = m_queue.front();
        m_queue.pop_front();
        if (m_queue.empty() && sleeping_on_empty) {
          m_empty_conditional.signal();
        }
      }
      m_mutex.unlock();

      return std::make_pair(elem, true);
    }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:24,代码来源:blocking_queue.hpp

示例13: main

int perthreadtestApp::main (void)
{
	outputOne = outputTwo = outputThree = 0;
	__THREADED = true;
	testThread one (&outputOne, 18321);
	testThread two (&outputTwo, 33510);
	testThread three (&outputThree, 18495);
	
	one.sendevent ("shutdown");
	two.sendevent ("shutdown");
	three.sendevent ("shutdown");
	
	threadStopped.wait ();
	::printf ("%i %i %i\n", outputOne, outputTwo, outputThree);
	threadStopped.wait ();
	::printf ("%i %i %i\n", outputOne, outputTwo, outputThree);
	threadStopped.wait ();
	::printf ("%i %i %i\n", outputOne, outputTwo, outputThree);
	
	value out;
	out.newval() = outputOne;
	out.newval() = outputTwo;
	out.newval() = outputThree;
	
	out.savexml ("out.xml");
	return 0;
}
开发者ID:CloudVPS,项目名称:openpanel-grace,代码行数:27,代码来源:main.cpp

示例14: receive

 void receive(procid_t source, blob b) {
   mut.lock();
   val = b;
   valready = true;
   cond.signal();
   mut.unlock();
 }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:7,代码来源:request_reply_handler.hpp

示例15: log_rotation_background_thread

void log_rotation_background_thread() {
  while(thread_running) {
    // set up the current logger
    std::string current_log_file = make_file_name(log_base_name, log_counter);
    global_logger().set_log_file(current_log_file);
    unlink(symlink_name.c_str());
    symlink(current_log_file.c_str(), symlink_name.c_str());
    
    // if our counter exceeds the truncate limit, delete earlier files
    if (truncate_limit > 0 && log_counter >= truncate_limit) {
      // delete oldest files
      std::string oldest_log_file = make_file_name(log_base_name, 
                                                   log_counter - truncate_limit); 
      unlink(oldest_log_file.c_str());
    }

    // sleep for the log interval period.
    // We maintain our own additional timer to prevent spurious wakeups
    timer ti; ti.start();
    lock.lock();
    while (thread_running && ti.current_time() < log_interval) {
      cond.timedwait(lock, log_interval);
    }
    lock.unlock();

    ++log_counter;
  }
}
开发者ID:Hannah1999,项目名称:Dato-Core,代码行数:28,代码来源:log_rotate.cpp


注:本文中的conditional类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。