项目作者: ingangi

项目描述 :
C++ coroutine framework
高级语言: C++
项目地址: git://github.com/ingangi/chroutine.git
创建时间: 2018-11-28T09:48:22Z
项目社区:https://github.com/ingangi/chroutine

开源协议:MIT License

下载


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:

  1. ENGIN.create_chroutine([](void *){
  2. while (1) {
  3. SPDLOG(INFO, "hello Chroutine 1, looping");
  4. SLEEP(1000);
  5. }
  6. }, nullptr);
  7. ENGIN.create_chroutine([](void *){
  8. SPDLOG(INFO, "hello Chroutine 2");
  9. SLEEP(1000);
  10. SPDLOG(INFO, "hello Chroutine 2, exit now");
  11. }, nullptr);

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

  1. ├── channel_example
  2. ├── CMakeLists.txt
  3. └── test_channel.cpp
  4. ├── chutex_example
  5. ├── CMakeLists.txt
  6. └── test_chutex.cpp
  7. ├── CMakeLists.txt
  8. ├── http_client_example
  9. ├── CMakeLists.txt
  10. └── test_main.cpp
  11. ├── raw_tcp_client_example
  12. ├── CMakeLists.txt
  13. └── raw_tcp_client_example.cpp
  14. ├── rpc_example
  15. ├── CMakeLists.txt
  16. ├── test_client
  17. ├── CMakeLists.txt
  18. ├── test_client.cpp
  19. ├── test_client.hpp
  20. └── test_client_main.cpp
  21. ├── test_server.cpp
  22. ├── test_server.hpp
  23. └── test_server_main.cpp
  24. ├── sched_test
  25. ├── CMakeLists.txt
  26. └── test_sched.cpp
  27. ├── stack_test
  28. ├── CMakeLists.txt
  29. └── test_stack.cpp
  30. ├── tcp_echo_server_example
  31. ├── CMakeLists.txt
  32. └── test_echo_server.cpp
  33. ├── test_chroutine.cpp
  34. └── timer_example
  35. ├── CMakeLists.txt
  36. └── test_timer.cpp
  37. $ cd examples/build
  38. $ ./configure.sh
  39. $ cd build
  40. $ 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

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

build and install

  1. git clone https://github.com/grpc/grpc
  2. cd grpc
  3. git submodule update --init
  4. make
  5. [sudo] make install

error and solution

if get configure error:

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

try:

  1. cd third_party/protobuf
  2. 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:

  1. Submodule 'third_party/abseil-cpp' (https://github.com/abseil/abseil-cpp) registered for path 'third_party/abseil-cpp'
  2. Submodule 'third_party/benchmark' (https://github.com/google/benchmark) registered for path 'third_party/benchmark'
  3. Submodule 'third_party/bloaty' (https://github.com/google/bloaty.git) registered for path 'third_party/bloaty'
  4. Submodule 'third_party/boringssl' (https://github.com/google/boringssl.git) registered for path 'third_party/boringssl'
  5. Submodule 'third_party/boringssl-with-bazel' (https://boringssl.googlesource.com/boringssl) registered for path 'third_party/boringssl-with-bazel'
  6. Submodule 'third_party/cares/cares' (https://github.com/c-ares/c-ares.git) registered for path 'third_party/cares/cares'
  7. Submodule 'third_party/gflags' (https://github.com/gflags/gflags.git) registered for path 'third_party/gflags'
  8. Submodule 'third_party/googletest' (https://github.com/google/googletest.git) registered for path 'third_party/googletest'
  9. Submodule 'third_party/protobuf' (https://github.com/google/protobuf.git) registered for path 'third_party/protobuf'
  10. Submodule 'third_party/zlib' (https://github.com/madler/zlib) registered for path 'third_party/zlib'

install protoc

it was build but not installed:

  1. cd third_party/protobuf
  2. sudo make install

try to generate protobuf code

  1. cd proto_def
  2. sh gen.sh test.proto

You should see four files:

  1. ├── proto_code
  2. ├── test.grpc.pb.cc
  3. ├── test.grpc.pb.h
  4. ├── test.pb.cc
  5. └── test.pb.h

install libcurl (if you need the http client module)

curl.git