• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ conditional类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了conditional类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: make_file_name

namespace graphlab {

static std::string log_base_name;
static std::string symlink_name;
static size_t log_counter = 0;
static size_t log_interval = 24 * 60 * 60;
static size_t truncate_limit = 2;
static thread log_rotate_thread;
static mutex lock;
static conditional cond;
static bool thread_running = false;

std::string make_file_name(std::string base_name, size_t ctr) {
  return base_name + "." + std::to_string(ctr);
}

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;
  }
}

void begin_log_rotation(std::string _log_file_name, 
                        size_t _log_interval,
                        size_t _truncate_limit) {
  if (_truncate_limit == 0) throw "Truncate limit must be >= 1";
  stop_log_rotation();
  // set up global variables
  log_base_name = _log_file_name;
  log_interval = _log_interval;
  truncate_limit = _truncate_limit;
  log_counter = 0;
  symlink_name = log_base_name;

  thread_running = true;
  log_rotate_thread.launch(log_rotation_background_thread);
}

void stop_log_rotation() {
  // if no log rotation active, quit.
  if (!thread_running) return;
  // join the log rotation thread.
  lock.lock();
  thread_running = false;
  cond.signal();
  lock.unlock();
  log_rotate_thread.join();
  // we will continue logging to the same location, but we will 
  // delete the symlink
  unlink(symlink_name.c_str());
}

} // namespace graphlab
开发者ID:Hannah1999,项目名称:Dato-Core,代码行数:76,代码来源:log_rotate.cpp


示例14: broadcast

 /**
  * Causes any threads currently blocking on a dequeue to wake up
  * and evaluate the state of the queue. If the queue is empty,
  * the threads will return back to sleep immediately. If the queue
  * is destroyed through stop_blocking, all threads will return. 
  */
 void broadcast() {
   m_mutex.lock();
   m_conditional.broadcast();
   m_mutex.unlock();
 }
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:11,代码来源:blocking_queue.hpp


示例15: broadcast_blocking_empty

 /**
  * Causes any threads blocking on "wait_until_empty()" to wake
  * up and evaluate the state of the queue. If the queue is not empty,
  * the threads will return back to sleep immediately. If the queue
  * is empty, all threads will return.
 */
 void broadcast_blocking_empty() {
   m_mutex.lock();
   m_empty_conditional.broadcast();
   m_mutex.unlock();
 }    
开发者ID:3upperm2n,项目名称:PowerGraph,代码行数:11,代码来源:blocking_queue.hpp


示例16: 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


示例17: 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


示例18: 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


示例19: post

 inline void post() const {
   mut.lock();
   if (waitercount > 0) {
     cond.signal();
   }
   semvalue++;
   mut.unlock();
 }
开发者ID:greeness,项目名称:graphlab_CMU,代码行数:8,代码来源:pthread_tools.hpp


示例20: wait

 inline void wait() const {
   mut.lock();
   waitercount++;
   while (semvalue == 0) {
     cond.wait(mut);
   }
   waitercount--;
   semvalue--;
   mut.unlock();
 }
开发者ID:greeness,项目名称:graphlab_CMU,代码行数:10,代码来源:pthread_tools.hpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ condor_sockaddr类代码示例发布时间:2022-05-31
下一篇:
C++ condition_variable类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap