mirror of
https://github.com/Theaninova/BeatLanguageMapper.git
synced 2026-01-19 16:33:03 +00:00
Mk2Rev1
various bugfixes and such. also bookmarks, temp song loaderm and undo overhaul with near complete multiplayer, but menu items disabled. i really wish i could split this into multiple commits, but i don't know how to work unreal.
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include "WindowsFileUtilityPrivatePCH.h"
|
||||
#include "WFULambdaRunnable.h"
|
||||
|
||||
uint64 WFULambdaRunnable::ThreadNumber = 0;
|
||||
|
||||
FQueuedThreadPool* WFULambdaRunnable::ThreadPool = nullptr;
|
||||
|
||||
WFULambdaRunnable::WFULambdaRunnable(TFunction< void()> InFunction)
|
||||
{
|
||||
FunctionPointer = InFunction;
|
||||
|
||||
FString threadStatGroup = FString::Printf(TEXT("FLambdaRunnable%d"), ThreadNumber++);
|
||||
Thread = NULL;
|
||||
Thread = FRunnableThread::Create(this, *threadStatGroup, 0, TPri_BelowNormal); //windows default = 8mb for thread, could specify more
|
||||
}
|
||||
|
||||
WFULambdaRunnable::~WFULambdaRunnable()
|
||||
{
|
||||
if (Thread == NULL)
|
||||
{
|
||||
delete Thread;
|
||||
Thread = NULL;
|
||||
}
|
||||
|
||||
ThreadPool->Destroy();
|
||||
}
|
||||
|
||||
//Run
|
||||
uint32 WFULambdaRunnable::Run()
|
||||
{
|
||||
if (FunctionPointer)
|
||||
FunctionPointer();
|
||||
|
||||
//UE_LOG(LogClass, Log, TEXT("FLambdaRunnable %d Run complete"), Number);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WFULambdaRunnable::Exit()
|
||||
{
|
||||
//UE_LOG(LogClass, Log, TEXT("FLambdaRunnable %d Exit"), Number);
|
||||
|
||||
//delete ourselves when we're done
|
||||
delete this;
|
||||
}
|
||||
|
||||
void WFULambdaRunnable::InitThreadPool(int32 NumberOfThreads)
|
||||
{
|
||||
if (ThreadPool == nullptr)
|
||||
{
|
||||
ThreadPool = FQueuedThreadPool::Allocate();
|
||||
int32 NumThreadsInThreadPool = NumberOfThreads;
|
||||
ThreadPool->Create(NumThreadsInThreadPool, 32 * 1024);
|
||||
}
|
||||
}
|
||||
|
||||
void WFULambdaRunnable::EnsureCompletion()
|
||||
{
|
||||
Thread->WaitForCompletion();
|
||||
}
|
||||
|
||||
WFULambdaRunnable* WFULambdaRunnable::RunLambdaOnBackGroundThread(TFunction< void()> InFunction)
|
||||
{
|
||||
if (FPlatformProcess::SupportsMultithreading())
|
||||
{
|
||||
//UE_LOG(LogClass, Log, TEXT("FLambdaRunnable RunLambdaBackGroundThread"));
|
||||
return new WFULambdaRunnable(InFunction);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IQueuedWork* WFULambdaRunnable::AddLambdaToQueue(TFunction< void()> InFunction)
|
||||
{
|
||||
if (ThreadPool == nullptr)
|
||||
{
|
||||
WFULambdaRunnable::InitThreadPool(FPlatformMisc::NumberOfIOWorkerThreadsToSpawn());
|
||||
}
|
||||
|
||||
if (ThreadPool)
|
||||
{
|
||||
return AsyncLambdaPool(*ThreadPool, InFunction);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool WFULambdaRunnable::RemoveLambdaFromQueue(IQueuedWork* Work)
|
||||
{
|
||||
if (ThreadPool)
|
||||
{
|
||||
return ThreadPool->RetractQueuedWork(Work);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FGraphEventRef WFULambdaRunnable::RunShortLambdaOnGameThread(TFunction< void()> InFunction)
|
||||
{
|
||||
return FFunctionGraphTask::CreateAndDispatchWhenReady(InFunction, TStatId(), nullptr, ENamedThreads::GameThread);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user