Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jamal Dahbur
libcloudstorage
Commits
348e5959
Commit
348e5959
authored
Feb 14, 2018
by
Paweł Wegner
Browse files
IThreadPool: use GenericCallback.
parent
f675c5ca
Changes
9
Hide whitespace changes
Inline
Side-by-side
bin/cloudbrowser/src/CloudContext.cpp
View file @
348e5959
...
...
@@ -416,9 +416,7 @@ ICloudProvider::Pointer CloudContext::provider(const std::string& name,
ThreadPoolWrapper
(
std
::
shared_ptr
<
IThreadPool
>
thread_pool
)
:
thread_pool_
(
thread_pool
)
{}
void
schedule
(
std
::
function
<
void
()
>
f
)
override
{
thread_pool_
->
schedule
(
f
);
}
void
schedule
(
const
Task
&
f
)
override
{
thread_pool_
->
schedule
(
f
);
}
private:
std
::
shared_ptr
<
IThreadPool
>
thread_pool_
;
...
...
bin/fuse/FuseCommon.cpp
View file @
348e5959
...
...
@@ -65,9 +65,7 @@ IHttpRequest::Pointer HttpWrapper::create(const std::string &url,
return
http_
->
create
(
url
,
method
,
follow_redirect
);
}
void
ThreadPoolWrapper
::
schedule
(
std
::
function
<
void
()
>
f
)
{
thread_pool_
->
schedule
(
f
);
}
void
ThreadPoolWrapper
::
schedule
(
const
Task
&
f
)
{
thread_pool_
->
schedule
(
f
);
}
IHttpServer
::
IResponse
::
Pointer
HttpServerCallback
::
handle
(
const
IHttpServer
::
IRequest
&
request
)
{
...
...
bin/fuse/FuseCommon.h
View file @
348e5959
...
...
@@ -35,7 +35,7 @@ class ThreadPoolWrapper : public IThreadPool {
ThreadPoolWrapper
(
std
::
shared_ptr
<
IThreadPool
>
thread_pool
)
:
thread_pool_
(
thread_pool
)
{}
void
schedule
(
std
::
function
<
void
()
>
f
)
override
;
void
schedule
(
const
Task
&
f
)
override
;
private:
std
::
shared_ptr
<
IThreadPool
>
thread_pool_
;
...
...
src/IHttp.h
View file @
348e5959
...
...
@@ -29,6 +29,8 @@
#include
<string>
#include
<unordered_map>
#include
"IRequest.h"
namespace
cloudstorage
{
class
IHttpRequest
{
...
...
@@ -38,7 +40,7 @@ class IHttpRequest {
using
Pointer
=
std
::
shared_ptr
<
IHttpRequest
>
;
using
GetParameters
=
std
::
unordered_map
<
std
::
string
,
std
::
string
>
;
using
HeaderParameters
=
std
::
unordered_map
<
std
::
string
,
std
::
string
>
;
using
CompleteCallback
=
std
::
function
<
void
(
Response
)
>
;
using
CompleteCallback
=
GenericCallback
<
Response
>
;
struct
Response
{
int
http_code_
;
...
...
src/IHttpServer.h
View file @
348e5959
...
...
@@ -28,6 +28,8 @@
#include
<string>
#include
<unordered_map>
#include
"IRequest.h"
namespace
cloudstorage
{
class
IHttpServer
{
...
...
@@ -42,7 +44,7 @@ class IHttpServer {
public:
using
Pointer
=
std
::
unique_ptr
<
IResponse
>
;
using
Headers
=
std
::
unordered_map
<
std
::
string
,
std
::
string
>
;
using
CompletedCallback
=
std
::
function
<
void
()
>
;
using
CompletedCallback
=
GenericCallback
<
>
;
static
constexpr
int
UnknownSize
=
-
1
;
...
...
src/IRequest.h
View file @
348e5959
...
...
@@ -226,7 +226,7 @@ class GenericCallback {
GenericCallback
(
typename
IGenericCallback
<
Arguments
...
>::
Pointer
functor
)
:
functor_
(
functor
)
{}
operator
bool
()
const
{
return
functor_
;
}
operator
bool
()
const
{
return
static_cast
<
bool
>
(
functor_
)
;
}
void
operator
()(
Arguments
...
d
)
const
{
functor_
->
done
(
d
...);
}
...
...
src/IThreadPool.h
View file @
348e5959
...
...
@@ -26,17 +26,20 @@
#include
<functional>
#include
<memory>
#include
"IRequest.h"
namespace
cloudstorage
{
class
IThreadPool
{
public:
using
Pointer
=
std
::
unique_ptr
<
IThreadPool
>
;
using
Task
=
GenericCallback
<>
;
virtual
~
IThreadPool
()
=
default
;
static
Pointer
create
(
uint32_t
thread_count
);
virtual
void
schedule
(
std
::
function
<
void
()
>
f
)
=
0
;
virtual
void
schedule
(
const
Task
&
f
)
=
0
;
};
}
// namespace cloudstorage
...
...
src/Utility/ThreadPool.cpp
View file @
348e5959
...
...
@@ -33,7 +33,7 @@ IThreadPool::Pointer IThreadPool::create(uint32_t cnt) {
ThreadPool
::
ThreadPool
(
uint32_t
thread_count
)
:
worker_
(
thread_count
)
{}
void
ThreadPool
::
schedule
(
std
::
function
<
void
()
>
f
)
{
void
ThreadPool
::
schedule
(
const
Task
&
f
)
{
auto
it
=
std
::
min_element
(
worker_
.
begin
(),
worker_
.
end
(),
[](
const
Worker
&
w1
,
const
Worker
&
w2
)
{
std
::
unique_lock
<
std
::
mutex
>
l1
(
w1
.
mutex_
);
...
...
src/Utility/ThreadPool.h
View file @
348e5959
...
...
@@ -35,7 +35,7 @@ class ThreadPool : public IThreadPool {
public:
ThreadPool
(
uint32_t
thread_count
);
void
schedule
(
std
::
function
<
void
()
>
f
)
override
;
void
schedule
(
const
Task
&
f
)
override
;
private:
struct
Worker
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment