Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add concurrency model with uv loops #36

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
407ed54
Add new uv shell
IsabelParedes Feb 5, 2024
d4d8677
Add uvw dependency
IsabelParedes Feb 6, 2024
54569b0
Copy split class
IsabelParedes Feb 6, 2024
0ab63f3
Replace virtual fun
IsabelParedes Feb 7, 2024
554d3cd
Copy control and shell for uv server
IsabelParedes Feb 7, 2024
e90318b
Add make fun for uv server
IsabelParedes Feb 7, 2024
57b7ded
Replace pool with uvw loop
IsabelParedes Feb 7, 2024
4fa82d7
Rebase
IsabelParedes Feb 9, 2024
5cfea17
Add uvw to environment file
IsabelParedes Feb 9, 2024
0a64760
Update header paths
IsabelParedes Feb 9, 2024
869dd69
Update make uv fun
IsabelParedes Feb 9, 2024
170e459
Fix header guards
IsabelParedes Feb 12, 2024
e151649
Register callback
IsabelParedes Feb 12, 2024
ca4266c
Replace poll event
IsabelParedes Feb 12, 2024
c23741c
Add controller poll
IsabelParedes Feb 12, 2024
9e6e776
Use uvw v3.3.0
IsabelParedes Feb 13, 2024
04dad20
Fix uvw linkage
IsabelParedes Feb 13, 2024
9eaf4dd
Test polls
IsabelParedes Feb 13, 2024
635fc65
Polling
IsabelParedes Feb 13, 2024
f6d6637
Fix json error
IsabelParedes Feb 14, 2024
50820b7
Debug kernel status
IsabelParedes Feb 19, 2024
36316da
Get loop pointer
IsabelParedes Feb 21, 2024
a6c27f9
Use loop pointer
IsabelParedes Feb 22, 2024
5f52b7b
Run loop
IsabelParedes Feb 22, 2024
8189cf5
Debug loop run
IsabelParedes Feb 23, 2024
23ce5ba
Save poll resources
IsabelParedes Feb 28, 2024
6110af9
Refactor
IsabelParedes Feb 29, 2024
978e322
Unoverload uv server maker
IsabelParedes Mar 8, 2024
3e7a100
Add hook base
IsabelParedes Mar 11, 2024
f05a547
Clean up
IsabelParedes Mar 12, 2024
8635ee7
Add default uvw loop
IsabelParedes Mar 13, 2024
d80b25d
Clean
IsabelParedes Mar 13, 2024
1e5f240
Update xhook_base
IsabelParedes Apr 12, 2024
94e57ad
Implement entity semantics
IsabelParedes Apr 15, 2024
145e645
Fix shell classes
IsabelParedes Apr 15, 2024
627f493
Fix alignment
IsabelParedes Apr 15, 2024
2b60712
Fix rebase conflict
IsabelParedes Apr 15, 2024
791f6ae
Restore tests
IsabelParedes Apr 15, 2024
3038b6f
Make shell destructors virtual
IsabelParedes Apr 15, 2024
a09874a
Add delegating constructor
IsabelParedes Apr 15, 2024
170ceb6
Fix alignment
IsabelParedes Apr 15, 2024
6585dc2
Clean up uvw preprocessor directives
IsabelParedes Apr 15, 2024
0b2021f
Add comment to create uv xserver
IsabelParedes Apr 16, 2024
467a479
Stop loop
IsabelParedes Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ endif()

message(STATUS "XEUS_ZMQ_BUILD_SHARED_LIBS: ${XEUS_ZMQ_BUILD_SHARED_LIBS}")
message(STATUS "XEUS_ZMQ_BUILD_STATIC_LIBS: ${XEUS_ZMQ_BUILD_STATIC_LIBS}")
message(STATUS "XEUS_ZMQ_STATIC_DEPENDENCIES: ${XEUS_ZMQ_STATIC_DEPENDENCIES}")
message(STATUS "XEUS_ZMQ_BUILD_TESTS: ${XEUS_ZMQ_BUILD_TESTS}")
message(STATUS "XEUS_ZMQ_STATIC_DEPENDENCIES: ${XEUS_ZMQ_STATIC_DEPENDENCIES}")
message(STATUS "XEUS_ZMQ_BUILD_TESTS: ${XEUS_ZMQ_BUILD_TESTS}")

# Dependencies
# ============
Expand Down Expand Up @@ -122,6 +122,9 @@ endif ()

find_package(OpenSSL REQUIRED)

find_library(UVW_LIBRARY uvw)
find_path(UVW_INCLUDE_DIR uvw.hpp)

# Source files
# ============

