Use lock_guard and OSMemoryBarrier

This commit is contained in:
Maschell 2022-10-06 18:54:16 +02:00
parent 174d13339f
commit f399e97aa8
2 changed files with 5 additions and 9 deletions

View File

@ -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;
}

View File

@ -6,7 +6,7 @@ BackgroundThreadWrapper::BackgroundThreadWrapper(int32_t priority) : CThread(CTh
BackgroundThreadWrapper::~BackgroundThreadWrapper() {
exitThread = 1;
DCFlushRange((void *) &exitThread, 4);
OSMemoryBarrier();
}
void BackgroundThreadWrapper::executeThread() {