Skip to content

Commit

Permalink
Formatting and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Jan 30, 2022
1 parent 2798272 commit dcbf322
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 38 deletions.
36 changes: 20 additions & 16 deletions src/utils/CThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class CThread {
typedef void (*Callback)(CThread *thread, void *arg);

//! constructor
explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
: pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) {
explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = nullptr, void *callbackArg = nullptr)
: pThread(nullptr), pThreadStack(nullptr), pCallback(callback), pCallbackArg(callbackArg) {
//! save attribute assignment
iAttributes = iAttr;
//! allocate the thread
Expand All @@ -43,7 +43,7 @@ class CThread {
}

//! destructor
virtual ~CThread() {
~CThread() {
shutdownThread();
}

Expand All @@ -58,36 +58,37 @@ class CThread {

//! Thread entry function
virtual void executeThread() {
if (pCallback)
if (pCallback) {
pCallback(this, pCallbackArg);
}
}

//! Suspend thread
virtual void suspendThread() {
if (isThreadSuspended()) return;
if (pThread) OSSuspendThread(pThread);
if (isThreadSuspended()) { return; }
if (pThread) { OSSuspendThread(pThread); }
}

//! Resume thread
virtual void resumeThread() {
if (!isThreadSuspended()) return;
if (pThread) OSResumeThread(pThread);
void resumeThread() {
if (!isThreadSuspended()) { return; }
if (pThread) { OSResumeThread(pThread); }
}

//! Set thread priority
virtual void setThreadPriority(int prio) {
if (pThread) OSSetThreadPriority(pThread, prio);
if (pThread) { OSSetThreadPriority(pThread, prio); }
}

//! Check if thread is suspended
[[nodiscard]] virtual BOOL isThreadSuspended() const {
if (pThread) return OSIsThreadSuspended(pThread);
if (pThread) { return OSIsThreadSuspended(pThread); }
return false;
}

//! Check if thread is terminated
[[nodiscard]] virtual BOOL isThreadTerminated() const {
if (pThread) return OSIsThreadTerminated(pThread);
if (pThread) { return OSIsThreadTerminated(pThread); }
return false;
}

Expand All @@ -97,19 +98,22 @@ class CThread {
}

//! Shutdown thread
virtual void shutdownThread() {
void shutdownThread() {
//! wait for thread to finish
if (pThread && !(iAttributes & eAttributeDetach)) {
if (isThreadSuspended())
if (isThreadSuspended()) {
resumeThread();
}

OSJoinThread(pThread, nullptr);
}
//! free the thread stack buffer
if (pThreadStack)
if (pThreadStack) {
free(pThreadStack);
if (pThread)
}
if (pThread) {
free(pThread);
}

pThread = nullptr;
pThreadStack = nullptr;
Expand Down
11 changes: 0 additions & 11 deletions src/utils/TcpReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ void TcpReceiver::executeThread() {

struct sockaddr_in clientAddr{};
memset(&clientAddr, 0, sizeof(clientAddr));
int32_t addrlen = sizeof(struct sockaddr);

while (!exitRequested) {
len = 16;
Expand All @@ -98,9 +97,6 @@ void TcpReceiver::executeThread() {
close(serverSocket);
}


extern bool gDoRelaunch;

int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
DEBUG_FUNCTION_LINE("Loading file from ip %08X", ipAddress);

Expand All @@ -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
}

struct in_addr in{};
uint32_t bytesRead = 0;
in.s_addr = ipAddress;

DEBUG_FUNCTION_LINE("transfer start");

auto *loadAddress = (unsigned char *) memalign(0x40, fileSize);
Expand All @@ -130,7 +123,6 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {

// Copy rpl in memory
while (bytesRead < fileSize) {

uint32_t blockSize = 0x1000;
if (blockSize > (fileSize - bytesRead))
blockSize = fileSize - bytesRead;
Expand Down Expand Up @@ -270,9 +262,6 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {

if (PluginUtils::LoadAndLinkOnRestart(finalList) != 0) {
DEBUG_FUNCTION_LINE("Failed to load & link");
} else {
//gDoRelaunch = true;
//DCFlushRange(&gDoRelaunch, sizeof(gDoRelaunch));
}
PluginUtils::destroyPluginContainer(finalList);

Expand Down
12 changes: 2 additions & 10 deletions src/utils/TcpReceiver.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef TCP_RECEIVER_H_
#define TCP_RECEIVER_H_
#pragma once

#include <vector>
#include <string>
Expand All @@ -19,13 +18,9 @@ class TcpReceiver : public CThread {

explicit TcpReceiver(int32_t port);

~TcpReceiver() override;

//sigslot::signal2<GuiElement *, uint32_t> serverReceiveStart;
//sigslot::signal3<GuiElement *, uint32_t, int32_t> serverReceiveFinished;
virtual ~TcpReceiver();

private:

void executeThread() override;

static int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress);
Expand All @@ -34,6 +29,3 @@ class TcpReceiver : public CThread {
int32_t serverPort;
int32_t serverSocket;
};


#endif
1 change: 0 additions & 1 deletion src/utils/utils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <string.h>
#include <stddef.h>
#include <whb/log.h>
#include "utils/logger.h"

Expand Down

0 comments on commit dcbf322

Please sign in to comment.