Skip to content

Commit

Permalink
libcopp stack pool
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed May 9, 2017
1 parent c75af74 commit 5aaf15e
Show file tree
Hide file tree
Showing 31 changed files with 1,391 additions and 700 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

# generated docs
doc/doxygen/*
docs/doxygen/*

# IDE & Editors
/.vscode
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Document

Generate document with doxygen.

Doxygen file located at *doc/libcopp.doxyfile* .
Doxygen file located at *docs/libcopp.doxyfile* .


INSTALL
Expand Down Expand Up @@ -202,9 +202,9 @@ On MinGW64, We use ms_pe_gas ASM code in boost.context to configure and build li
DEVELOPER
=========

[basic coroutine object summary](doc/basic_coroutine_class.txt)
[basic coroutine object summary](docs/basic_coroutine_class.txt)

[safe coroutine object summary](doc/safe_basic_coroutine_class.txt)
[safe coroutine object summary](docs/safe_basic_coroutine_class.txt)

HISTORY
========
Expand Down
7 changes: 0 additions & 7 deletions doc/md/060_DEVELOPER.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
2 changes: 1 addition & 1 deletion doc/md/000_DESCRIPTION.md → docs/md/000_DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Document

Generate document with doxygen.

Doxygen file located at *doc/libcopp.doxyfile* .
Doxygen file located at *docs/libcopp.doxyfile* .


File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions docs/md/060_DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DEVELOPER
=========

[basic coroutine object summary](docs/basic_coroutine_class.txt)

[safe coroutine object summary](docs/safe_basic_coroutine_class.txt)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions include/libcopp/stack/allocator/stack_allocator_malloc.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#ifndef _COPP_STACKCONTEXT_ALLOCATOR_MALLOC_H_
#define _COPP_STACKCONTEXT_ALLOCATOR_MALLOC_H_


#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

#include <cstddef>

Expand Down
3 changes: 0 additions & 3 deletions include/libcopp/stack/allocator/stack_allocator_memory.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#ifndef _COPP_STACKCONTEXT_ALLOCATOR_MEMORY_H_
#define _COPP_STACKCONTEXT_ALLOCATOR_MEMORY_H_


#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

#include <cstddef>

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

#pragma once

#include <assert.h>
#include <cstddef>

#include <libcopp/utils/features.h>
#include <libcopp/utils/std/smart_ptr.h>

#ifdef COPP_HAS_ABI_HEADERS
#include COPP_ABI_PREFIX
#endif

namespace copp {
struct stack_context;

namespace allocator {

/**
* @brief memory allocator
* this allocator will maintain buffer using malloc/free function
*/
template <typename TPool>
class stack_allocator_pool {
public:
typedef TPool pool_t;

public:
stack_allocator_pool() UTIL_CONFIG_NOEXCEPT {}
~stack_allocator_pool() {}

/**
* specify memory section allocated
* @param start_ptr buffer start address
* @param max_size buffer size
* @note must be called before allocate operation
*/
void attach(const std::shared_ptr<pool_t> &p) UTIL_CONFIG_NOEXCEPT { pool_ = p; }

/**
* allocate memory and attach to stack context [standard function]
* @param ctx stack context
* @param size ignored
* @note size must less or equal than attached
*/
void allocate(stack_context &ctx, std::size_t size) UTIL_CONFIG_NOEXCEPT {
assert(pool_);
if (pool_) {
pool_->allocate(ctx);
}
}

/**
* deallocate memory from stack context [standard function]
* @param ctx stack context
*/
void deallocate(stack_context &ctx) UTIL_CONFIG_NOEXCEPT {
assert(pool_);
if (pool_) {
pool_->deallocate(ctx);
}
}

private:
std::shared_ptr<pool_t> pool_;
};
}
}

#ifdef COPP_HAS_ABI_HEADERS
#include COPP_ABI_SUFFIX
#endif

#endif
3 changes: 0 additions & 3 deletions include/libcopp/stack/allocator/stack_allocator_posix.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#ifndef _COPP_STACKCONTEXT_ALLOCATOR_POSIX_H_
#define _COPP_STACKCONTEXT_ALLOCATOR_POSIX_H_


#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

#include <cstddef>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#ifndef _COPP_STACKCONTEXT_ALLOCATOR_SPLIT_SEGMENT_H_
#define _COPP_STACKCONTEXT_ALLOCATOR_SPLIT_SEGMENT_H_


#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

#include <cstddef>

Expand Down
3 changes: 0 additions & 3 deletions include/libcopp/stack/allocator/stack_allocator_windows.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#ifndef _COPP_STACKCONTEXT_ALLOCATOR_WINDOWS_H_
#define _COPP_STACKCONTEXT_ALLOCATOR_WINDOWS_H_


#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

#include <cstddef>

Expand Down
5 changes: 3 additions & 2 deletions include/libcopp/stack/stack_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

#include <libcopp/utils/features.h>

#include "allocator/stack_allocator_memory.h"
#include "allocator/stack_allocator_malloc.h"
#include "allocator/stack_allocator_memory.h"
#include "allocator/stack_allocator_pool.h"

#ifdef COPP_MACRO_USE_SEGMENTED_STACKS
#include "allocator/stack_allocator_split_segment.h"
Expand All @@ -28,7 +29,7 @@ namespace copp {
}
}

#else
#else

#error unknown stack allocator

Expand Down
Loading

0 comments on commit 5aaf15e

Please sign in to comment.