open png/jpg image with memory buffer
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* A Thread Pool Implementation
|
||||
* Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <time.h>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
#if defined(STD_THREAD_NOT_SUPPORTED)
|
||||
#include <nana/std_mutex.hpp>
|
||||
@@ -62,23 +63,22 @@ namespace threads
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
typedef HANDLE thread_t;
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#elif defined(NANA_POSIX)
|
||||
typedef pthread_t thread_t;
|
||||
#endif
|
||||
impl * pool_ptr;
|
||||
task * task_ptr;
|
||||
thread_t handle;
|
||||
volatile state thr_state;
|
||||
std::atomic<state> thr_state;
|
||||
time_t timestamp;
|
||||
#if defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#if defined(NANA_POSIX)
|
||||
std::mutex wait_mutex;
|
||||
std::condition_variable wait_cond;
|
||||
volatile bool suspended;
|
||||
std::atomic<bool> suspended;
|
||||
#endif
|
||||
};
|
||||
public:
|
||||
impl(std::size_t thr_number)
|
||||
: runflag_(true)
|
||||
{
|
||||
if(0 == thr_number) thr_number = 4;
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace threads
|
||||
pto->task_ptr = nullptr;
|
||||
#if defined(NANA_WINDOWS)
|
||||
pto->handle = (HANDLE)::_beginthreadex(0, 0, reinterpret_cast<unsigned(__stdcall*)(void*)>(&impl::_m_thr_starter), pto, 0, 0);
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#elif defined(NANA_POSIX)
|
||||
pto->suspended = false;
|
||||
::pthread_create(&(pto->handle), 0, reinterpret_cast<void*(*)(void*)>(&impl::_m_thr_starter), pto);
|
||||
#endif
|
||||
@@ -137,7 +137,7 @@ namespace threads
|
||||
#if defined(NANA_WINDOWS)
|
||||
::WaitForSingleObject(thr->handle, INFINITE);
|
||||
::CloseHandle(thr->handle);
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#elif defined(NANA_POSIX)
|
||||
::pthread_join(thr->handle, 0);
|
||||
::pthread_detach(thr->handle);
|
||||
#endif
|
||||
@@ -223,7 +223,7 @@ namespace threads
|
||||
pto->thr_state = state::idle;
|
||||
#if defined(NANA_WINDOWS)
|
||||
::SuspendThread(pto->handle);
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#elif defined(NANA_POSIX)
|
||||
std::unique_lock<std::mutex> lock(pto->wait_mutex);
|
||||
pto->suspended = true;
|
||||
pto->wait_cond.wait(lock);
|
||||
@@ -240,7 +240,7 @@ namespace threads
|
||||
if(n == 1 || n == static_cast<DWORD>(-1))
|
||||
break;
|
||||
}
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#elif defined(NANA_POSIX)
|
||||
while(false == pto->suspended)
|
||||
;
|
||||
std::unique_lock<std::mutex> lock(pto->wait_mutex);
|
||||
@@ -327,7 +327,7 @@ namespace threads
|
||||
::_endthreadex(0);
|
||||
return 0;
|
||||
}
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#elif defined(NANA_POSIX)
|
||||
static void * _m_thr_starter(pool_throbj * pto)
|
||||
{
|
||||
pto->pool_ptr->_m_thr_runner(pto);
|
||||
@@ -335,7 +335,7 @@ namespace threads
|
||||
}
|
||||
#endif
|
||||
private:
|
||||
volatile bool runflag_;
|
||||
std::atomic<bool> runflag_{ true };
|
||||
std::recursive_mutex mutex_;
|
||||
|
||||
struct signal
|
||||
|
||||
Reference in New Issue
Block a user