mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-28 17:16:29 +03:00
ecode: Added sol format support.
Added new option for the ThreadPool.
This commit is contained in:
@@ -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"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -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
@@ -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();
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user