Browse Source

整理头文件定义,使得重要的类放在显眼之处

tags/v2.9.7
tearshark 4 years ago
parent
commit
cba8cd7d8f
6 changed files with 131 additions and 117 deletions
  1. 2
    1
      librf/librf.h
  2. 38
    116
      librf/src/def.h
  3. 58
    0
      librf/src/exception.inl
  4. 25
    0
      librf/src/type_traits.inl
  5. 2
    0
      vs_proj/librf.vcxproj
  6. 6
    0
      vs_proj/librf.vcxproj.filters

+ 2
- 1
librf/librf.h View File

@@ -16,6 +16,8 @@
#pragma once
#include "src/future.h"
#include "src/awaitable.h"
#include "src/event.h"
#include "src/mutex.h"
#include "src/channel.h"
@@ -23,7 +25,6 @@
#include "src/promise.inl"
#include "src/state.inl"
#include "src/sleep.h"
#include "src/awaitable.h"
#if _HAS_CXX17 || RESUMEF_USE_BOOST_ANY
#include "src/when.h"

+ 38
- 116
librf/src/def.h View File

@@ -4,17 +4,11 @@
//#include <yvals.h>
#include <atomic>
#include <memory>
#include <chrono>
#include <thread>
#include <list>
#include <vector>
#include <deque>
#include <mutex>
#include <functional>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <optional>
#include <assert.h>
@@ -24,13 +18,39 @@
//替代<experimental/generator>,因为VS2015/VS2017的generator<>未实现return_value,导致yield后不能return
#include "generator.h"
#if defined(RESUMEF_DLL_EXPORT)
# define RF_API __declspec(dllexport)
#elif defined(RESUMEF_DLL_IMPORT)
# define RF_API __declspec(dllimport)
namespace resumef
{
struct scheduler_t;
template<class _Ty = void>
struct future_t;
using future_vt [[deprecated]] = future_t<>;
template<class _Ty = void>
struct promise_t;
template<class _Ty = void>
struct awaitable_t;
//获得当前线程下的调度器
scheduler_t* this_scheduler();
template <typename _Ty = std::nullptr_t, typename _Alloc = std::allocator<char>>
using generator_t = std::experimental::generator<_Ty, _Alloc>;
template<typename _PromiseT = void>
using coroutine_handle = std::experimental::coroutine_handle<_PromiseT>;
struct state_base_t;
#if _HAS_CXX17
template<class... _Mutexes>
using scoped_lock = std::scoped_lock<_Mutexes...>;
#else
# define RF_API
template<class... _Mutexes>
using scoped_lock = std::lock_guard<_Mutexes...>;
#endif
}
#if RESUMEF_DEBUG_COUNTER
extern std::mutex g_resumef_cout_mutex;
@@ -55,114 +75,16 @@ namespace std
#endif
}
namespace resumef
{
#if _HAS_CXX17
template<class... _Mutexes>
using scoped_lock = std::scoped_lock<_Mutexes...>;
#if defined(RESUMEF_DLL_EXPORT)
# define RF_API __declspec(dllexport)
#elif defined(RESUMEF_DLL_IMPORT)
# define RF_API __declspec(dllimport)
#else
template<class... _Mutexes>
using scoped_lock = std::lock_guard<_Mutexes...>;
# define RF_API
#endif
template<typename _PromiseT = void>
using coroutine_handle = std::experimental::coroutine_handle<_PromiseT>;
template <typename _Ty = std::nullptr_t, typename _Alloc = std::allocator<char>>
using generator_t = std::experimental::generator<_Ty, _Alloc>;
enum struct error_code
{
none,
not_ready, // get_value called when value not available
already_acquired, // attempt to get another future
unlock_more, // unlock 次数多余lock次数
read_before_write, // 0容量的channel,先读后写
timer_canceled, // 定时器被意外取消
max__
};
const char * get_error_string(error_code fe, const char * classname);
struct future_exception : std::exception
{
error_code _error;
future_exception(error_code fe)
: exception(get_error_string(fe, "future_exception"))
, _error(fe)
{
}
};
struct lock_exception : std::exception
{
error_code _error;
lock_exception(error_code fe)
: exception(get_error_string(fe, "lock_exception"))
, _error(fe)
{
}
};
struct channel_exception : std::exception
{
error_code _error;
channel_exception(error_code fe)
: exception(get_error_string(fe, "channel_exception"))
, _error(fe)
{
}
};
struct timer_canceled_exception : public std::exception
{
error_code _error;
timer_canceled_exception(error_code fe)
: exception(get_error_string(fe, "timer canceled"))
, _error(fe)
{
}
};
struct scheduler_t;
struct state_base_t;
template<class _Ty = void>
struct future_t;
using future_vt [[deprecated]] = future_t<>;
template<class _Ty = void>
struct promise_t;
template<class _Ty = void>
struct awaitable_t;
template<class _PromiseT>
struct is_promise : std::false_type {};
template<class _Ty>
struct is_promise<promise_t<_Ty>> : std::true_type {};
template<class _Ty>
_INLINE_VAR constexpr bool is_promise_v = is_promise<std::remove_cvref_t<_Ty>>::value;
template<class _PromiseT>
struct is_future : std::false_type {};
template<class _Ty>
struct is_future<future_t<_Ty>> : std::true_type {};
template<class _Ty>
_INLINE_VAR constexpr bool is_future_v = is_future<std::remove_cvref_t<_Ty>>::value;
template<class _G>
struct is_generator : std::false_type {};
template <typename _Ty, typename _Alloc>
struct is_generator<generator_t<_Ty, _Alloc>> : std::true_type {};
template<class _Ty>
_INLINE_VAR constexpr bool is_generator_v = is_generator<std::remove_cvref_t<_Ty>>::value;
//获得当前线程下的调度器
scheduler_t* this_scheduler();
}
#include "exception.inl"
#include "type_traits.inl"
#define co_yield_void co_yield nullptr
#define co_return_void co_return nullptr

