Skip to content

Commit

Permalink
Add preprocessor guards to allow build without threads/threadpool.
Browse files Browse the repository at this point in the history
  • Loading branch information
mingodad authored and Charles Baker committed Jul 16, 2023
1 parent 3d1351c commit a807827
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lalr/GrammarGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -49,7 +51,9 @@ using namespace lalr;
*/
GrammarGenerator::GrammarGenerator()
: error_policy_( nullptr )
#ifndef LALR_NO_THREADS
, thread_pool_( nullptr )
#endif
, identifier_()
, actions_()
, productions_()
Expand All @@ -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
Expand Down Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/lalr/GrammarGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace lalr
{

class ErrorPolicy;
#ifndef LALR_NO_THREADS
class ThreadPool;
#endif
class LexerStateMachine;
class GrammarCompiler;
class GrammarAction;
Expand All @@ -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.
Expand Down

0 comments on commit a807827

Please sign in to comment.