1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-17 10:52:46 +00:00

More std::atomic and friends

This commit is contained in:
2014-04-08 21:38:46 -07:00
parent 23a071860e
commit 34b2eb1836
15 changed files with 61 additions and 94 deletions

View File

@ -80,7 +80,6 @@ static unsigned s_pageSizeMask;
//===========================================================================
CNtWaitHandle::CNtWaitHandle () {
m_refCount = 1;
m_event = CreateEvent(
(LPSECURITY_ATTRIBUTES) nil,
true, // manual reset
@ -94,17 +93,6 @@ CNtWaitHandle::~CNtWaitHandle () {
CloseHandle(m_event);
}
//===========================================================================
void CNtWaitHandle::IncRef () {
InterlockedIncrement(&m_refCount);
}
//===========================================================================
void CNtWaitHandle::DecRef () {
if (!InterlockedDecrement(&m_refCount))
delete this;
}
//===========================================================================
bool CNtWaitHandle::WaitForObject (unsigned timeMs) const {
return WAIT_TIMEOUT != WaitForSingleObject(m_event, timeMs);
@ -189,7 +177,7 @@ static void INtOpDispatch (
// set event *after* operation is complete
if (signalComplete) {
signalComplete->SignalObject();
signalComplete->DecRef();
signalComplete->UnRef();
}
// if we just deleted the last operation then stop dispatching
@ -203,7 +191,7 @@ static void INtOpDispatch (
if (op->pending)
break;
InterlockedDecrement(&ntObj->ioCount);
--ntObj->ioCount;
}
ntObj->critsect.Leave();
@ -300,7 +288,7 @@ bool INtConnInitialize (NtObject * ntObj) {
//===========================================================================
void INtConnCompleteOperation (NtObject * ntObj) {
// are we completing the last operation for this object?
if (InterlockedDecrement(&ntObj->ioCount))
if (--ntObj->ioCount)
return;
DWORD err = GetLastError();

View File

@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#endif
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNASYNCCOREEXE_PRIVATE_NT_PNACENTINT_H
#include "hsRefCnt.h"
namespace Nt {
@ -87,15 +88,12 @@ public:
BOOL TryEnter () { return TryEnterCriticalSection(&m_handle); }
};
class CNtWaitHandle {
long m_refCount;
class CNtWaitHandle : public hsAtomicRefCnt {
HANDLE m_event;
public:
CNtWaitHandle ();
~CNtWaitHandle ();
void IncRef ();
void DecRef ();
bool WaitForObject (unsigned timeMs) const;
void SignalObject () const;
};
@ -131,7 +129,7 @@ struct NtObject {
LISTDECL(Operation, link) opList;
long nextCompleteSequence;
long nextStartSequence;
long ioCount;
std::atomic<long> ioCount;
bool closed;
NtObject()

View File

@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#pragma hdrstop
#include "pnAceNtInt.h"
#include <mutex>
namespace Nt {
@ -222,7 +223,7 @@ static void SocketStartAsyncRead (NtSock * sock) {
bool readResult;
sock->critsect.Enter();
if (sock->handle != INVALID_HANDLE_VALUE) {
InterlockedIncrement(&sock->ioCount);
++sock->ioCount;
readResult = ReadFile(
sock->handle,
sock->buffer + sock->bytesLeft,
@ -238,7 +239,7 @@ static void SocketStartAsyncRead (NtSock * sock) {
DWORD err = GetLastError();
if (!readResult && (err != ERROR_IO_PENDING))
InterlockedDecrement(&sock->ioCount);
--sock->ioCount;
}
//===========================================================================
@ -378,7 +379,7 @@ static NtOpSocketWrite * SocketQueueAsyncWrite (
op->write.bytesProcessed = bytes;
memcpy(op->write.buffer, data, bytes);
InterlockedIncrement(&sock->ioCount);
++sock->ioCount;
PerfAddCounter(kAsyncPerfSocketBytesWaitQueued, bytes);
return op;
@ -1022,8 +1023,8 @@ void INtSocketOpCompleteSocketRead (
|| ((sock->opRead.read.bytesProcessed + sock->bytesLeft) > sizeof(sock->buffer))
) {
#ifdef HS_DEBUGGING
static long s_once;
if (!AtomicAdd(&s_once, 1)) {
static std::once_flag s_once;
std::call_once(s_once, [sock]() {
DumpInvalidData(
"NtSockErr.log",
sizeof(sock->buffer),
@ -1034,7 +1035,7 @@ void INtSocketOpCompleteSocketRead (
sock->opRead.read.bytes,
sock->opRead.read.bytesProcessed
);
}
});
#endif // ifdef HS_DEBUGGING
LogMsg(
@ -1419,7 +1420,7 @@ bool NtSocketWrite (
op->write.bytesProcessed = bytes;
PerfAddCounter(kAsyncPerfSocketBytesWaitQueued, bytes);
InterlockedIncrement(&sock->ioCount);
++sock->ioCount;
if (op == sock->opList.Head())
result = INtSocketOpCompleteQueuedSocketWrite((NtSock *) sock, op);