Expand All @@ -134,6 +137,7 @@ set(XEUS_ZMQ_HEADERS
${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xserver_zmq.hpp
${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xthread.hpp
${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xzmq_context.hpp
${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xhook_base.hpp
)

set(XEUS_ZMQ_SOURCES
Expand Down Expand Up @@ -175,15 +179,20 @@ set(XEUS_ZMQ_SOURCES
${XEUS_ZMQ_SOURCE_DIR}/xserver_zmq_split.cpp
${XEUS_ZMQ_SOURCE_DIR}/xserver_zmq_split.hpp
${XEUS_ZMQ_SOURCE_DIR}/xserver_zmq.cpp
${XEUS_ZMQ_SOURCE_DIR}/xshell.hpp
${XEUS_ZMQ_SOURCE_DIR}/xshell.cpp
${XEUS_ZMQ_SOURCE_DIR}/xshell_base.hpp
${XEUS_ZMQ_SOURCE_DIR}/xshell_base.cpp
${XEUS_ZMQ_SOURCE_DIR}/xshell_default.hpp
${XEUS_ZMQ_SOURCE_DIR}/xshell_default.cpp
${XEUS_ZMQ_SOURCE_DIR}/xshell_uv.hpp
${XEUS_ZMQ_SOURCE_DIR}/xshell_uv.cpp
${XEUS_ZMQ_SOURCE_DIR}/xtrivial_messenger.hpp
${XEUS_ZMQ_SOURCE_DIR}/xtrivial_messenger.cpp
${XEUS_ZMQ_SOURCE_DIR}/xzmq_context.cpp
${XEUS_ZMQ_SOURCE_DIR}/xzmq_messenger.hpp
${XEUS_ZMQ_SOURCE_DIR}/xzmq_messenger.cpp
${XEUS_ZMQ_SOURCE_DIR}/xzmq_serializer.cpp
${XEUS_ZMQ_SOURCE_DIR}/xzmq_serializer.hpp
${XEUS_ZMQ_SOURCE_DIR}/xhook_base.cpp
)

# Targets and link
Expand Down Expand Up @@ -226,6 +235,7 @@ macro(xeus_zmq_create_target target_name linkage output_name)
PUBLIC ${XEUS_TARGET_NAME}
PRIVATE ${CPPZMQ_TARGET_NAME}
PRIVATE OpenSSL::Crypto
PUBLIC ${UVW_LIBRARY}
)

if (NOT MSVC)
Expand Down Expand Up @@ -274,6 +284,7 @@ macro(xeus_zmq_create_target target_name linkage output_name)
# =================

target_compile_features(${target_name} PRIVATE cxx_std_17)
target_compile_definitions(${target_name} PUBLIC UVW_AS_LIB)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
Expand Down
3 changes: 2 additions & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ dependencies:
- cppzmq
- xtl=0.7
- xeus>=4.0.3,<5.0
- OpenSSL=1
- OpenSSL=1
- libopenssl-static=1
- nlohmann_json=3.11.3
- libuvw
# Test dependencies
- doctest >= 2.4.6
- pytest
Expand Down
48 changes: 48 additions & 0 deletions include/xeus-zmq/xhook_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/***************************************************************************
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay, Martin Renou *
* Copyright (c) 2016, QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#ifndef XHOOK_BASE_HPP
#define XHOOK_BASE_HPP

#include "xeus-zmq.hpp"

#include <uvw.hpp>

namespace xeus
{
class XEUS_ZMQ_API xhook_base
{
public:

virtual ~xhook_base() = default;
IsabelParedes marked this conversation as resolved.
Show resolved Hide resolved

xhook_base(const xhook_base&) = delete;
xhook_base& operator=(const xhook_base&) = delete;

xhook_base(xhook_base&&) = delete;
xhook_base& operator=(xhook_base&&) = delete;

void pre_hook();
void post_hook();
void run(std::shared_ptr<uvw::loop> loop);

protected:

xhook_base() = default;

private:

virtual void pre_hook_impl() = 0;
virtual void post_hook_impl() = 0;
virtual void run_impl(std::shared_ptr<uvw::loop> loop);

};
}

#endif
14 changes: 14 additions & 0 deletions include/xeus-zmq/xserver_zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
#ifndef XEUS_SERVER_ZMQ_HPP
#define XEUS_SERVER_ZMQ_HPP

#include <uvw.hpp>
IsabelParedes marked this conversation as resolved.
Show resolved Hide resolved

#include <memory>

#include "xeus/xeus_context.hpp"
#include "xeus/xkernel_configuration.hpp"
#include "xeus/xserver.hpp"

#include "xeus-zmq.hpp"
#include "xhook_base.hpp"

namespace xeus
{
Expand Down Expand Up @@ -63,6 +68,15 @@ namespace xeus
std::unique_ptr<xserver> make_xserver_shell_main(xcontext& context,
const xconfiguration& config,
nl::json::error_handler_t eh = nl::json::error_handler_t::strict);

XEUS_ZMQ_API
std::unique_ptr<xserver> make_xserver_uv_shell_main(
IsabelParedes marked this conversation as resolved.
Show resolved Hide resolved
xcontext& context,
const xconfiguration& config,
nl::json::error_handler_t eh = nl::json::error_handler_t::strict,
std::shared_ptr<uvw::loop> loop_ptr = nullptr,
std::unique_ptr<xhook_base> hook = nullptr);

}

#endif
35 changes: 35 additions & 0 deletions src/xhook_base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/***************************************************************************
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay, Martin Renou *
* Copyright (c) 2016, QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include "xeus-zmq/xhook_base.hpp"

#include <uvw.hpp>

namespace xeus
{
void xhook_base::pre_hook()
{
pre_hook_impl();
}

void xhook_base::post_hook()
{
post_hook_impl();
}

void xhook_base::run(std::shared_ptr<uvw::loop> loop)
{
run_impl(loop);
}

void xhook_base::run_impl(std::shared_ptr<uvw::loop> loop)
{
loop->run();
}
}
13 changes: 12 additions & 1 deletion src/xserver_shell_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include <chrono>
#include <iostream>

#include <uvw.hpp>

#include "zmq_addon.hpp"
#include "xeus/xguid.hpp"
#include "xeus-zmq/xmiddleware.hpp"
#include "xserver_shell_main.hpp"
#include "xshell.hpp"
#include "xshell_base.hpp"

namespace xeus
{
Expand All @@ -27,6 +29,15 @@ namespace xeus
{
}

xserver_shell_main::xserver_shell_main(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh,
std::shared_ptr<uvw::loop> loop_ptr,
std::unique_ptr<xhook_base> hook)
: xserver_zmq_split(context, config, eh, loop_ptr, std::move(hook))
{
}

xserver_shell_main::~xserver_shell_main()
{
}
Expand Down
11 changes: 11 additions & 0 deletions src/xserver_shell_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
#ifndef XEUS_SERVER_SHELL_MAIN_HPP
#define XEUS_SERVER_SHELL_MAIN_HPP

#include <uvw.hpp>

#include "xeus/xeus_context.hpp"
#include "xeus/xkernel_configuration.hpp"

#include "xeus-zmq/xeus-zmq.hpp"
#include "xserver_zmq_split.hpp"
#include "xeus-zmq/xhook_base.hpp"

namespace xeus
{
Expand All @@ -25,6 +28,14 @@ namespace xeus
xserver_shell_main(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t he);


xserver_shell_main(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t he,
std::shared_ptr<uvw::loop> loop_ptr,
std::unique_ptr<xhook_base> hook);

virtual ~xserver_shell_main();

private:
Expand Down
24 changes: 21 additions & 3 deletions src/xserver_zmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include <memory>

#include <uvw.hpp>

#include "xeus-zmq/xserver_zmq.hpp"
#include "xserver_zmq_impl.hpp"
#include "xserver_zmq_default.hpp"
Expand Down Expand Up @@ -46,7 +50,7 @@ namespace xeus
{
return xserver::notify_internal_listener(std::move(msg));
}

xcontrol_messenger& xserver_zmq::get_control_messenger_impl()
{
return p_impl->get_control_messenger();
Expand Down Expand Up @@ -93,8 +97,8 @@ namespace xeus
}

std::unique_ptr<xserver> make_xserver_default(xcontext& context,
const xconfiguration& config,
nl::json::error_handler_t eh)
const xconfiguration& config,
nl::json::error_handler_t eh)
{
auto impl = std::make_unique<xserver_zmq_default>(context.get_wrapped_context<zmq::context_t>(), config, eh);
return std::make_unique<xserver_zmq>(std::move(impl));
Expand All @@ -115,4 +119,18 @@ namespace xeus
auto impl = std::make_unique<xserver_shell_main>(context.get_wrapped_context<zmq::context_t>(), config, eh);
return std::make_unique<xserver_zmq>(std::move(impl));
}

// Since xkernel only accepts three arguments, it is recommended to create a lambda function which
// captures a loop pointer and a hook object pointer. For example:
// auto make_xserver = [&loop_ptr, &hook_ptr](context, config, eh){ return make_xserver_uv_shell_main(...); }
std::unique_ptr<xserver> make_xserver_uv_shell_main(xcontext& context,
const xconfiguration& config,
nl::json::error_handler_t eh,
std::shared_ptr<uvw::loop> loop_ptr,
std::unique_ptr<xhook_base> hook)
{
auto impl = std::make_unique<xserver_shell_main>(
context.get_wrapped_context<zmq::context_t>(), config, eh, loop_ptr, std::move(hook));
return std::make_unique<xserver_zmq>(std::move(impl));
}
}
Loading