Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preprocessor guards to allow build without threads/threadpool. #43

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading