This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef TIMER_POOL_IMPL_HPP_ | |
| #define TIMER_POOL_IMPL_HPP_ | |
| #include <vector> | |
| #include <algorithm> | |
| #include <functional> | |
| #include <windows.h> | |
| #include <assert.h> | |
| #include <mutex> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define begin() \ | |
| static unsigned int state_ = 0;\ | |
| switch (state_) \ | |
| case 0: | |
| #define _yield_impl(x_, z_) \ | |
| do { \ | |
| state_ = z_; \ | |
| ##x_; \ | |
| goto exit__;\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "yield.hpp" // Enable the pseudo-keywords reenter, yield and fork. | |
| void server::operator()(boost::system::error_code ec, std::size_t length) | |
| { | |
| // In this example we keep the error handling code in one place by | |
| // hoisting it outside the coroutine. An alternative approach would be to | |
| // check the value of ec after each yield for an asynchronous operation. | |
| if (!ec) | |
| { | |
| // On reentering a coroutine, control jumps to the location of the last |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void coroutine_executor_ex() { | |
| std::cout<<__FUNCTION__<<std::endl; | |
| coroutine_ref _coro_value = this; | |
| switch (_coro_value) | |
| { | |
| case -1: | |
| { | |
| if (_coro_value) | |
| { | |
| goto terminate_coroutine; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define begin() \ | |
| static unsigned int state_ = 0;\ | |
| switch (state_) \ | |
| case 0: | |
| #define _yield_impl(x_, z_) \ | |
| do { \ | |
| state_ = z_; \ | |
| ##x_; \ | |
| goto exit__;\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void coroutine_executor() { | |
| reenter(this) { | |
| std::cout<<"before yield 1"<<std::endl; | |
| yield task_thread_pool_.post_task([&](){ | |
| std::cout<<"yield 1"<<std::endl; | |
| coroutine_executor(); | |
| }); | |
| std::cout<<"after yield 1"<<std::endl; | |
| yield task_thread_pool_.post_task([&](){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef PRODUCER_TASK_HPP | |
| #define PRODUCER_TASK_HPP | |
| #include <deque> | |
| #include <utility> | |
| #include <functional> | |
| #include <base/coroutine.hpp> | |
| template <typename data_t, typename task_pool_t> | |
| class producer_task { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inline std::string base64_encode(std::string src) | |
| { | |
| std::string tail(3, '\0'); | |
| std::vector<char> result(src.length()/3*4+6); | |
| unsigned int one_third_len = src.length()/3; | |
| unsigned int len_rounded_down = one_third_len*3; | |
| unsigned int j = len_rounded_down + one_third_len; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/xml" | |
| "fmt" | |
| "io/ioutil" | |
| "net/http" | |
| ) | |
| type RssItem struct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "crypto/tls" | |
| "net" | |
| "net/http" | |
| "time" | |
| "fmt" | |
| "errors" | |
| ) |