summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-03-17 06:14:21 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-03-17 06:14:21 +0100
commitdca6593e4c99ac317fc95e569099283bbc609339 (patch)
tree4e68b6c28064c2cdd360b70e8fac5512ad97e0e7
parent2c188c8c35424b33b288af3b6a39df25a26b06f3 (diff)
[FEAT] TBB example for OCL.Fix.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--example/fix_tag_example/example.cpp2
-rw-r--r--example/fix_tag_example_tbb/CMakeLists.txt19
-rw-r--r--example/fix_tag_example_tbb/example.cpp96
-rw-r--r--src/fix/checksum.cpp2
-rw-r--r--src/fix/parser.cpp1
5 files changed, 117 insertions, 3 deletions
diff --git a/example/fix_tag_example/example.cpp b/example/fix_tag_example/example.cpp
index 294291c..71cd60d 100644
--- a/example/fix_tag_example/example.cpp
+++ b/example/fix_tag_example/example.cpp
@@ -46,7 +46,7 @@ int main(int argc, char** argv)
ocl::io::print(":value=", fix["49"], "\n");
ocl::io::print(":checksum=", ocl::fix::try_index_checksum(fix), "\n");
- //ocl::io::print(":checksum=", ocl::fix::operators::checksum(default_fix_unchecked), "\n");
+ // ocl::io::print(":checksum=", ocl::fix::operators::checksum(default_fix_unchecked), "\n");
return 0;
}
diff --git a/example/fix_tag_example_tbb/CMakeLists.txt b/example/fix_tag_example_tbb/CMakeLists.txt
new file mode 100644
index 0000000..b47dd86
--- /dev/null
+++ b/example/fix_tag_example_tbb/CMakeLists.txt
@@ -0,0 +1,19 @@
+# AMLALE: Hm?
+cmake_minimum_required(VERSION 3.15...3.31)
+
+project(
+ FixTBBExample
+ VERSION 1.0
+ LANGUAGES CXX)
+
+find_package(Boost REQUIRED)
+find_package(TBB REQUIRED)
+
+add_executable(FixTBBExample example.cpp)
+
+target_include_directories(FixTBBExample PUBLIC ${BOOST_INCLUDE_DIRS})
+
+set_property(TARGET FixTBBExample PROPERTY CXX_STANDARD 20)
+target_include_directories(FixTBBExample PUBLIC ../../include/ocl)
+target_link_libraries(FixTBBExample PRIVATE TBB::tbb)
+target_link_libraries(FixTBBExample PUBLIC ocl_fix.a)
diff --git a/example/fix_tag_example_tbb/example.cpp b/example/fix_tag_example_tbb/example.cpp
new file mode 100644
index 0000000..bd7ee12
--- /dev/null
+++ b/example/fix_tag_example_tbb/example.cpp
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: BSL-1.0
+// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org)
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+// Official repository: https://github.com/ocl-foss-org/fix
+
+#include <ocl/fix/parser.hpp>
+#include <ocl/fix/checksum.hpp>
+#include <tbb/tbb.h>
+#include <vector>
+#include <mutex>
+
+constexpr char const default_fix[] = {
+ '8', '=', 'F', 'I', 'X', '.', '4', '.', '2', 0x01,
+ '9', '=', '8', '7', 0x01, // BodyLength = 87
+ '3', '5', '=', 'A', 0x01,
+ '4', '9', '=', 'S', 'E', 'R', 'V', 'E', 'R', 0x01,
+ '5', '6', '=', 'C', 'L', 'I', 'E', 'N', 'T', 0x01,
+ '3', '4', '=', '1', '7', '7', 0x01,
+ '5', '2', '=', '2', '0', '0', '9', '0', '1', '0', '7', '-', '1', '8', ':', '1', '5', ':', '1', '6', 0x01,
+ '9', '8', '=', '0', 0x01,
+ '1', '0', '8', '=', '3', '0', 0x01,
+ '1', '0', '=', '6', '0', 0x01, 0x00 // CheckSum = 143
+};
+
+constexpr char default_fix_unchecked[] = {
+ '8', '=', 'F', 'I', 'X', '.', '4', '.', '2', 0x01,
+ '9', '=', '8', '0', 0x01, // BodyLength = 80
+ '3', '5', '=', 'A', 0x01,
+ '4', '9', '=', 'S', 'E', 'R', 'V', 'E', 'R', 0x01,
+ '5', '6', '=', 'C', 'L', 'I', 'E', 'N', 'T', 0x01,
+ '3', '4', '=', '1', '7', '7', 0x01,
+ '5', '2', '=', '2', '0', '0', '9', '0', '1', '0', '7', '-', '1', '8', ':', '1', '5', ':', '1', '6', 0x01,
+ '9', '8', '=', '0', 0x01,
+ '1', '0', '8', '=', '3', '0', 0x01,
+ 0x00};
+
+static std::mutex mutex_main;
+
+int task_main()
+{
+ std::unique_lock<std::mutex> lk{mutex_main};
+
+ ocl::fix::visitor basic_visitor;
+ ocl::fix::range_buffer fix = basic_visitor.visit(default_fix);
+
+ ocl::io::enable_stdio_sync(false);
+
+ ocl::io::print(":key=35\n");
+ ocl::io::print(":value=", fix["35"], "\n");
+
+ ocl::io::print(":key=49\n");
+ ocl::io::print(":value=", fix["49"], "\n");
+
+ ocl::io::print(":checksum=", ocl::fix::try_index_checksum(fix), "\n");
+ // ocl::io::print(":checksum=", ocl::fix::operators::checksum(default_fix_unchecked), "\n");
+
+ return 0;
+}
+
+struct fix_task final
+{
+ fix_task(size_t n)
+ : _n(n)
+ {
+ }
+
+ void operator()()
+ {
+ std::cerr << "[TASK " << _n << "]\n";
+ task_main();
+ }
+
+ size_t _n{};
+};
+
+template <typename T>
+struct invoker
+{
+ void operator()(T& it) const
+ {
+ it();
+ }
+};
+
+int main(int, char**)
+{
+ tbb::task_arena init; // automatic thread retrieval (like in Asio!)
+
+ std::vector<fix_task> tasks;
+ for (int i = 0; i < 1000; ++i)
+ tasks.push_back(fix_task(i));
+
+ tbb::parallel_for_each(tasks.begin(), tasks.end(), invoker<fix_task>());
+ return 0;
+}
diff --git a/src/fix/checksum.cpp b/src/fix/checksum.cpp
index ab91a6d..f2cbe0f 100644
--- a/src/fix/checksum.cpp
+++ b/src/fix/checksum.cpp
@@ -16,7 +16,7 @@ namespace ocl::fix
else
detail::throw_runtime_error();
- detail::unreachable();
+ detail::unreachable();
return {};
}
diff --git a/src/fix/parser.cpp b/src/fix/parser.cpp
index b1cf353..d7ff4f5 100644
--- a/src/fix/parser.cpp
+++ b/src/fix/parser.cpp
@@ -4,7 +4,6 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// Official repository: https://github.com/ocl-foss-org/fix
-
#define OCL_FIX_HAS_IMPL
#include <ocl/fix/parser.hpp>
#include <boost/algorithm/cxx11/is_sorted.hpp>