Skip to content

ingangi/chroutine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Chroutine

image image image

With Chroutine, you can easily develop highly concurrent programs in C++ and write code with synchronization semantics.

Usage

Create a chroutine is very simple:

ENGIN.create_chroutine([](void *){
    while (1) {
        SPDLOG(INFO, "hello Chroutine 1, looping");
        SLEEP(1000);
    }
}, nullptr);

ENGIN.create_chroutine([](void *){
    SPDLOG(INFO, "hello Chroutine 2");
    SLEEP(1000);
    SPDLOG(INFO, "hello Chroutine 2, exit now");
}, nullptr);

You can also run the examples and see the code to learn more:

β”œβ”€β”€ channel_example
β”‚Β Β  β”œβ”€β”€ CMakeLists.txt
β”‚Β Β  └── test_channel.cpp
β”œβ”€β”€ chutex_example
β”‚Β Β  β”œβ”€β”€ CMakeLists.txt
β”‚Β Β  └── test_chutex.cpp
β”œβ”€β”€ CMakeLists.txt
β”œβ”€β”€ http_client_example
β”‚Β Β  β”œβ”€β”€ CMakeLists.txt
β”‚Β Β  └── test_main.cpp
β”œβ”€β”€ raw_tcp_client_example
β”‚Β Β  β”œβ”€β”€ CMakeLists.txt
β”‚Β Β  └── raw_tcp_client_example.cpp
β”œβ”€β”€ rpc_example
β”‚Β Β  β”œβ”€β”€ CMakeLists.txt
β”‚Β Β  β”œβ”€β”€ test_client
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ CMakeLists.txt
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ test_client.cpp
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ test_client.hpp
β”‚Β Β  β”‚Β Β  └── test_client_main.cpp
β”‚Β Β  β”œβ”€β”€ test_server.cpp
β”‚Β Β  β”œβ”€β”€ test_server.hpp
β”‚Β Β  └── test_server_main.cpp
β”œβ”€β”€ sched_test
β”‚Β Β  β”œβ”€β”€ CMakeLists.txt
β”‚Β Β  └── test_sched.cpp
β”œβ”€β”€ stack_test
β”‚Β Β  β”œβ”€β”€ CMakeLists.txt
β”‚Β Β  └── test_stack.cpp
β”œβ”€β”€ tcp_echo_server_example
β”‚Β Β  β”œβ”€β”€ CMakeLists.txt
β”‚Β Β  └── test_echo_server.cpp
β”œβ”€β”€ test_chroutine.cpp
└── timer_example
    β”œβ”€β”€ CMakeLists.txt
    └── test_timer.cpp

$ cd examples/build
$ ./configure.sh
$ cd build
$ make

Install

my platform

  • CentOS Linux release 7.4.1708, x86_64
  • gcc (GCC) 4.8.5 20150623

install grpc (if you need the RPC module)

my system: CentOS Linux release 7.4.1708

get ready

sudo yum install autoconf automake autogen libtool shtool build-essential pkg-config libgflags-dev libgtest-dev clang libc++-dev

build and install

git clone https://github.com/grpc/grpc
cd grpc
git submodule update --init
make
[sudo] make install

error and solution

if get configure error:

configure in doc/example fails with "cannot find install-sh, install.sh, or shtool in "." "./.." "./../..""

try:

cd third_party/protobuf
autoreconf -i -v -f

git submodule update --init will download third party code, try to download yourself and put them in right place if failed in China:

Submodule 'third_party/abseil-cpp' (https://github.com/abseil/abseil-cpp) registered for path 'third_party/abseil-cpp'
Submodule 'third_party/benchmark' (https://github.com/google/benchmark) registered for path 'third_party/benchmark'
Submodule 'third_party/bloaty' (https://github.com/google/bloaty.git) registered for path 'third_party/bloaty'
Submodule 'third_party/boringssl' (https://github.com/google/boringssl.git) registered for path 'third_party/boringssl'
Submodule 'third_party/boringssl-with-bazel' (https://boringssl.googlesource.com/boringssl) registered for path 'third_party/boringssl-with-bazel'
Submodule 'third_party/cares/cares' (https://github.com/c-ares/c-ares.git) registered for path 'third_party/cares/cares'
Submodule 'third_party/gflags' (https://github.com/gflags/gflags.git) registered for path 'third_party/gflags'
Submodule 'third_party/googletest' (https://github.com/google/googletest.git) registered for path 'third_party/googletest'
Submodule 'third_party/protobuf' (https://github.com/google/protobuf.git) registered for path 'third_party/protobuf'
Submodule 'third_party/zlib' (https://github.com/madler/zlib) registered for path 'third_party/zlib'

install protoc

it was build but not installed:

cd third_party/protobuf
sudo make install

try to generate protobuf code

cd proto_def
sh gen.sh test.proto

You should see four files:

β”œβ”€β”€ proto_code
β”‚Β Β  β”œβ”€β”€ test.grpc.pb.cc
β”‚Β Β  β”œβ”€β”€ test.grpc.pb.h
β”‚Β Β  β”œβ”€β”€ test.pb.cc
β”‚Β Β  └── test.pb.h

install libcurl (if you need the http client module)

curl.git

About

C++ coroutine framework

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published