ecode: Added sol format support.

Added new option for the ThreadPool.
This commit is contained in:
Martín Lucas Golini
2021-11-10 19:54:21 -03:00
parent 21e8ae53af
commit 63d998656d
7 changed files with 44 additions and 1092 deletions

View File

@@ -27,5 +27,11 @@
"warning_pattern": "[^:]:(%d+):(%d+):%s?([^%s]*)([^\n]*)",
"warning_pattern_order": { "line": 1, "col": 2, "message": 4, "type": 3 },
"command": "shellcheck -f gcc $FILENAME"
},
{
"file_patterns": ["%.sol$"],
"warning_pattern": "(%d+):(%d+)%s.(%w*)%s.([^\n]*)",
"warning_pattern_order": { "line": 1, "col": 2, "message": 4, "type": 3 },
"command": "solhint $FILENAME"
}
]

View File

@@ -15,13 +15,15 @@ namespace EE { namespace System {
class EE_API ThreadPool : NonCopyable {
public:
static std::shared_ptr<ThreadPool> createShared( Uint32 numThreads );
static std::shared_ptr<ThreadPool> createShared( Uint32 numThreads,
bool terminateOnClose = false );
static std::unique_ptr<ThreadPool> createUnique( Uint32 numThreads );
static std::unique_ptr<ThreadPool> createUnique( Uint32 numThreads,
bool terminateOnClose = false );
static ThreadPool* createRaw( Uint32 numThreads );
static ThreadPool* createRaw( Uint32 numThreads, bool terminateOnClose = false );
ThreadPool( Uint32 numThreads );
ThreadPool( Uint32 numThreads, bool terminateOnClose = false );
virtual ~ThreadPool();
@@ -29,6 +31,10 @@ class EE_API ThreadPool : NonCopyable {
Uint32 numThreads() const;
bool terminateOnClose() const;
void setTerminateOnClose( bool terminateOnClose );
private:
struct Work {
const std::function<void()> func;
@@ -40,6 +46,7 @@ class EE_API ThreadPool : NonCopyable {
std::vector<std::unique_ptr<Thread>> mThreads;
std::deque<std::unique_ptr<Work>> mWork;
bool mShuttingDown = false;
bool mTerminateOnClose = false;
mutable std::mutex mMutex;
std::condition_variable mWorkAvailable;
};

File diff suppressed because it is too large Load Diff

View File

@@ -2,21 +2,22 @@
namespace EE { namespace System {
std::shared_ptr<ThreadPool> ThreadPool::createShared( Uint32 numThreads ) {
std::shared_ptr<ThreadPool> pool( new ThreadPool( numThreads ) );
std::shared_ptr<ThreadPool> ThreadPool::createShared( Uint32 numThreads, bool terminateOnClose ) {
std::shared_ptr<ThreadPool> pool( new ThreadPool( numThreads, terminateOnClose ) );
return pool;
}
std::unique_ptr<ThreadPool> ThreadPool::createUnique( Uint32 numThreads ) {
std::unique_ptr<ThreadPool> pool( new ThreadPool( numThreads ) );
std::unique_ptr<ThreadPool> ThreadPool::createUnique( Uint32 numThreads, bool terminateOnClose ) {
std::unique_ptr<ThreadPool> pool( new ThreadPool( numThreads, terminateOnClose ) );
return pool;
}
ThreadPool* ThreadPool::createRaw( Uint32 numThreads ) {
return eeNew( ThreadPool, ( numThreads ) );
ThreadPool* ThreadPool::createRaw( Uint32 numThreads, bool terminateOnClose ) {
return eeNew( ThreadPool, ( numThreads, terminateOnClose ) );
}
ThreadPool::ThreadPool( Uint32 numThreads ) {
ThreadPool::ThreadPool( Uint32 numThreads, bool terminateOnClose ) :
mTerminateOnClose( terminateOnClose ) {
for ( Uint32 i = 0; i < numThreads; ++i ) {
mThreads.emplace_back( std::make_unique<Thread>( &ThreadPool::threadFunc, this ) );
mThreads.back().get()->launch();
@@ -32,7 +33,11 @@ ThreadPool::~ThreadPool() {
mWorkAvailable.notify_all();
for ( auto& t : mThreads ) {
t.get()->wait();
if ( terminateOnClose() ) {
t.get()->terminate();
} else {
t.get()->wait();
}
}
}
@@ -60,6 +65,14 @@ void ThreadPool::threadFunc() {
}
}
bool ThreadPool::terminateOnClose() const {
return mTerminateOnClose;
}
void ThreadPool::setTerminateOnClose( bool terminateOnClose ) {
mTerminateOnClose = terminateOnClose;
}
void ThreadPool::run( const std::function<void()>& func,
const std::function<void()>& doneCallback ) {
{
@@ -68,7 +81,7 @@ void ThreadPool::run( const std::function<void()>& func,
if ( mShuttingDown )
return;
mWork.emplace_back( new Work{func, doneCallback} );
mWork.emplace_back( new Work{ func, doneCallback } );
}
mWorkAvailable.notify_one();

View File

@@ -370,7 +370,7 @@ void App::onTextDropped( String text ) {
}
}
App::App() : mThreadPool( ThreadPool::createShared( eemax<int>( 2, Sys::getCPUCount() ) ) ) {}
App::App() : mThreadPool( ThreadPool::createShared( eemax<int>( 2, Sys::getCPUCount() ), true ) ) {}
App::~App() {
if ( mFileWatcher )

View File

@@ -135,11 +135,9 @@ void FormatterModule::runFormatter( UICodeEditor* editor, const Formatter& forma
if ( 0 == result ) {
std::string buffer( 1024, '\0' );
std::string data;
unsigned index = 0;
unsigned bytesRead = 0;
do {
bytesRead = subprocess_read_stdout( &subprocess, &buffer[0], buffer.size() );
index += bytesRead;
data += buffer.substr( 0, bytesRead );
} while ( bytesRead != 0 );

View File

@@ -220,11 +220,9 @@ void LinterModule::runLinter( std::shared_ptr<TextDocument> doc, const Linter& l
if ( 0 == result ) {
std::string buffer( 1024, '\0' );
std::string data;
unsigned index = 0;
unsigned bytesRead = 0;
do {
bytesRead = subprocess_read_stdout( &subprocess, &buffer[0], buffer.size() );
index += bytesRead;
data += buffer.substr( 0, bytesRead );
} while ( bytesRead != 0 );