-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from headupinclouds/pr.template.storage.size
Pr.template.storage.size
- Loading branch information
Showing
12 changed files
with
550 additions
and
398 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,82 @@ | ||
#ifndef ASIO_THREAD_POOL_HPP | ||
#define ASIO_THREAD_POOL_HPP | ||
|
||
#include <boost/asio.hpp> | ||
|
||
#include <functional> | ||
#include <thread> | ||
#include <vector> | ||
#include <memory> | ||
|
||
class AsioThreadPool | ||
{ | ||
public: | ||
inline AsioThreadPool(size_t threads); | ||
|
||
inline ~AsioThreadPool() | ||
{ | ||
stop(); | ||
} | ||
|
||
inline void joinThreadPool(); | ||
|
||
template <typename Handler> | ||
inline void post(Handler &&handler) | ||
{ | ||
m_io_svc.post(handler); | ||
} | ||
|
||
private: | ||
inline void start(); | ||
inline void stop(); | ||
inline void worker_thread_func(); | ||
|
||
boost::asio::io_service m_io_svc; | ||
std::unique_ptr<boost::asio::io_service::work> m_work; | ||
|
||
std::vector<std::thread> m_threads; | ||
}; | ||
|
||
inline AsioThreadPool::AsioThreadPool(size_t threads) | ||
: m_threads(threads) | ||
{ | ||
start(); | ||
} | ||
|
||
inline void AsioThreadPool::start() | ||
{ | ||
m_work.reset(new boost::asio::io_service::work(m_io_svc)); | ||
|
||
for (auto &i : m_threads) | ||
{ | ||
i = std::thread(&AsioThreadPool::worker_thread_func, this); | ||
} | ||
|
||
} | ||
|
||
inline void AsioThreadPool::stop() | ||
{ | ||
m_work.reset(); | ||
|
||
m_io_svc.stop(); | ||
|
||
for (auto &i : m_threads) | ||
{ | ||
if (i.joinable()) | ||
{ | ||
i.join(); | ||
} | ||
} | ||
} | ||
|
||
inline void AsioThreadPool::joinThreadPool() | ||
{ | ||
m_io_svc.run(); | ||
} | ||
|
||
inline void AsioThreadPool::worker_thread_func() | ||
{ | ||
joinThreadPool(); | ||
} | ||
|
||
#endif | ||
#ifndef ASIO_THREAD_POOL_HPP | ||
#define ASIO_THREAD_POOL_HPP | ||
|
||
#include <boost/asio.hpp> | ||
|
||
#include <functional> | ||
#include <thread> | ||
#include <vector> | ||
#include <memory> | ||
|
||
class AsioThreadPool | ||
{ | ||
public: | ||
inline AsioThreadPool(size_t threads); | ||
|
||
inline ~AsioThreadPool() | ||
{ | ||
stop(); | ||
} | ||
|
||
inline void joinThreadPool(); | ||
|
||
template <typename Handler> | ||
inline void post(Handler &&handler) | ||
{ | ||
m_io_svc.post(handler); | ||
} | ||
|
||
private: | ||
inline void start(); | ||
inline void stop(); | ||
inline void worker_thread_func(); | ||
|
||
boost::asio::io_service m_io_svc; | ||
std::unique_ptr<boost::asio::io_service::work> m_work; | ||
|
||
std::vector<std::thread> m_threads; | ||
}; | ||
|
||
inline AsioThreadPool::AsioThreadPool(size_t threads) | ||
: m_threads(threads) | ||
{ | ||
start(); | ||
} | ||
|
||
inline void AsioThreadPool::start() | ||
{ | ||
m_work.reset(new boost::asio::io_service::work(m_io_svc)); | ||
|
||
for (auto &i : m_threads) | ||
{ | ||
i = std::thread(&AsioThreadPool::worker_thread_func, this); | ||
} | ||
|
||
} | ||
|
||
inline void AsioThreadPool::stop() | ||
{ | ||
m_work.reset(); | ||
|
||
m_io_svc.stop(); | ||
|
||
for (auto &i : m_threads) | ||
{ | ||
if (i.joinable()) | ||
{ | ||
i.join(); | ||
} | ||
} | ||
} | ||
|
||
inline void AsioThreadPool::joinThreadPool() | ||
{ | ||
m_io_svc.run(); | ||
} | ||
|
||
inline void AsioThreadPool::worker_thread_func() | ||
{ | ||
joinThreadPool(); | ||
} | ||
|
||
#endif |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <worker.hpp> | ||
|
||
size_t getWorkerIdForCurrentThread() | ||
{ | ||
return *detail::thread_id(); | ||
} | ||
|
||
size_t getWorkerIdForCurrentThread2() | ||
{ | ||
return Worker::getWorkerIdForCurrentThread(); | ||
} |
Oops, something went wrong.