mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
re-add accidently deleted files
This commit is contained in:
parent
3373e24558
commit
f0de6e1712
25
moses/TranslationModel/UG/generic/threading/ug_ref_counter.h
Normal file
25
moses/TranslationModel/UG/generic/threading/ug_ref_counter.h
Normal file
@ -0,0 +1,25 @@
|
||||
#include "ug_thread_safe_counter.h"
|
||||
#pragma once
|
||||
// obsolete once intrusive_ref_counter is available everywhere
|
||||
|
||||
namespace Moses {
|
||||
|
||||
class reference_counter
|
||||
{
|
||||
public:
|
||||
friend void intrusive_ptr_add_ref(reference_counter const* p)
|
||||
{
|
||||
if (p) ++p->m_refcount;
|
||||
}
|
||||
friend void intrusive_ptr_release(reference_counter const* p)
|
||||
{
|
||||
if (p && --p->m_refcount == 0)
|
||||
delete p;
|
||||
}
|
||||
protected:
|
||||
reference_counter() {}
|
||||
virtual ~reference_counter() {};
|
||||
private:
|
||||
mutable ThreadSafeCounter m_refcount;
|
||||
};
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#include "ug_thread_pool.h"
|
||||
namespace ug {
|
||||
|
||||
ThreadPool::
|
||||
ThreadPool(size_t const num_workers)
|
||||
: m_service(), m_busywork(new boost::asio::io_service::work(m_service))
|
||||
{
|
||||
m_workers.reserve(num_workers);
|
||||
for (size_t i = 0; i < num_workers; ++i)
|
||||
{
|
||||
// boost::shared_ptr<boost::thread> t;
|
||||
// t.reset(new boost::thread(boost::bind(&service_t::run, &m_service)));
|
||||
boost::thread* t;
|
||||
t = new boost::thread(boost::bind(&service_t::run, &m_service));
|
||||
m_pool.add_thread(t);
|
||||
// m_workers.push_back(t);
|
||||
}
|
||||
}
|
||||
|
||||
ThreadPool::
|
||||
~ThreadPool()
|
||||
{
|
||||
m_busywork.reset();
|
||||
m_pool.join_all();
|
||||
m_service.stop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
30
moses/TranslationModel/UG/generic/threading/ug_thread_pool.h
Normal file
30
moses/TranslationModel/UG/generic/threading/ug_thread_pool.h
Normal file
@ -0,0 +1,30 @@
|
||||
// -*- mode: c++; tab-width: 2; indent-tabs-mode: nil -*-
|
||||
#pragma once
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace ug {
|
||||
class ThreadPool
|
||||
{
|
||||
typedef boost::asio::io_service service_t;
|
||||
service_t m_service;
|
||||
boost::thread_group m_pool;
|
||||
boost::scoped_ptr<service_t::work> m_busywork;
|
||||
std::vector<boost::shared_ptr<boost::thread> > m_workers;
|
||||
|
||||
public:
|
||||
ThreadPool(size_t const num_workers);
|
||||
~ThreadPool();
|
||||
|
||||
template<class callable>
|
||||
void add(callable& job) { m_service.post(job); }
|
||||
|
||||
}; // end of class declaration ThreadPool
|
||||
} // end of namespace ug
|
Loading…
Reference in New Issue
Block a user