Skip to content

Commit

Permalink
Remove from SimpleBufferPool
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Jan 2, 2025
1 parent de72484 commit 698f0f0
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions simulation/halsim_ds_socket/src/main/native/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ struct DataStore {
};
} // namespace

static SimpleBufferPool<4>& GetBufferPool() {
static SimpleBufferPool<4> bufferPool;
static SimpleBufferPool& GetBufferPool() {
static SimpleBufferPool bufferPool;
return bufferPool;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HALSimWSClientConnection
bool m_ws_connected = false;
wpi::WebSocket* m_websocket = nullptr;

wpi::uv::SimpleBufferPool<4> m_buffers;
wpi::uv::SimpleBufferPool m_buffers;
std::mutex m_buffers_mutex;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HALSimHttpConnection
bool m_isWsConnected = false;

// these are only valid if the websocket is connected
wpi::uv::SimpleBufferPool<4> m_buffers;
wpi::uv::SimpleBufferPool m_buffers;
std::mutex m_buffers_mutex;
};

Expand Down
4 changes: 2 additions & 2 deletions simulation/halsim_xrp/src/main/native/cpp/HALSimXRP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ void HALSimXRP::OnSimValueChanged(const wpi::json& simData) {
}
}

uv::SimpleBufferPool<4>& HALSimXRP::GetBufferPool() {
static uv::SimpleBufferPool<4> bufferPool(128);
uv::SimpleBufferPool& HALSimXRP::GetBufferPool() {
static uv::SimpleBufferPool bufferPool(128);
return bufferPool;
}

Expand Down
2 changes: 1 addition & 1 deletion simulation/halsim_xrp/src/main/native/include/HALSimXRP.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class HALSimXRP : public wpilibws::HALSimBaseWebSocketConnection,
int m_port;

void SendStateToXRP();
wpi::uv::SimpleBufferPool<4>& GetBufferPool();
wpi::uv::SimpleBufferPool& GetBufferPool();
std::mutex m_buffer_mutex;

struct sockaddr_in m_dest;
Expand Down
7 changes: 2 additions & 5 deletions wpinet/src/main/native/include/wpinet/uv/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
#include <uv.h>

#include <cstring>
#include <initializer_list>
#include <span>
#include <string_view>
#include <utility>

#include <wpi/SmallVector.h>
#include <vector>

namespace wpi::uv {

Expand Down Expand Up @@ -108,7 +106,6 @@ class Buffer : public uv_buf_t {
* to the heap.
* @tparam DEPTH depth of pool
*/
template <size_t DEPTH = 4>
class SimpleBufferPool {
public:
/**
Expand Down Expand Up @@ -167,7 +164,7 @@ class SimpleBufferPool {
size_t Remaining() const { return m_pool.size(); }

private:
SmallVector<Buffer, DEPTH> m_pool;
std::vector<Buffer> m_pool;
size_t m_size; // NOLINT
};

Expand Down
8 changes: 4 additions & 4 deletions wpinet/src/test/native/cpp/uv/UvBufferTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
namespace wpi::uv {

TEST(UvSimpleBufferPoolTest, ConstructDefault) {
SimpleBufferPool<> pool;
SimpleBufferPool pool;
auto buf1 = pool.Allocate();
ASSERT_EQ(buf1.len, 4096u); // NOLINT
pool.Release({&buf1, 1});
}

TEST(UvSimpleBufferPoolTest, ConstructSize) {
SimpleBufferPool<4> pool{8192};
SimpleBufferPool pool{8192};
auto buf1 = pool.Allocate();
ASSERT_EQ(buf1.len, 8192u); // NOLINT
pool.Release({&buf1, 1});
}

TEST(UvSimpleBufferPoolTest, ReleaseReuse) {
SimpleBufferPool<4> pool;
SimpleBufferPool pool;
auto buf1 = pool.Allocate();
auto buf1copy = buf1;
auto origSize = buf1.len;
Expand All @@ -37,7 +37,7 @@ TEST(UvSimpleBufferPoolTest, ReleaseReuse) {
}

TEST(UvSimpleBufferPoolTest, ClearRemaining) {
SimpleBufferPool<4> pool;
SimpleBufferPool pool;
auto buf1 = pool.Allocate();
pool.Release({&buf1, 1});
ASSERT_EQ(pool.Remaining(), 1u);
Expand Down

0 comments on commit 698f0f0

Please sign in to comment.