+ 58
- 0
librf/src/exception.inl View File

@@ -0,0 +1,58 @@
#pragma once

namespace resumef
{
enum struct error_code
{
none,
not_ready, // get_value called when value not available
already_acquired, // attempt to get another future
unlock_more, // unlock 次数多余lock次数
read_before_write, // 0容量的channel,先读后写
timer_canceled, // 定时器被意外取消

max__
};

const char* get_error_string(error_code fe, const char* classname);

struct future_exception : std::exception
{
error_code _error;
future_exception(error_code fe)
: exception(get_error_string(fe, "future_exception"))
, _error(fe)
{
}
};

struct lock_exception : std::exception
{
error_code _error;
lock_exception(error_code fe)
: exception(get_error_string(fe, "lock_exception"))
, _error(fe)
{
}
};

struct channel_exception : std::exception
{
error_code _error;
channel_exception(error_code fe)
: exception(get_error_string(fe, "channel_exception"))
, _error(fe)
{
}
};

struct timer_canceled_exception : public std::exception
{
error_code _error;
timer_canceled_exception(error_code fe)
: exception(get_error_string(fe, "timer canceled"))
, _error(fe)
{
}
};
}

+ 25
- 0
librf/src/type_traits.inl View File

@@ -0,0 +1,25 @@
#pragma once

namespace resumef
{
template<class _PromiseT>
struct is_promise : std::false_type {};
template<class _Ty>
struct is_promise<promise_t<_Ty>> : std::true_type {};
template<class _Ty>
_INLINE_VAR constexpr bool is_promise_v = is_promise<std::remove_cvref_t<_Ty>>::value;

template<class _PromiseT>
struct is_future : std::false_type {};
template<class _Ty>
struct is_future<future_t<_Ty>> : std::true_type {};
template<class _Ty>
_INLINE_VAR constexpr bool is_future_v = is_future<std::remove_cvref_t<_Ty>>::value;

template<class _G>
struct is_generator : std::false_type {};
template <typename _Ty, typename _Alloc>
struct is_generator<generator_t<_Ty, _Alloc>> : std::true_type {};
template<class _Ty>
_INLINE_VAR constexpr bool is_generator_v = is_generator<std::remove_cvref_t<_Ty>>::value;
}

+ 2
- 0
vs_proj/librf.vcxproj View File

@@ -241,8 +241,10 @@
<ItemGroup>
<None Include="..\librf\src\asio_task_1.10.0.inl" />
<None Include="..\librf\src\asio_task_1.12.0.inl" />
<None Include="..\librf\src\exception.inl" />
<None Include="..\librf\src\promise.inl" />
<None Include="..\librf\src\state.inl" />
<None Include="..\librf\src\type_traits.inl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

+ 6
- 0
vs_proj/librf.vcxproj.filters View File

@@ -191,5 +191,11 @@
<None Include="..\librf\src\state.inl">
<Filter>librf\src</Filter>
</None>
<None Include="..\librf\src\exception.inl">
<Filter>librf\src</Filter>
</None>
<None Include="..\librf\src\type_traits.inl">
<Filter>librf\src</Filter>
</None>
</ItemGroup>
</Project>

Loading…
Cancel
Save