update README.md

minor

minor

minor
This commit is contained in:
Nomango 2019-07-22 12:59:23 +08:00
parent 2dc4c04482
commit ef4b0d85e6
5 changed files with 42 additions and 31 deletions

View File

@ -20,24 +20,27 @@
#include "AsyncTask.h"
#include "../platform/Application.h"
#include <thread>
namespace kiwano
{
AsyncTask::AsyncTask()
: thread_(MakeClosure(this, &AsyncTask::TaskThread))
{
}
AsyncTask::AsyncTask(AsyncTaskFunc func)
: AsyncTask()
{
Then(func);
}
AsyncTask::~AsyncTask()
{
}
void AsyncTask::Start()
{
std::thread thread(MakeClosure(this, &AsyncTask::TaskThread));
thread.detach();
thread_.detach();
// retain this object until finished
Retain();

View File

@ -21,7 +21,7 @@
#pragma once
#include "Object.h"
#include "../common/closure.hpp"
#include <functional>
#include <thread>
#include <mutex>
namespace kiwano
@ -41,6 +41,8 @@ namespace kiwano
AsyncTaskFunc func
);
virtual ~AsyncTask();
AsyncTask& Then(
AsyncTaskFunc func
);
@ -57,8 +59,9 @@ namespace kiwano
void Complete();
protected:
std::thread thread_;
std::mutex func_mutex_;
Queue<AsyncTaskFunc> thread_func_queue_;
AsyncTaskCallback thread_cb_;
std::mutex func_mutex_;
};
}

View File

