aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-04-27 14:35:38 +0200
committerGitHub <[email protected]>2023-04-27 14:35:38 +0200
commit88b977d78617c31f61f2a51e96b35ceeb7e9db72 (patch)
tree23a34aea9319a9f4dd41fbc39a51a783aeba7f0f
parentbugfixes (#261) (diff)
downloadzen-88b977d78617c31f61f2a51e96b35ceeb7e9db72.tar.xz
zen-88b977d78617c31f61f2a51e96b35ceeb7e9db72.zip
made Ref<> constructor explicit (#262)
This change makes the Ref<> constructor explicit, which can help avoid unnecessary overheads and other accidents
-rw-r--r--zencore/include/zencore/refcount.h2
-rw-r--r--zencore/workthreadpool.cpp4
-rw-r--r--zenhttp/httpserver.cpp9
-rw-r--r--zenserver/projectstore/projectstore.cpp2
-rw-r--r--zenserver/testing/httptest.cpp6
-rw-r--r--zenstore/blockstore.cpp8
6 files changed, 16 insertions, 15 deletions
diff --git a/zencore/include/zencore/refcount.h b/zencore/include/zencore/refcount.h
index 32c282600..f0bb6b85e 100644
--- a/zencore/include/zencore/refcount.h
+++ b/zencore/include/zencore/refcount.h
@@ -131,7 +131,7 @@ class Ref
public:
inline Ref() = default;
inline Ref(const Ref& Rhs) : m_Ref(Rhs.m_Ref) { m_Ref && m_Ref->AddRef(); }
- inline Ref(T* Ptr) : m_Ref(Ptr) { m_Ref && m_Ref->AddRef(); }
+ inline explicit Ref(T* Ptr) : m_Ref(Ptr) { m_Ref && m_Ref->AddRef(); }
inline ~Ref() { m_Ref && m_Ref->Release(); }
template<typename DerivedType>
diff --git a/zencore/workthreadpool.cpp b/zencore/workthreadpool.cpp
index 4291d1581..b4328cdbd 100644
--- a/zencore/workthreadpool.cpp
+++ b/zencore/workthreadpool.cpp
@@ -45,7 +45,7 @@ WorkerThreadPool::ScheduleWork(Ref<IWork> Work)
void
WorkerThreadPool::ScheduleWork(std::function<void()>&& Work)
{
- m_WorkQueue.Enqueue(new detail::LambdaWork(Work));
+ m_WorkQueue.Enqueue(Ref<IWork>(new detail::LambdaWork(Work)));
}
[[nodiscard]] size_t
@@ -80,4 +80,4 @@ WorkerThreadPool::WorkerThreadFunction()
} while (true);
}
-} // namespace zen \ No newline at end of file
+} // namespace zen
diff --git a/zenhttp/httpserver.cpp b/zenhttp/httpserver.cpp
index 3576d9b3d..671cbd319 100644
--- a/zenhttp/httpserver.cpp
+++ b/zenhttp/httpserver.cpp
@@ -4,6 +4,7 @@
#include "httpasio.h"
#include "httpnull.h"
+#include "httpsys.h"
#include <zencore/compactbinary.h>
#include <zencore/compactbinarybuilder.h>
@@ -418,7 +419,7 @@ HttpService::HandlePackageRequest(HttpServerRequest& HttpServiceRequest)
{
ZEN_UNUSED(HttpServiceRequest);
- return nullptr;
+ return Ref<IHttpPackageHandler>();
}
//////////////////////////////////////////////////////////////////////////
@@ -738,17 +739,17 @@ CreateHttpServer(std::string_view ServerClass)
default:
case HttpServerClass::kHttpAsio:
ZEN_INFO("using asio HTTP server implementation");
- return new HttpAsioServer();
+ return Ref<HttpServer>(new HttpAsioServer());
#if ZEN_WITH_HTTPSYS
case HttpServerClass::kHttpSys:
ZEN_INFO("using http.sys server implementation");
- return CreateHttpSysServer(std::thread::hardware_concurrency(), /* background worker threads */ 16);
+ return Ref<HttpServer>(new HttpSysServer(std::thread::hardware_concurrency(), /* background worker threads */ 16));
#endif
case HttpServerClass::kHttpNull:
ZEN_INFO("using null HTTP server implementation");
- return new HttpNullServer;
+ return Ref<HttpServer>(new HttpNullServer);
}
}
diff --git a/zenserver/projectstore/projectstore.cpp b/zenserver/projectstore/projectstore.cpp
index db5cae503..847a79a1d 100644
--- a/zenserver/projectstore/projectstore.cpp
+++ b/zenserver/projectstore/projectstore.cpp
@@ -1811,7 +1811,7 @@ ProjectStore::OpenProject(std::string_view ProjectId)
}
}
- return nullptr;
+ return {};
}
Ref<ProjectStore::Project>
diff --git a/zenserver/testing/httptest.cpp b/zenserver/testing/httptest.cpp
index 10b69c469..349a95ab3 100644
--- a/zenserver/testing/httptest.cpp
+++ b/zenserver/testing/httptest.cpp
@@ -128,14 +128,14 @@ HttpTestingService::HandlePackageRequest(HttpServerRequest& HttpServiceRequest)
m_HandlerMap.erase(It);
- return Handler.Get();
+ return Handler;
}
- auto InsertResult = m_HandlerMap.insert({RequestId, nullptr});
+ auto InsertResult = m_HandlerMap.insert({RequestId, Ref<PackageHandler>()});
_.ReleaseNow();
- return (InsertResult.first->second = new PackageHandler(*this, RequestId)).Get();
+ return (InsertResult.first->second = Ref<PackageHandler>(new PackageHandler(*this, RequestId)));
}
void
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp
index 9738df729..5dfa10c91 100644
--- a/zenstore/blockstore.cpp
+++ b/zenstore/blockstore.cpp
@@ -177,7 +177,7 @@ BlockStore::Initialize(const std::filesystem::path& BlocksBasePath,
}
continue;
}
- Ref<BlockStoreFile> BlockFile = new BlockStoreFile(Path);
+ Ref<BlockStoreFile> BlockFile{new BlockStoreFile(Path)};
BlockFile->Open();
m_TotalSize.fetch_add(BlockFile->FileSize(), std::memory_order::relaxed);
m_ChunkBlocks[BlockIndex] = BlockFile;
@@ -215,7 +215,7 @@ BlockStore::WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment, cons
RwLock::ExclusiveLockScope InsertLock(m_InsertLock);
uint32_t WriteBlockIndex = m_WriteBlockIndex.load(std::memory_order_acquire);
- bool IsWriting = m_WriteBlock != nullptr;
+ bool IsWriting = !!m_WriteBlock;
if (!IsWriting || (m_CurrentInsertOffset + Size) > m_MaxBlockSize)
{
if (m_WriteBlock)
@@ -236,7 +236,7 @@ BlockStore::WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment, cons
std::filesystem::path BlockPath = GetBlockPath(m_BlocksBasePath, WriteBlockIndex);
- Ref<BlockStoreFile> NewBlockFile = new BlockStoreFile(BlockPath);
+ Ref<BlockStoreFile> NewBlockFile(new BlockStoreFile(BlockPath));
NewBlockFile->Create(m_MaxBlockSize);
m_ChunkBlocks[WriteBlockIndex] = NewBlockFile;
@@ -486,7 +486,7 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
ReadBlockTimeUs += ElapsedUs;
ReadBlockLongestTimeUs = std::max(ElapsedUs, ReadBlockLongestTimeUs);
});
- if (OldBlockFile != nullptr)
+ if (OldBlockFile)
{
m_ChunkBlocks[BlockIndex] = nullptr;
ZEN_DEBUG("marking cas block store file '{}' for delete, block #{}", OldBlockFile->GetPath(), BlockIndex);