Skip to content

Instantly share code, notes, and snippets.

@eao197
eao197 / example.cpp
Created January 12, 2019 12:39
More or less valid C++ syntax for aensidhe example
// Source: https://aensidhe.ru/blog/readonlyspan-readonlysequence-c++
template<class TElement>
class Parser {
private:
const IMsgPackParser<TElement> elementParser_;
template<template<class> Container>
void Read(const Container<byte> & source, Span<TElement> & array, size_t & readSize) {
for(size_t i = 0u; i != array.Length(); ++i) {
size_t temp;
@eao197
eao197 / dining_philosophers_simple_csp_based.cpp
Created January 24, 2019 15:57
The first working version of very simple (and not fair) implementation of Dining Philosopher problem with threads and CSP-like channels
#include <dining_philosophers/common/fork_messages.hpp>
#include <dining_philosophers/common/random_generator.hpp>
#include <dining_philosophers/csp_based/trace_maker/all.hpp>
#include <fmt/format.h>
void fork_process(
so_5::mchain_t fork_ch )
{
@eao197
eao197 / dining_philosophers_dijkstra_csp_based.cpp
Created January 25, 2019 07:12
Simple implementation of Dijkstra solution for Dining Philosophers problem. This implementation is built on top of std::threads and CSP-like channels from SObjectizer-5.5
#include <dining_philosophers/common/fork_messages.hpp>
#include <dining_philosophers/common/random_generator.hpp>
#include <dining_philosophers/csp_based/trace_maker/all.hpp>
#include <fmt/format.h>
#include <queue>
void fork_process(
@eao197
eao197 / example.cpp
Created April 11, 2019 17:30
CTRP and C++ template magic for compile-time control
#include <iostream>
enum class msg_count_status_t
{
undefined,
defined
};
struct basic_data_t
{
@eao197
eao197 / adv_example.cpp
Created April 12, 2019 06:07
CTRP and C++ template magic for compile-time control (more advanced version)
#include <iostream>
enum class msg_count_status_t
{
undefined,
defined
};
struct basic_data_t
{
@eao197
eao197 / so5extra-asio_thread_pool.hpp
Created April 17, 2019 12:21
The source code of so5extra's implementation of Asio's based thread_pool dispatcher for SObjectizer-5.6
/*!
* \file
* \brief Implementation of Asio's Thread Pool dispatcher.
*
* \since
* v.1.0.2
*/
#pragma once
@eao197
eao197 / message_holder-simplified.cpp
Created April 23, 2019 06:13
Полный код для статьи о деталях реализации message_holder_t из SObjectizer-5.6
template< typename Payload, typename Envelope >
class basic_message_holder_impl_t
{
protected :
intrusive_ptr_t< Envelope > m_msg;
public :
using payload_type = Payload;
using envelope_type = Envelope;
@eao197
eao197 / restinio_github_issue_22_2.cpp
Created May 11, 2019 12:59
An example of chunk_encoding response with RESTinio and SO-5.5
#include <restinio/all.hpp>
#include <so_5/all.hpp>
#include <random>
// Message for transfer requests from RESTinio's thread to processing thread.
struct handle_request
{
restinio::request_handle_t m_req;
@eao197
eao197 / restinio_handle_post_body_x_www_form_urlencoded.cpp
Created April 10, 2020 08:49
An example of handling POST body with x-www-form-urlencoded content type in RESTinio 0.6.5
#include <restinio/all.hpp>
#include <restinio/helpers/http_field_parsers/content-type.hpp>
#include <fmt/format.h>
using router_t = restinio::router::express_router_t<>;
auto handle_post_body(
const restinio::request_handle_t & req )
#include <chrono>
#include <condition_variable>
#include <iostream>
#include <mutex>
#include <thread>
using namespace std::chrono;
struct lock_context
{