Skip to content

Commit

Permalink
Merge commit '68e7eace0e41683b677c6b38ad5385bd26d4cbd1' into v2
Browse files Browse the repository at this point in the history
# Conflicts:
#	project/cmake/CompilerOption.cmake
  • Loading branch information
owent committed Mar 24, 2019
2 parents fa1af66 + 68e7eac commit 03247f5
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 115 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
cmake_minimum_required(VERSION 3.7.0)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13")
cmake_policy(SET CMP0074 NEW)
endif()

enable_testing()

Expand Down Expand Up @@ -61,6 +64,14 @@ configure_file(
@ONLY
)

if (COMPILER_STRICT_EXTRA_CFLAGS)
add_definitions(${COMPILER_STRICT_EXTRA_CFLAGS})
endif ()

if (COMPILER_STRICT_CFLAGS)
add_definitions(${COMPILER_STRICT_CFLAGS})
endif ()

## 导入所有工程项目
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/src")

Expand Down
12 changes: 6 additions & 6 deletions include/libcopp/stack/allocator/stack_allocator_pool.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef COPP_STACKCONTEXT_ALLOCATOR_POOL_H
#define COPP_STACKCONTEXT_ALLOCATOR_POOL_H
#ifndef COPP_STACKCONTEXT_ALLOCATOR_POOL_H
#define COPP_STACKCONTEXT_ALLOCATOR_POOL_H

#pragma once

Expand Down Expand Up @@ -29,7 +29,7 @@ namespace copp {

public:
stack_allocator_pool() UTIL_CONFIG_NOEXCEPT {}
stack_allocator_pool(const std::shared_ptr<pool_t>& p) UTIL_CONFIG_NOEXCEPT : pool_(p){}
stack_allocator_pool(const std::shared_ptr<pool_t> &p) UTIL_CONFIG_NOEXCEPT : pool_(p) {}
~stack_allocator_pool() {}

/**
Expand All @@ -46,7 +46,7 @@ namespace copp {
* @param size ignored
* @note size must less or equal than attached
*/
void allocate(stack_context &ctx, std::size_t size) UTIL_CONFIG_NOEXCEPT {
void allocate(stack_context &ctx, std::size_t) UTIL_CONFIG_NOEXCEPT {
assert(pool_);
if (pool_) {
pool_->allocate(ctx);
Expand All @@ -67,8 +67,8 @@ namespace copp {
private:
std::shared_ptr<pool_t> pool_;
};
}
}
} // namespace allocator
} // namespace copp

