job/queue: add default constructor

This commit is contained in:
Danny Robson 2018-03-27 16:16:13 +11:00
parent 429c0151db
commit d941188dd5
2 changed files with 32 additions and 4 deletions

View File

@ -16,12 +16,43 @@
#include "queue.hpp" #include "queue.hpp"
#include "../parse.hpp"
#include "../raii.hpp" #include "../raii.hpp"
using util::job::queue; using util::job::queue;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static unsigned
default_parallelism (void)
{
if (auto var = getenv ("JOB_THREADS")) {
return util::parse<unsigned> (var);
}
return std::thread::hardware_concurrency ();
}
//-----------------------------------------------------------------------------
static unsigned
default_depth (void)
{
if (auto var = getenv ("JOB_DEPTH")) {
return util::parse<unsigned> (var);
}
return 1024;
}
///////////////////////////////////////////////////////////////////////////////
queue::queue ():
queue (default_parallelism (), default_depth ())
{ ; }
//-----------------------------------------------------------------------------
queue::queue (unsigned thread_count, unsigned pool_size): queue::queue (unsigned thread_count, unsigned pool_size):
m_tasks { m_tasks {
{}, util::pool<task> {pool_size}, {}, {} {}, util::pool<task> {pool_size}, {}, {}

View File

@ -41,10 +41,7 @@
namespace util::job { namespace util::job {
class queue { class queue {
public: public:
queue (): queue ();
queue (std::thread::hardware_concurrency (), 1024)
{ ; }
queue (unsigned thread_count, unsigned pool_size); queue (unsigned thread_count, unsigned pool_size);
~queue (); ~queue ();