mirror of
https://github.com/cwbaker/lalr.git
synced 2026-09-26 16:33:18 +03:00
Add preprocessor guards to allow build without threads/threadpool.
This commit is contained in:
parent
3d1351c555
commit
a807827db8
2 changed files with 19 additions and 1 deletions
|
|
@ -21,7 +21,9 @@
|
|||
#include "ParserStateMachine.hpp"
|
||||
#include "RegexGenerator.hpp"
|
||||
#include "RegexCompiler.hpp"
|
||||
#ifndef LALR_NO_THREADS
|
||||
#include "ThreadPool.hpp"
|
||||
#endif
|
||||
#include "ErrorPolicy.hpp"
|
||||
#include "ErrorCode.hpp"
|
||||
#include "assert.hpp"
|
||||
|
|
@ -49,7 +51,9 @@ using namespace lalr;
|
|||
*/
|
||||
GrammarGenerator::GrammarGenerator()
|
||||
: error_policy_( nullptr )
|
||||
#ifndef LALR_NO_THREADS
|
||||
, thread_pool_( nullptr )
|
||||
#endif
|
||||
, identifier_()
|
||||
, actions_()
|
||||
, productions_()
|
||||
|
|
@ -64,14 +68,18 @@ GrammarGenerator::GrammarGenerator()
|
|||
, start_state_( nullptr )
|
||||
, errors_( 0 )
|
||||
{
|
||||
#ifndef LALR_NO_THREADS
|
||||
thread_pool_ = new ThreadPool;
|
||||
thread_pool_->start( 8 );
|
||||
#endif
|
||||
}
|
||||
|
||||
GrammarGenerator::~GrammarGenerator()
|
||||
{
|
||||
#ifndef LALR_NO_THREADS
|
||||
delete thread_pool_;
|
||||
thread_pool_ = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
const std::vector<std::unique_ptr<GrammarAction>>& GrammarGenerator::actions() const
|
||||
|
|
@ -756,7 +764,9 @@ void GrammarGenerator::generate_goto_items()
|
|||
{
|
||||
for ( const shared_ptr<GrammarState>& state : states_ )
|
||||
{
|
||||
#ifndef LALR_NO_THREADS
|
||||
thread_pool_->push_job( [this, state]()
|
||||
#endif
|
||||
{
|
||||
for ( GrammarTransition* transition : state->transitions() )
|
||||
{
|
||||
|
|
@ -799,9 +809,13 @@ void GrammarGenerator::generate_goto_items()
|
|||
}
|
||||
}
|
||||
}
|
||||
#ifndef LALR_NO_THREADS
|
||||
);
|
||||
#endif
|
||||
}
|
||||
thread_pool_->wait_idle();
|
||||
#ifndef LALR_NO_THREADS
|
||||
thread_pool_->wait_idle();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ namespace lalr
|
|||
{
|
||||
|
||||
class ErrorPolicy;
|
||||
#ifndef LALR_NO_THREADS
|
||||
class ThreadPool;
|
||||
#endif
|
||||
class LexerStateMachine;
|
||||
class GrammarCompiler;
|
||||
class GrammarAction;
|
||||
|
|
@ -34,7 +36,9 @@ class Grammar;
|
|||
class GrammarGenerator
|
||||
{
|
||||
ErrorPolicy* error_policy_; ///< The event sink to report errors to and print with or null to ignore errors and prints.
|
||||
#ifndef LALR_NO_THREADS
|
||||
ThreadPool* thread_pool_; ///< The pool of threads to use to generate the parser.
|
||||
#endif
|
||||
std::string identifier_; ///< The identifier of the parser.
|
||||
std::vector<std::unique_ptr<GrammarAction>> actions_; ///< The actions in the parser.
|
||||
std::vector<std::unique_ptr<GrammarProduction>> productions_; ///< The productions in the parser.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue