Permalink
Browse files

Remove the unused 'incomplete and untested' BaseTaskThread class.

  • Loading branch information...
arcum42 committed Jan 10, 2019
1 parent e087760 commit 1b41d19016f23e10b1545f7314d298c77035c973
Showing with 0 additions and 124 deletions.
  1. +0 −67 common/include/Utilities/PersistentThread.h
  2. +0 −57 common/src/Utilities/ThreadTools.cpp
@@ -202,71 +202,4 @@ class pxThread
static void *_internal_callback(void *func);
static void _pt_callback_cleanup(void *handle);
};


// --------------------------------------------------------------------------------------
// BaseTaskThread
// --------------------------------------------------------------------------------------
// an abstract base class which provides simple parallel execution of single tasks.
//
// FIXME: This class is incomplete and untested! Don't use, unless you want to fix it
// while you're at it. :D
//
// Implementation:
// To use this class your derived class will need to implement its own Task() function
// and also a "StartTask( parameters )" function which suits the need of your task, along
// with any local variables your task needs to do its job. You may additionally want to
// implement a "GetResult()" function, which would be a combination of WaitForResult()
// and a return value of the computational result.
//
// Thread Safety:
// If operating on local variables, you must execute WaitForResult() before leaving the
// variable scope -- or alternatively have your StartTask() implementation make full
// copies of dependent data. Also, by default PostTask() always assumes the previous
// task has completed. If your system can post a new task before the previous one has
// completed, then it needs to explicitly call WaitForResult() or provide a mechanism
// to cancel the previous task (which is probably more work than it's worth).
//
// Performance notes:
// * Remember that thread creation is generally slow, so you should make your object
// instance once early and then feed it tasks repeatedly over the course of program
// execution.
//
// * For threading to be a successful speedup, the task being performed should be as lock
// free as possible. For example using STL containers in parallel usually fails to
// yield any speedup due to the gratuitous amount of locking that the STL performs
// internally.
//
// * The best application of tasking threads is to divide a large loop over a linear array
// into smaller sections. For example, if you have 20,000 items to process, the task
// can be divided into two threads of 10,000 items each.
//
class BaseTaskThread : public pxThread
{
protected:
std::atomic<bool> m_Done;
std::atomic<bool> m_TaskPending;
Semaphore m_post_TaskComplete;
Mutex m_lock_TaskComplete;

public:
virtual ~BaseTaskThread() = default;
BaseTaskThread()
: m_Done(false)
, m_TaskPending(false)
, m_post_TaskComplete()
{
}

void Block();
void PostTask();
void WaitForResult();

protected:
// Abstract method run when a task has been posted. Implementing classes should do
// all your necessary processing work here.
virtual void Task() = 0;

virtual void ExecuteTaskInThread();
};
}
@@ -698,63 +698,6 @@ void Threading::pxThread::_DoSetThreadName(const wxString &name)
_DoSetThreadName(static_cast<const char *>(name.ToUTF8()));
}

// --------------------------------------------------------------------------------------
// BaseTaskThread Implementations
// --------------------------------------------------------------------------------------

// Tells the thread to exit and then waits for thread termination.
void Threading::BaseTaskThread::Block()
{
if (!IsRunning())
return;
m_Done = true;
m_sem_event.Post();
pxThread::Block();
}

// Initiates the new task. This should be called after your own StartTask has
// initialized internal variables / preparations for task execution.
void Threading::BaseTaskThread::PostTask()
{
pxAssert(!m_detached);

ScopedLock locker(m_lock_TaskComplete);
m_TaskPending = true;
m_post_TaskComplete.Reset();
m_sem_event.Post();
}

// Blocks current thread execution pending the completion of the parallel task.
void Threading::BaseTaskThread::WaitForResult()
{
if (m_detached || !m_running)
return;
if (m_TaskPending)
#if wxUSE_GUI
m_post_TaskComplete.Wait();
#else
m_post_TaskComplete.WaitWithoutYield();
#endif

m_post_TaskComplete.Reset();
}

void Threading::BaseTaskThread::ExecuteTaskInThread()
{
while (!m_Done) {
// Wait for a job -- or get a pthread_cancel. I'm easy.
m_sem_event.WaitWithoutYield();

Task();
m_lock_TaskComplete.Acquire();
m_TaskPending = false;
m_post_TaskComplete.Post();
m_lock_TaskComplete.Release();
};

return;
}

// --------------------------------------------------------------------------------------
// pthread Cond is an evil api that is not suited for Pcsx2 needs.
// Let's not use it. (Air)

0 comments on commit 1b41d19

Please sign in to comment.