mirror of
https://github.com/cathery/sys-con.git
synced 2024-10-06 06:19:43 +00:00
SwitchThread: Add Initialize() for manual thread creation
This commit is contained in:
parent
b4dfe8a548
commit
4f1247fe0c
@ -13,8 +13,9 @@ private:
|
|||||||
static void ThreadLoop(void *argument);
|
static void ThreadLoop(void *argument);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SwitchThread() = default;
|
SwitchThread(){};
|
||||||
|
|
||||||
|
//Constructs the class by creating and starting the thread.
|
||||||
//function - the function you want to be called
|
//function - the function you want to be called
|
||||||
//argument - the argument passed to that function
|
//argument - the argument passed to that function
|
||||||
//stackSize - the stack size of the created thread
|
//stackSize - the stack size of the created thread
|
||||||
@ -27,11 +28,19 @@ public:
|
|||||||
//Closes the thread upon exiting
|
//Closes the thread upon exiting
|
||||||
~SwitchThread();
|
~SwitchThread();
|
||||||
|
|
||||||
//Starts the thread. This is called automatically upon class creation.
|
//Creates the thread.
|
||||||
Result Start();
|
//function - the function you want to be called
|
||||||
|
//argument - the argument passed to that function
|
||||||
|
//stackSize - the stack size of the created thread
|
||||||
|
//prio - thread priority, 0x00 - highest, 0x3F - lowest. Switch uses 0x2C
|
||||||
|
Result Initialize(size_t stackSize, int prio);
|
||||||
|
|
||||||
|
//Starts the thread. The given function will be called with the given argument in a loop until the thread is closed.
|
||||||
|
Result Start(ThreadFunc function, void *argument);
|
||||||
|
|
||||||
|
//Closes the thread.
|
||||||
//This will block the caller indefinitely until the thread is returned!
|
//This will block the caller indefinitely until the thread is returned!
|
||||||
Result Close();
|
Result Exit();
|
||||||
|
|
||||||
bool inline IsRunning() { return m_isRunning; }
|
bool inline IsRunning() { return m_isRunning; }
|
||||||
};
|
};
|
@ -11,31 +11,38 @@ void SwitchThread::ThreadLoop(void *argument)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SwitchThread::SwitchThread(ThreadFunc function, void *argument, size_t stackSize, int prio)
|
SwitchThread::SwitchThread(ThreadFunc function, void *argument, size_t stackSize, int prio)
|
||||||
: m_function(function), m_argument(argument)
|
|
||||||
{
|
{
|
||||||
if (R_SUCCEEDED(threadCreate(&m_thread, &SwitchThread::ThreadLoop, this, NULL, stackSize, prio, -2)))
|
if (R_SUCCEEDED(Initialize(stackSize, prio)))
|
||||||
{
|
{
|
||||||
Start();
|
Start(function, argument);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result SwitchThread::Initialize(size_t stackSize, int prio)
|
||||||
|
{
|
||||||
|
Result rc = threadCreate(&m_thread, &SwitchThread::ThreadLoop, this, NULL, stackSize, prio, -2);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
SwitchThread::~SwitchThread()
|
SwitchThread::~SwitchThread()
|
||||||
{
|
{
|
||||||
Close();
|
Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SwitchThread::Start()
|
Result SwitchThread::Start(ThreadFunc function, void *argument)
|
||||||
{
|
{
|
||||||
if (!m_isRunning)
|
if (!m_isRunning)
|
||||||
{
|
{
|
||||||
m_isRunning = true;
|
m_isRunning = true;
|
||||||
|
m_function = function;
|
||||||
|
m_argument = argument;
|
||||||
return threadStart(&m_thread);
|
return threadStart(&m_thread);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SwitchThread::Close()
|
Result SwitchThread::Exit()
|
||||||
{
|
{
|
||||||
if (m_isRunning)
|
if (m_isRunning)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user