#ifdef COPP_HAS_ABI_HEADERS
#include COPP_ABI_SUFFIX
Expand Down
34 changes: 17 additions & 17 deletions include/libcopp/stack/stack_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace copp {
template <typename TAlloc>
class stack_pool {
public:
typedef TAlloc allocator_t;
typedef TAlloc allocator_t;
typedef std::shared_ptr<stack_pool<TAlloc> > ptr_t;

struct limit_t {
Expand All @@ -39,7 +39,7 @@ namespace copp {
size_t max_stack_size;
size_t min_stack_number;
size_t min_stack_size;
bool auto_gc;
bool auto_gc;
};

private:
Expand All @@ -51,18 +51,18 @@ namespace copp {
public:
static ptr_t create() { return std::make_shared<stack_pool>(constructor_delegator()); }

stack_pool(constructor_delegator d) {
stack_pool(constructor_delegator) {
memset(&limits_, 0, sizeof(limits_));
memset(&conf_, 0, sizeof(conf_));
conf_.stack_size = copp::stack_traits::default_size();
conf_.auto_gc = true;
conf_.auto_gc = true;
}
~stack_pool() { clear(); }

inline const limit_t &get_limit() const { return limits_; }

// configure
inline allocator_t &get_origin_allocator() COPP_MACRO_NOEXCEPT { return alloc_; }
inline allocator_t & get_origin_allocator() COPP_MACRO_NOEXCEPT { return alloc_; }
inline const allocator_t &get_origin_allocator() const COPP_MACRO_NOEXCEPT { return alloc_; }

size_t set_stack_size(size_t sz) {
Expand All @@ -81,20 +81,20 @@ namespace copp {
size_t get_stack_size() const { return conf_.stack_size; }
size_t get_stack_size_offset() const { return conf_.stack_offset; }

inline void set_max_stack_size(size_t sz) COPP_MACRO_NOEXCEPT { conf_.max_stack_size = sz; }
inline void set_max_stack_size(size_t sz) COPP_MACRO_NOEXCEPT { conf_.max_stack_size = sz; }
inline size_t get_max_stack_size() const COPP_MACRO_NOEXCEPT { return conf_.max_stack_size; }
inline void set_max_stack_number(size_t sz) COPP_MACRO_NOEXCEPT { conf_.max_stack_number = sz; }
inline void set_max_stack_number(size_t sz) COPP_MACRO_NOEXCEPT { conf_.max_stack_number = sz; }
inline size_t get_max_stack_number() const COPP_MACRO_NOEXCEPT { return conf_.max_stack_number; }

inline void set_min_stack_size(size_t sz) COPP_MACRO_NOEXCEPT { conf_.min_stack_size = sz; }
inline void set_min_stack_size(size_t sz) COPP_MACRO_NOEXCEPT { conf_.min_stack_size = sz; }
inline size_t get_min_stack_size() const COPP_MACRO_NOEXCEPT { return conf_.min_stack_size; }
inline void set_min_stack_number(size_t sz) COPP_MACRO_NOEXCEPT { conf_.min_stack_number = sz; }
inline void set_min_stack_number(size_t sz) COPP_MACRO_NOEXCEPT { conf_.min_stack_number = sz; }
inline size_t get_min_stack_number() const COPP_MACRO_NOEXCEPT { return conf_.min_stack_number; }

inline void set_auto_gc(bool v) COPP_MACRO_NOEXCEPT { conf_.auto_gc = v; }
inline bool is_auto_gc() const COPP_MACRO_NOEXCEPT { return conf_.auto_gc; }

inline void set_gc_once_number(size_t v) COPP_MACRO_NOEXCEPT { conf_.gc_number = v; }
inline void set_gc_once_number(size_t v) COPP_MACRO_NOEXCEPT { conf_.gc_number = v; }
inline size_t get_gc_once_number() const COPP_MACRO_NOEXCEPT { return conf_.gc_number; }

// actions
Expand All @@ -111,13 +111,13 @@ namespace copp {
#endif
// check limit
if (0 != conf_.max_stack_number && limits_.used_stack_number >= conf_.max_stack_number) {
ctx.sp = NULL;
ctx.sp = NULL;
ctx.size = 0;
return;
}

if (0 != conf_.max_stack_size && limits_.used_stack_size + conf_.stack_size > conf_.max_stack_size) {
ctx.sp = NULL;
ctx.sp = NULL;
ctx.size = 0;
return;
}
Expand Down Expand Up @@ -234,12 +234,12 @@ namespace copp {
util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
#endif

size_t keep_size = limits_.free_stack_size >> 1;
size_t keep_size = limits_.free_stack_size >> 1;
size_t keep_number = limits_.free_stack_number >> 1;
size_t left_gc = conf_.gc_number;
size_t left_gc = conf_.gc_number;
while (limits_.free_stack_size > keep_size || limits_.free_stack_number > keep_number) {
if (free_list_.empty()) {
limits_.free_stack_size = 0;
limits_.free_stack_size = 0;
limits_.free_stack_number = 0;
break;
}
Expand Down Expand Up @@ -282,7 +282,7 @@ namespace copp {
util::lock::lock_holder<util::lock::spin_lock> lock_guard(action_lock_);
#endif

limits_.free_stack_size = 0;
limits_.free_stack_size = 0;
limits_.free_stack_number = 0;

for (typename std::list<stack_context>::iterator iter = free_list_.begin(); iter != free_list_.end(); ++iter) {
Expand All @@ -293,7 +293,7 @@ namespace copp {
}

private:
limit_t limits_;
limit_t limits_;
configure_t conf_;
allocator_t alloc_;
#if !defined(PROJECT_DISABLE_MT) || !(PROJECT_DISABLE_MT)
Expand Down
5 changes: 5 additions & 0 deletions include/libcopp/utils/config/compiler_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# define UTIL_CONFIG_COMPILER_IS_Cray 0
# define UTIL_CONFIG_COMPILER_IS_TI 0
# define UTIL_CONFIG_COMPILER_IS_Fujitsu 0
# define UTIL_CONFIG_COMPILER_IS_GHS 0
# define UTIL_CONFIG_COMPILER_IS_SCO 0
# define UTIL_CONFIG_COMPILER_IS_AppleClang 0
# define UTIL_CONFIG_COMPILER_IS_Clang 0
Expand Down Expand Up @@ -100,6 +101,10 @@
# undef UTIL_CONFIG_COMPILER_IS_Fujitsu
# define UTIL_CONFIG_COMPILER_IS_Fujitsu 1

#elif defined(__ghs__)
# undef UTIL_CONFIG_COMPILER_IS_GHS
# define UTIL_CONFIG_COMPILER_IS_GHS 1

#elif defined(__SCO_VERSION__)
# undef UTIL_CONFIG_COMPILER_IS_SCO
# define UTIL_CONFIG_COMPILER_IS_SCO 1
Expand Down
168 changes: 168 additions & 0 deletions include/libcopp/utils/std/explicit_declare.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/**
* @file explicit_declare.h
* @brief 导入继承关系约束<br />
* Licensed under the MIT licenses.
*
* @version 1.0
* @author OWenT, owt5008137@live.com
* @date 2013-12-25
*
* @history
*
*/
#ifndef STD_EXPLICIT_DECLARE_H
#define STD_EXPLICIT_DECLARE_H


#pragma once

// ============================================================
// 公共包含部分
// C++0x/11/14/17 显示申明
// ============================================================

#ifndef PARAM_IN
#if defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
#define PARAM_IN _In_
#else
#define PARAM_IN
#endif
#endif

#ifndef PARAM_OUT
#if defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
#define PARAM_OUT _Out_
#else
#define PARAM_OUT
#endif
#endif

#ifndef PARAM_INOUT
#if defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
#define PARAM_INOUT _Inout_
#else
#define PARAM_INOUT
#endif
#endif


/**
* @brief deprecated, 标记为不推荐使用
* usage:
* EXPLICIT_DEPRECATED_ATTR int a;
* class EXPLICIT_DEPRECATED_ATTR a;
* EXPLICIT_DEPRECATED_ATTR int a();
* usage:
* EXPLICIT_DEPRECATED_MSG("there is better choose") int a;
* class DEPRECATED_MSG("there is better choose") a;
* EXPLICIT_DEPRECATED_MSG("there is better choose") int a();
*/
#if defined(__cplusplus) && __cplusplus >= 201402L
#define EXPLICIT_DEPRECATED_ATTR [[deprecated]]
#elif defined(__clang__)
#define EXPLICIT_DEPRECATED_ATTR __attribute__((deprecated))
#elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#define EXPLICIT_DEPRECATED_ATTR __attribute__((deprecated))
#elif defined(_MSC_VER) && _MSC_VER >= 1400 // vs 2005 or higher
#if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
#define EXPLICIT_DEPRECATED_ATTR [[deprecated]]
#else
#define EXPLICIT_DEPRECATED_ATTR __declspec(deprecated)
#endif
#else
#define EXPLICIT_DEPRECATED_ATTR
#endif

#if defined(__cplusplus) && __cplusplus >= 201402L
#define EXPLICIT_DEPRECATED_MSG(msg) [[deprecated(msg)]]
#elif defined(__clang__)
#define EXPLICIT_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
#elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#define EXPLICIT_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
#elif defined(_MSC_VER) && _MSC_VER >= 1400 // vs 2005 or higher
#if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
#define EXPLICIT_DEPRECATED_MSG(msg) [[deprecated(msg)]]
#else
#define EXPLICIT_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
#endif
#else
#define EXPLICIT_DEPRECATED_MSG(msg)
#endif

/**
* @brief nodiscard, 标记禁止忽略返回值
* usage:
* EXPLICIT_NODISCARD_ATTR int a;
* class EXPLICIT_NODISCARD_ATTR a;
* EXPLICIT_NODISCARD_ATTR int a();
*/
#if defined(__cplusplus) && __cplusplus >= 201703L
#define EXPLICIT_NODISCARD_ATTR [[nodiscard]]
#elif defined(__clang__)
#define EXPLICIT_NODISCARD_ATTR __attribute__((warn_unused_result))
#elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#define EXPLICIT_NODISCARD_ATTR __attribute__((warn_unused_result))
#elif defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
#if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
#define EXPLICIT_NODISCARD_ATTR [[nodiscard]]
#else
#define EXPLICIT_NODISCARD_ATTR _Check_return_
#endif
#else
#define EXPLICIT_NODISCARD_ATTR
#endif

/**
* @brief maybe_unused, 标记忽略unused警告
* usage:
* EXPLICIT_UNUSED_ATTR int a;
* class EXPLICIT_UNUSED_ATTR a;
* EXPLICIT_UNUSED_ATTR int a();
*/
#if defined(__cplusplus) && __cplusplus >= 201703L
#define EXPLICIT_UNUSED_ATTR [[maybe_unused]]
#elif defined(__clang__)
#define EXPLICIT_UNUSED_ATTR __attribute__((unused))
#elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#define EXPLICIT_UNUSED_ATTR __attribute__((unused))
#elif defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
#if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
#define EXPLICIT_UNUSED_ATTR [[maybe_unused]]
#else
#define EXPLICIT_UNUSED_ATTR
#endif
#else
#define EXPLICIT_UNUSED_ATTR
#endif

/**
* @brief fallthrough, 标记忽略switch内case的无break警告
* usage:
* EXPLICIT_FALLTHROUGH int a;
* switch (xxx) {
* case XXX:
* EXPLICIT_FALLTHROUGH
*/
#if defined(__cplusplus) && __cplusplus >= 201703L
#define EXPLICIT_FALLTHROUGH [[fallthrough]];
#elif defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__) >= 309
#if defined(__apple_build_version__)
#define EXPLICIT_FALLTHROUGH
#elif defined(__has_warning) && __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
#define EXPLICIT_FALLTHROUGH [[clang::fallthrough]];
#else
#define EXPLICIT_FALLTHROUGH
#endif
#elif defined(__GNUC__) && (__GNUC__ >= 7)
#define EXPLICIT_FALLTHROUGH [[gnu::fallthrough]];
#elif defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
#if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
#define EXPLICIT_FALLTHROUGH [[fallthrough]];
#else
#define EXPLICIT_FALLTHROUGH
#endif
#else
#define EXPLICIT_FALLTHROUGH
#endif

#endif
Loading

0 comments on commit 03247f5

Please sign in to comment.