Formatting and clean up

This commit is contained in:
Maschell 2022-01-30 17:54:27 +01:00
parent 2798272513
commit dcbf322005
4 changed files with 22 additions and 38 deletions

View File

@ -27,8 +27,8 @@ public:
typedef void (*Callback)(CThread *thread, void *arg); typedef void (*Callback)(CThread *thread, void *arg);
//! constructor //! constructor
explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL) explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = nullptr, void *callbackArg = nullptr)
: pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) { : pThread(nullptr), pThreadStack(nullptr), pCallback(callback), pCallbackArg(callbackArg) {
//! save attribute assignment //! save attribute assignment
iAttributes = iAttr; iAttributes = iAttr;
//! allocate the thread //! allocate the thread
@ -43,7 +43,7 @@ public:
} }
//! destructor //! destructor
virtual ~CThread() { ~CThread() {
shutdownThread(); shutdownThread();
} }
@ -58,36 +58,37 @@ public:
//! Thread entry function //! Thread entry function
virtual void executeThread() { virtual void executeThread() {
if (pCallback) if (pCallback) {
pCallback(this, pCallbackArg); pCallback(this, pCallbackArg);
}
} }
//! Suspend thread //! Suspend thread
virtual void suspendThread() { virtual void suspendThread() {
if (isThreadSuspended()) return; if (isThreadSuspended()) { return; }
if (pThread) OSSuspendThread(pThread); if (pThread) { OSSuspendThread(pThread); }
} }
//! Resume thread //! Resume thread
virtual void resumeThread() { void resumeThread() {
if (!isThreadSuspended()) return; if (!isThreadSuspended()) { return; }
if (pThread) OSResumeThread(pThread); if (pThread) { OSResumeThread(pThread); }
} }
//! Set thread priority //! Set thread priority
virtual void setThreadPriority(int prio) { virtual void setThreadPriority(int prio) {
if (pThread) OSSetThreadPriority(pThread, prio); if (pThread) { OSSetThreadPriority(pThread, prio); }
} }
//! Check if thread is suspended //! Check if thread is suspended
[[nodiscard]] virtual BOOL isThreadSuspended() const { [[nodiscard]] virtual BOOL isThreadSuspended() const {
if (pThread) return OSIsThreadSuspended(pThread); if (pThread) { return OSIsThreadSuspended(pThread); }
return false; return false;
} }
//! Check if thread is terminated //! Check if thread is terminated
[[nodiscard]] virtual BOOL isThreadTerminated() const { [[nodiscard]] virtual BOOL isThreadTerminated() const {
if (pThread) return OSIsThreadTerminated(pThread); if (pThread) { return OSIsThreadTerminated(pThread); }
return false; return false;
} }
@ -97,19 +98,22 @@ public:
} }
//! Shutdown thread //! Shutdown thread
virtual void shutdownThread() { void shutdownThread() {
//! wait for thread to finish //! wait for thread to finish
if (pThread && !(iAttributes & eAttributeDetach)) { if (pThread && !(iAttributes & eAttributeDetach)) {
if (isThreadSuspended()) if (isThreadSuspended()) {
resumeThread(); resumeThread();
}
OSJoinThread(pThread, nullptr); OSJoinThread(pThread, nullptr);
} }
//! free the thread stack buffer //! free the thread stack buffer
if (pThreadStack) if (pThreadStack) {
free(pThreadStack); free(pThreadStack);
if (pThread) }
if (pThread) {
free(pThread); free(pThread);
}
pThread = nullptr; pThread = nullptr;
pThreadStack = nullptr; pThreadStack = nullptr;

View File

@ -73,7 +73,6 @@ void TcpReceiver::executeThread() {
struct sockaddr_in clientAddr{}; struct sockaddr_in clientAddr{};
memset(&clientAddr, 0, sizeof(clientAddr)); memset(&clientAddr, 0, sizeof(clientAddr));
int32_t addrlen = sizeof(struct sockaddr);
while (!exitRequested) { while (!exitRequested) {
len = 16; len = 16;
@ -98,9 +97,6 @@ void TcpReceiver::executeThread() {
close(serverSocket); close(serverSocket);
} }
extern bool gDoRelaunch;
int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) { int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
DEBUG_FUNCTION_LINE("Loading file from ip %08X", ipAddress); DEBUG_FUNCTION_LINE("Loading file from ip %08X", ipAddress);
@ -116,10 +112,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
recvwait(clientSocket, (unsigned char *) &fileSizeUnc, sizeof(fileSizeUnc)); // Compressed protocol, read another 4 bytes recvwait(clientSocket, (unsigned char *) &fileSizeUnc, sizeof(fileSizeUnc)); // Compressed protocol, read another 4 bytes
} }
struct in_addr in{};
uint32_t bytesRead = 0; uint32_t bytesRead = 0;
in.s_addr = ipAddress;
DEBUG_FUNCTION_LINE("transfer start"); DEBUG_FUNCTION_LINE("transfer start");
auto *loadAddress = (unsigned char *) memalign(0x40, fileSize); auto *loadAddress = (unsigned char *) memalign(0x40, fileSize);
@ -130,7 +123,6 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
// Copy rpl in memory // Copy rpl in memory
while (bytesRead < fileSize) { while (bytesRead < fileSize) {
uint32_t blockSize = 0x1000; uint32_t blockSize = 0x1000;
if (blockSize > (fileSize - bytesRead)) if (blockSize > (fileSize - bytesRead))
blockSize = fileSize - bytesRead; blockSize = fileSize - bytesRead;
@ -270,9 +262,6 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
if (PluginUtils::LoadAndLinkOnRestart(finalList) != 0) { if (PluginUtils::LoadAndLinkOnRestart(finalList) != 0) {
DEBUG_FUNCTION_LINE("Failed to load & link"); DEBUG_FUNCTION_LINE("Failed to load & link");
} else {
//gDoRelaunch = true;
//DCFlushRange(&gDoRelaunch, sizeof(gDoRelaunch));
} }
PluginUtils::destroyPluginContainer(finalList); PluginUtils::destroyPluginContainer(finalList);

View File

@ -1,5 +1,4 @@
#ifndef TCP_RECEIVER_H_ #pragma once
#define TCP_RECEIVER_H_
#include <vector> #include <vector>
#include <string> #include <string>
@ -19,13 +18,9 @@ public:
explicit TcpReceiver(int32_t port); explicit TcpReceiver(int32_t port);
~TcpReceiver() override; virtual ~TcpReceiver();
//sigslot::signal2<GuiElement *, uint32_t> serverReceiveStart;
//sigslot::signal3<GuiElement *, uint32_t, int32_t> serverReceiveFinished;
private: private:
void executeThread() override; void executeThread() override;
static int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress); static int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress);
@ -34,6 +29,3 @@ private:
int32_t serverPort; int32_t serverPort;
int32_t serverSocket; int32_t serverSocket;
}; };
#endif

View File

@ -1,5 +1,4 @@
#include <string.h> #include <string.h>
#include <stddef.h>
#include <whb/log.h> #include <whb/log.h>
#include "utils/logger.h" #include "utils/logger.h"