mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-12-23 03:11:49 +01:00
Use lock_guard and OSMemoryBarrier
This commit is contained in:
parent
174d13339f
commit
f399e97aa8
@ -1,34 +1,31 @@
|
||||
#include "BackgroundThread.hpp"
|
||||
#include "ftp.h"
|
||||
#include "net.h"
|
||||
#include <cstring>
|
||||
#include <sys/socket.h>
|
||||
|
||||
BackgroundThread *BackgroundThread::instance = nullptr;
|
||||
|
||||
BackgroundThread::BackgroundThread() : BackgroundThreadWrapper(BackgroundThread::getPriority()) {
|
||||
DEBUG_FUNCTION_LINE("Start FTP Server");
|
||||
mutex.lock();
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
this->serverSocket = create_server(PORT);
|
||||
DCFlushRange(&(this->serverSocket), 4);
|
||||
mutex.unlock();
|
||||
OSMemoryBarrier();
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Resume Thread");
|
||||
CThread::resumeThread();
|
||||
}
|
||||
|
||||
BackgroundThread::~BackgroundThread() {
|
||||
DEBUG_FUNCTION_LINE("Shutting down FTP Server");
|
||||
mutex.lock();
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
if (this->serverSocket >= 0) {
|
||||
cleanup_ftp();
|
||||
network_close(this->serverSocket);
|
||||
this->serverSocket = -1;
|
||||
}
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
BOOL BackgroundThread::whileLoop() {
|
||||
mutex.lock();
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
||||
if (this->serverSocket >= 0) {
|
||||
network_down = process_ftp_events(this->serverSocket);
|
||||
if (network_down) {
|
||||
@ -45,7 +42,6 @@ BOOL BackgroundThread::whileLoop() {
|
||||
OSSleepTicks(OSSecondsToTicks(5));
|
||||
}
|
||||
}
|
||||
mutex.unlock();
|
||||
OSSleepTicks(OSMillisecondsToTicks(1));
|
||||
return true;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ BackgroundThreadWrapper::BackgroundThreadWrapper(int32_t priority) : CThread(CTh
|
||||
|
||||
BackgroundThreadWrapper::~BackgroundThreadWrapper() {
|
||||
exitThread = 1;
|
||||
DCFlushRange((void *) &exitThread, 4);
|
||||
OSMemoryBarrier();
|
||||
}
|
||||
|
||||
void BackgroundThreadWrapper::executeThread() {
|
||||
|
Loading…
Reference in New Issue
Block a user