@ -82,17 +82,17 @@ namespace kiwano
inline void swap(Array& rhs) noexcept { std::swap(size_, rhs.size_); std::swap(capacity_, rhs.capacity_); std::swap(data_, rhs.data_); }
inline void resize(size_type new_size) { resize(new_size, _Ty()); }
inline void resize(size_type new_size, const _Ty& v);
inline void reserve(size_type new_capacity);
void resize(size_type new_size, const _Ty& v);
void reserve(size_type new_capacity);
inline void push_back(const _Ty& val) { resize(size_ + 1, val); }
inline void pop_back() { if (empty()) throw std::out_of_range("pop() called on empty vector"); resize(size_ - 1); }
inline void push_front(const _Ty& val) { if (size_ == 0) push_back(val); else insert(begin(), val); }
inline iterator erase(const_iterator where) { return erase(where, where + 1); }
inline iterator erase(const_iterator first, const_iterator last);
iterator erase(const_iterator first, const_iterator last);
inline iterator insert(const_iterator where, const _Ty& v);
iterator insert(const_iterator where, const _Ty& v);
inline bool empty() const { return size_ == 0; }
inline size_type size() const { return size_; }
@ -134,7 +134,7 @@ namespace kiwano
};
template<typename _Ty, typename _Alloc, typename _Manager>
inline void Array<_Ty, _Alloc, _Manager>::resize(size_type new_size, const _Ty& val)
void Array<_Ty, _Alloc, _Manager>::resize(size_type new_size, const _Ty& val)
{
if (new_size > size_)
{
@ -152,7 +152,7 @@ namespace kiwano
}
template<typename _Ty, typename _Alloc, typename _Manager>
inline void Array<_Ty, _Alloc, _Manager>::reserve(size_type new_capacity)
void Array<_Ty, _Alloc, _Manager>::reserve(size_type new_capacity)
{
if (new_capacity <= capacity_)
return;
@ -170,7 +170,7 @@ namespace kiwano
}
template<typename _Ty, typename _Alloc, typename _Manager>
inline typename Array<_Ty, _Alloc, _Manager>::iterator
typename Array<_Ty, _Alloc, _Manager>::iterator
Array<_Ty, _Alloc, _Manager>::erase(const_iterator first, const_iterator last)
{
const auto off = first - begin();
@ -187,7 +187,7 @@ namespace kiwano
}
template<typename _Ty, typename _Alloc, typename _Manager>
inline typename Array<_Ty, _Alloc, _Manager>::iterator
typename Array<_Ty, _Alloc, _Manager>::iterator
Array<_Ty, _Alloc, _Manager>::insert(const_iterator where, const _Ty& v)
{
const auto off = where - begin();
@ -211,16 +211,16 @@ namespace kiwano
using size_type = size_t;
using allocator_type = typename _Alloc;
static inline void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memcpy(dest, src, (size_t)count * sizeof(value_type)); }
static inline void copy_data(value_type* dest, size_type count, const value_type& val) { ::memset(dest, (int)val, (size_t)count * sizeof(value_type)); }
static inline void move_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memmove(dest, src, (size_t)count * sizeof(value_type)); }
static void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memcpy(dest, src, (size_t)count * sizeof(value_type)); }
static void copy_data(value_type* dest, size_type count, const value_type& val) { ::memset(dest, (int)val, (size_t)count * sizeof(value_type)); }
static void move_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memmove(dest, src, (size_t)count * sizeof(value_type)); }
static inline value_type* allocate(size_type count) { return get_allocator().allocate(count); }
static inline void deallocate(value_type*& ptr, size_type count) { if (ptr) { get_allocator().deallocate(ptr, count); ptr = nullptr; } }
static value_type* allocate(size_type count) { return get_allocator().allocate(count); }
static void deallocate(value_type*& ptr, size_type count) { if (ptr) { get_allocator().deallocate(ptr, count); ptr = nullptr; } }
static inline void construct(value_type* ptr, size_type count) { }
static inline void construct(value_type* ptr, size_type count, const value_type& val) { while (count) { --count; *(ptr + count) = val; } }
static inline void destroy(value_type* ptr, size_type count) { }
static void construct(value_type* ptr, size_type count) { }
static void construct(value_type* ptr, size_type count, const value_type& val) { while (count) { --count; *(ptr + count) = val; } }
static void destroy(value_type* ptr, size_type count) { }
private:
static allocator_type& get_allocator()
@ -240,9 +240,9 @@ namespace kiwano
using size_type = size_t;
using allocator_type = typename _Alloc;
static inline void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; while (count--) (*dest++) = (*src++); }
static inline void copy_data(value_type* dest, size_type count, const value_type& val) { while (count--) (*dest++) = val; }
static inline void move_data(value_type* dest, const value_type* src, size_type count)
static void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; while (count--) (*dest++) = (*src++); }
static void copy_data(value_type* dest, size_type count, const value_type& val) { while (count--) (*dest++) = val; }
static void move_data(value_type* dest, const value_type* src, size_type count)
{
if (src == dest) return;
if (dest > src && dest < src + count)
@ -259,12 +259,12 @@ namespace kiwano
}
}
static inline value_type* allocate(size_type count) { return get_allocator().allocate(count); }
static inline void deallocate(value_type*& ptr, size_type count) { if (ptr) { get_allocator().deallocate(ptr, count); ptr = nullptr; } }
static value_type* allocate(size_type count) { return get_allocator().allocate(count); }
static void deallocate(value_type*& ptr, size_type count) { if (ptr) { get_allocator().deallocate(ptr, count); ptr = nullptr; } }
static inline void construct(value_type* ptr, size_type count) { construct(ptr, count, value_type()); }
static inline void construct(value_type* ptr, size_type count, const value_type& val) { while (count) get_allocator().construct(ptr + (--count), val); }
static inline void destroy(value_type* ptr, size_type count) { while (count) get_allocator().destroy(ptr + (--count)); }
static void construct(value_type* ptr, size_type count) { construct(ptr, count, value_type()); }
static void construct(value_type* ptr, size_type count, const value_type& val) { while (count) get_allocator().construct(ptr + (--count), val); }
static void destroy(value_type* ptr, size_type count) { while (count) get_allocator().destroy(ptr + (--count)); }
private:
static allocator_type& get_allocator()

View File

@ -42,6 +42,11 @@ namespace kiwano
typename _Manager::AddRef(ptr_);
}
IntrusivePtr(const Type* p) noexcept : ptr_(p)
{
typename _Manager::AddRef(ptr_);
}
IntrusivePtr(const IntrusivePtr& other) noexcept
: ptr_(other.ptr_)
{

View File

@ -26,5 +26,5 @@ More docs and examples will be added later.
* Particle system
## Contact
* Website: www.kiwanoengine.com
* Website: [kiwanoengine.com](https://kiwanoengine.com)
* QQ Group: 608406540