Sync mode for tiling progress enhanced - with progress now.

This commit is contained in:
Matthias Koefferlein 2021-03-13 10:12:01 +01:00
parent f323c830d7
commit 7c4c928632
2 changed files with 41 additions and 16 deletions

View File

@ -327,11 +327,14 @@ public:
: tl::JobBase (nworkers),
mp_proc (proc),
m_has_tiles (has_tiles),
m_progress (0)
m_progress_count (0),
m_progress (std::string ())
{
// .. nothing yet ..
}
void start (const std::string &job_description);
bool has_tiles () const
{
return m_has_tiles;
@ -340,18 +343,18 @@ public:
void next_progress ()
{
tl::MutexLocker locker (&m_mutex);
++m_progress;
++m_progress_count;
}
void update_progress (tl::RelativeProgress &progress)
void update_progress ()
{
unsigned int p;
{
tl::MutexLocker locker (&m_mutex);
p = m_progress;
p = m_progress_count;
}
progress.set (p, true /*force yield*/);
m_progress.set (p, true /*force yield*/);
}
TilingProcessor *processor () const
@ -361,11 +364,14 @@ public:
virtual tl::Worker *create_worker ();
virtual void after_sync_task (tl::Task *task);
private:
TilingProcessor *mp_proc;
bool m_has_tiles;
unsigned int m_progress;
unsigned int m_progress_count;
tl::Mutex m_mutex;
tl::RelativeProgress m_progress;
};
class TilingProcessorTask
@ -601,9 +607,25 @@ TilingProcessorJob::create_worker ()
return new TilingProcessorWorker (this);
}
void
TilingProcessorJob::after_sync_task (tl::Task * /*task*/)
{
// This needs to be done here as there is no external loop to do this
update_progress ();
}
void
TilingProcessorJob::start (const std::string &job_description)
{
m_progress = tl::RelativeProgress (job_description, tasks (), 1);
tl::JobBase::start ();
}
// ----------------------------------------------------------------------------------
// The tiling processor implementation
tl::Mutex TilingProcessor::s_output_lock;
TilingProcessor::TilingProcessor ()
: m_tile_width (0.0), m_tile_height (0.0),
m_ntiles_w (0), m_ntiles_h (0),
@ -781,7 +803,7 @@ TilingProcessor::output (const std::string &name, db::Edges &edges)
tl::Variant
TilingProcessor::receiver (const std::vector<tl::Variant> &args)
{
tl::MutexLocker locker (&m_output_mutex);
tl::MutexLocker locker (&s_output_lock);
if (args.size () != 1) {
throw tl::Exception (tl::to_string (tr ("_rec function requires one argument: the handle of the output channel")));
@ -803,7 +825,7 @@ TilingProcessor::receiver (const std::vector<tl::Variant> &args)
void
TilingProcessor::put (size_t ix, size_t iy, const db::Box &tile, const std::vector<tl::Variant> &args)
{
tl::MutexLocker locker (&m_output_mutex);
tl::MutexLocker locker (&s_output_lock);
if (args.size () < 2 || args.size () > 3) {
throw tl::Exception (tl::to_string (tr ("_output function requires two or three arguments: handle and object and a clip flag (optional)")));
@ -930,11 +952,6 @@ TilingProcessor::execute (const std::string &desc)
}
// TODO: there should be a general scheme of how thread-specific progress is merged
// into a global one ..
size_t todo_count = ntiles_w * ntiles_h * m_scripts.size ();
tl::RelativeProgress progress (desc, todo_count, 1);
try {
try {
@ -946,10 +963,10 @@ TilingProcessor::execute (const std::string &desc)
}
}
job.start ();
job.start (desc);
while (job.is_running ()) {
// This may throw an exception, if the cancel button has been pressed.
job.update_progress (progress);
job.update_progress ();
job.wait (100);
}

View File

@ -644,6 +644,14 @@ public:
*/
void execute (const std::string &desc);
/**
* @brief Gets the output mutex for operations not using the output method
*/
static tl::Mutex &output_lock ()
{
return s_output_lock;
}
private:
friend class TilingProcessorWorker;
friend class TilingProcessorOutputFunction;
@ -689,8 +697,8 @@ private:
bool m_dbu_specific_set;
bool m_scale_to_dbu;
std::vector<std::string> m_scripts;
tl::Mutex m_output_mutex;
tl::Eval m_top_eval;
static tl::Mutex s_output_lock;
};
}