Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pyopencl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Klöckner
pyopencl
Commits
06f0f807
Commit
06f0f807
authored
10 years ago
by
Yichao Yu
Browse files
Options
Downloads
Patches
Plain Diff
async
parent
40da708e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/c_wrapper/async.cpp
+6
-4
6 additions, 4 deletions
src/c_wrapper/async.cpp
src/c_wrapper/async.h
+2
-0
2 additions, 0 deletions
src/c_wrapper/async.h
with
8 additions
and
4 deletions
src/c_wrapper/async.cpp
+
6
−
4
View file @
06f0f807
#include
"async.h"
#include
"async.h"
#include
"function.h"
#include
<queue>
#include
<queue>
#include
<thread>
#include
<thread>
...
@@ -14,7 +15,7 @@ private:
...
@@ -14,7 +15,7 @@ private:
std
::
mutex
m_mutex
;
std
::
mutex
m_mutex
;
std
::
condition_variable
m_cond
;
std
::
condition_variable
m_cond
;
public:
public:
T
PYOPENCL_INLINE
T
pop
()
pop
()
{
{
std
::
unique_lock
<
std
::
mutex
>
mlock
(
m_mutex
);
std
::
unique_lock
<
std
::
mutex
>
mlock
(
m_mutex
);
...
@@ -25,10 +26,11 @@ public:
...
@@ -25,10 +26,11 @@ public:
m_queue
.
pop
();
m_queue
.
pop
();
return
item
;
return
item
;
}
}
void
PYOPENCL_INLINE
void
push
(
const
T
&
item
)
push
(
const
T
&
item
)
{
{
{
{
// Sub scope for the lock
std
::
unique_lock
<
std
::
mutex
>
mlock
(
m_mutex
);
std
::
unique_lock
<
std
::
mutex
>
mlock
(
m_mutex
);
m_queue
.
push
(
item
);
m_queue
.
push
(
item
);
}
}
...
@@ -58,12 +60,12 @@ private:
...
@@ -58,12 +60,12 @@ private:
t
.
detach
();
t
.
detach
();
}
}
public
:
public
:
void
PYOPENCL_INLINE
void
ensure_thread
()
ensure_thread
()
{
{
std
::
call_once
(
m_flag
,
&
AsyncCaller
::
start_thread
,
this
);
std
::
call_once
(
m_flag
,
&
AsyncCaller
::
start_thread
,
this
);
}
}
void
PYOPENCL_INLINE
void
push
(
const
std
::
function
<
void
()
>
&
func
)
push
(
const
std
::
function
<
void
()
>
&
func
)
{
{
ensure_thread
();
ensure_thread
();
...
...
This diff is collapsed.
Click to expand it.
src/c_wrapper/async.h
+
2
−
0
View file @
06f0f807
...
@@ -5,7 +5,9 @@
...
@@ -5,7 +5,9 @@
namespace
pyopencl
{
namespace
pyopencl
{
// Start the helper thread
void
init_async
();
void
init_async
();
// Call @func in the helper thread
void
call_async
(
const
std
::
function
<
void
()
>
&
func
);
void
call_async
(
const
std
::
function
<
void
()
>
&
func
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment