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