Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
DONE:
- Fix std::string constructor call in rmw_subscription_data.cpp
- Move serialization buffer pool to the context

TODO:
- Remove printf calls
- Remove sanitizer usage
- Fix formatting
- Resolve FIXMEs in BufferPool impl
  • Loading branch information
zenoh committed Nov 22, 2024
1 parent d9e53a9 commit 284bcc4
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 371 deletions.
4 changes: 3 additions & 1 deletion rmw_zenoh_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ if(NOT CMAKE_CXX_STANDARD)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
add_compile_options(-Wall -Wextra -Wpedantic -g -fsanitize=address)
link_libraries("-fsanitize=address")
link_libraries("-lasan")
endif()

# find dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef DETAIL__SERIALIZATION_BUFFER_POOL_HPP_
#define DETAIL__SERIALIZATION_BUFFER_POOL_HPP_
#ifndef DETAIL__BUFFER_POOL_HPP_
#define DETAIL__BUFFER_POOL_HPP_

#include <mutex>
#include <cassert>
#include <vector>

#include "rcutils/allocator.h"

class SerializationBufferPool
class BufferPool
{
public:
SerializationBufferPool() = default;
BufferPool() = default;

uint8_t * allocate(rcutils_allocator_t * allocator, size_t size)
{
// FIXME(fuzzypixelz): indeed, this methods leaks all allocated buffers ;)
std::lock_guard<std::mutex> guard(mutex_);

if (available_buffers_.empty()) {
Expand All @@ -47,7 +48,6 @@ class SerializationBufferPool
assert(buffer.data); // FIXME(fuzzypixelz): handle error
buffer.size = size;
}

return buffer.data;
}
}
Expand All @@ -56,6 +56,7 @@ class SerializationBufferPool
deallocate(uint8_t * data)
{
std::lock_guard<std::mutex> guard(mutex_);

for (size_t i = 0; i < buffers_.size(); i++) {
if (buffers_.at(i).data == data) {
available_buffers_.push_back(i);
Expand All @@ -77,4 +78,4 @@ class SerializationBufferPool
std::mutex mutex_;
};

#endif // DETAIL__SERIALIZATION_BUFFER_POOL_HPP_
#endif // DETAIL__BUFFER_POOL_HPP_
4 changes: 4 additions & 0 deletions rmw_zenoh_cpp/src/detail/rmw_context_impl_s.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "graph_cache.hpp"
#include "rmw_node_data.hpp"
#include "buffer_pool.hpp"

#include "rmw/ret_types.h"
#include "rmw/types.h"
Expand Down Expand Up @@ -92,6 +93,9 @@ class rmw_context_impl_s final
// Forward declaration
class Data;

// Pool of serialization buffers.
BufferPool serialization_buffer_pool;

private:
std::shared_ptr<Data> data_{nullptr};
};
Expand Down
Loading

0 comments on commit 284bcc4

Please sign in to comment.