[*] Continued loop work (Linux and Win32)
This commit is contained in:
parent
da506dd0d8
commit
d3428f4cd9
@ -266,9 +266,8 @@ namespace Aurora::IO::FS
|
||||
|
||||
void PosixFileStream::Close()
|
||||
{
|
||||
int handle;
|
||||
|
||||
if ((handle = std::exchange(this->handle_, -1)) != -1)
|
||||
int handle = AuExchange(this->handle_, -1);
|
||||
if (handle != -1)
|
||||
{
|
||||
::close(handle);
|
||||
}
|
||||
|
@ -16,6 +16,15 @@ namespace Aurora::Loop
|
||||
Init(triggered);
|
||||
}
|
||||
|
||||
LSEvent::~LSEvent()
|
||||
{
|
||||
if ((this->handle != 0) &&
|
||||
(this->handle != -1))
|
||||
{
|
||||
close(this->handle);
|
||||
}
|
||||
}
|
||||
|
||||
bool LSEvent::OnTrigger(AuUInt handle)
|
||||
{
|
||||
AuUInt64 oldSemaphoreValue {};
|
||||
|
@ -13,7 +13,8 @@ namespace Aurora::Loop
|
||||
struct LSEvent : public ILSEvent, public LSHandle
|
||||
{
|
||||
LSEvent(bool triggered, bool atomicRelease, bool permitMultipleTriggers);
|
||||
|
||||
~LSEvent();
|
||||
|
||||
bool Set() override;
|
||||
bool Reset() override;
|
||||
|
||||
|
@ -15,6 +15,12 @@ namespace Aurora::Loop
|
||||
|
||||
}
|
||||
|
||||
LSEvent::~LSEvent()
|
||||
{
|
||||
auto handle = reinterpret_cast<HANDLE>(this->handle);
|
||||
AuWin32CloseHandle(handle);
|
||||
}
|
||||
|
||||
bool LSEvent::Set()
|
||||
{
|
||||
return SetEvent(reinterpret_cast<HANDLE>(this->handle));
|
||||
|
@ -13,6 +13,7 @@ namespace Aurora::Loop
|
||||
struct LSEvent : public ILSEvent, public LSHandle
|
||||
{
|
||||
LSEvent(bool triggered, bool atomicRelease, bool permitMultipleTriggers);
|
||||
~LSEvent();
|
||||
|
||||
bool Set() override;
|
||||
bool Reset() override;
|
||||
|
@ -14,6 +14,16 @@ namespace Aurora::Loop
|
||||
{
|
||||
LSMutex::LSMutex()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
LSMutex::~LSMutex()
|
||||
{
|
||||
if ((this->handle != 0) &&
|
||||
(this->handle != -1))
|
||||
{
|
||||
::close(this->handle);
|
||||
}
|
||||
}
|
||||
|
||||
bool LSMutex::OnTrigger(AuUInt handle)
|
||||
|
@ -13,6 +13,7 @@ namespace Aurora::Loop
|
||||
struct LSMutex : public ILSMutex, public LSHandle
|
||||
{
|
||||
LSMutex();
|
||||
~LSMutex();
|
||||
|
||||
bool Unlock() override;
|
||||
|
||||
|
@ -10,6 +10,15 @@
|
||||
|
||||
namespace Aurora::Loop
|
||||
{
|
||||
Mutex::Mutex(HANDLE handle) : LSHandle(reinterpret_cast<AuUInt>(handle))
|
||||
{}
|
||||
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
auto handle = reinterpret_cast<HANDLE>(this->handle);
|
||||
AuWin32CloseHandle(handle);
|
||||
}
|
||||
|
||||
bool Mutex::Unlock()
|
||||
{
|
||||
return ReleaseMutex(reinterpret_cast<HANDLE>(handle));
|
||||
|
@ -13,8 +13,8 @@ namespace Aurora::Loop
|
||||
class Mutex : public ILSMutex, public LSHandle
|
||||
{
|
||||
public:
|
||||
Mutex(HANDLE handle) : LSHandle(reinterpret_cast<AuUInt>(handle))
|
||||
{}
|
||||
Mutex(HANDLE handle);
|
||||
~Mutex();
|
||||
|
||||
bool Unlock() override;
|
||||
|
||||
|
@ -16,6 +16,15 @@ namespace Aurora::Loop
|
||||
Init(initialCount);
|
||||
}
|
||||
|
||||
LSSemaphore::~LSSemaphore()
|
||||
{
|
||||
if ((this->handle != 0) &&
|
||||
(this->handle != -1))
|
||||
{
|
||||
::close(this->handle);
|
||||
}
|
||||
}
|
||||
|
||||
void LSSemaphore::Init(AuUInt32 initialCount)
|
||||
{
|
||||
handle = eventfd(initialCount, EFD_SEMAPHORE | EFD_NONBLOCK);
|
||||
|
@ -13,6 +13,7 @@ namespace Aurora::Loop
|
||||
struct LSSemaphore : public ILSSemaphore, public LSHandle
|
||||
{
|
||||
LSSemaphore(AuUInt32 initialCount);
|
||||
~LSSemaphore();
|
||||
|
||||
bool AddOne() override;
|
||||
|
||||
|
@ -10,6 +10,15 @@
|
||||
|
||||
namespace Aurora::Loop
|
||||
{
|
||||
LSSemaphore::LSSemaphore(HANDLE handle) : LSHandle(reinterpret_cast<AuUInt>(handle))
|
||||
{}
|
||||
|
||||
LSSemaphore::~LSSemaphore()
|
||||
{
|
||||
auto handle = reinterpret_cast<HANDLE>(this->handle);
|
||||
AuWin32CloseHandle(handle);
|
||||
}
|
||||
|
||||
bool LSSemaphore::AddOne()
|
||||
{
|
||||
LONG atomicOld;
|
||||
|
@ -13,8 +13,8 @@ namespace Aurora::Loop
|
||||
class LSSemaphore : public ILSSemaphore, public LSHandle
|
||||
{
|
||||
public:
|
||||
LSSemaphore(HANDLE handle) : LSHandle(reinterpret_cast<AuUInt>(handle))
|
||||
{}
|
||||
LSSemaphore(HANDLE handle);
|
||||
~LSSemaphore();
|
||||
|
||||
bool AddOne() override;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "Loop.NT.hpp"
|
||||
#include "ILoopSourceEx.hpp"
|
||||
#include "LoopQueue.Linux.hpp"
|
||||
#include <sys/epoll.h>
|
||||
|
||||
namespace Aurora::Loop
|
||||
{
|
||||
@ -36,7 +37,21 @@ namespace Aurora::Loop
|
||||
|
||||
LoopQueue::~LoopQueue()
|
||||
{
|
||||
Deinit();
|
||||
}
|
||||
|
||||
bool LoopQueue::Init()
|
||||
{
|
||||
this->epollFd_ = epoll_create1(-1);
|
||||
if (this->epollFd_ == -1) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LoopQueue::Deinit()
|
||||
{
|
||||
auto handle = AuExchange(this->epollFd_, -1);
|
||||
if (handle != -1) close(handle);
|
||||
}
|
||||
|
||||
bool LoopQueue::SourceAdd(const AuSPtr<ILoopSource> &source)
|
||||
@ -56,32 +71,40 @@ namespace Aurora::Loop
|
||||
|
||||
AuUInt32 LoopQueue::GetSourceCount()
|
||||
{
|
||||
return {};
|
||||
return this->sources_.size();
|
||||
}
|
||||
|
||||
bool LoopQueue::AddCallback(const AuSPtr<ILoopSource> &source, const AuSPtr<ILoopSourceSubscriber> &subscriber)
|
||||
{
|
||||
return {};
|
||||
AU_LOCK_GUARD(this->commitQueueMutex_);
|
||||
bool bAdded {};
|
||||
|
||||
return bAdded;
|
||||
}
|
||||
|
||||
bool LoopQueue::AddCallbackEx(const AuSPtr<ILoopSource> &source, const AuSPtr<ILoopSourceSubscriberEx> &subscriber)
|
||||
{
|
||||
return {};
|
||||
AU_LOCK_GUARD(this->commitQueueMutex_);
|
||||
bool bAdded {};
|
||||
|
||||
|
||||
return bAdded;
|
||||
}
|
||||
|
||||
bool LoopQueue::AddCallback(const AuSPtr<ILoopSourceSubscriber> &subscriber)
|
||||
{
|
||||
return {};
|
||||
AU_LOCK_GUARD(this->globalLockMutex_);
|
||||
return AuTryInsert(this->allSubscribers_, subscriber);
|
||||
}
|
||||
|
||||
void LoopQueue::ChugPathConfigure(AuUInt32 sectionTickTime, AuSInt sectionDequeCount)
|
||||
{
|
||||
|
||||
// Intentionally NO-OP under Linux
|
||||
}
|
||||
|
||||
void LoopQueue::ChugHint(bool value)
|
||||
{
|
||||
|
||||
// Intentionally NO-OP under Linux
|
||||
}
|
||||
|
||||
bool LoopQueue::Commit()
|
||||
@ -108,4 +131,14 @@ namespace Aurora::Loop
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void LoopQueue::DoTick()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AUKN_SYM AuSPtr<ILoopQueue> NewLoopQueue()
|
||||
{
|
||||
return AuMakeShared<LoopQueue>();
|
||||
}
|
||||
}
|
@ -16,6 +16,9 @@ namespace Aurora::Loop
|
||||
LoopQueue();
|
||||
~LoopQueue();
|
||||
|
||||
bool Init();
|
||||
void Deinit();
|
||||
|
||||
bool SourceAdd(const AuSPtr<ILoopSource> &source) override;
|
||||
bool SourceAddWithTimeout(const AuSPtr<ILoopSource> &source, AuUInt32 ms) override;
|
||||
bool SourceRemove(const AuSPtr<ILoopSource> &source) override;
|
||||
@ -37,7 +40,39 @@ namespace Aurora::Loop
|
||||
AuUInt32 WaitAny(AuUInt32 timeout) override;
|
||||
AuList<AuSPtr<ILoopSource>> WaitAnyEx(AuUInt32 timeout) override;
|
||||
|
||||
void DoTick();
|
||||
|
||||
private:
|
||||
|
||||
struct SpecialHandle
|
||||
{
|
||||
int fd;
|
||||
void *priv;
|
||||
};
|
||||
|
||||
struct SourceExtended
|
||||
{
|
||||
SpecialHandle internal;
|
||||
AuSPtr<void> pin;
|
||||
|
||||
AuList<AuSPtr<ILoopSourceSubscriber>> subscribers;
|
||||
AuList<AuSPtr<ILoopSourceSubscriberEx>> subscriberExs;
|
||||
};
|
||||
|
||||
|
||||
AuThreadPrimitives::SpinLock commitQueueMutex_;
|
||||
AuList<AuSPtr<SourceExtended>> commitQueue_;
|
||||
|
||||
|
||||
AuThreadPrimitives::SpinLock globalLockMutex_;
|
||||
AuList<AuSPtr<ILoopSourceSubscriber>> allSubscribers_;
|
||||
|
||||
|
||||
AuThreadPrimitives::RWLockUnique_t sourceMutex_;
|
||||
AuList<AuSPtr<SourceExtended>> sources_;
|
||||
|
||||
int epollFd_ {-1};
|
||||
bool hasActiveBeforeCommit_ {};
|
||||
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user