Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Louis BECQUEY
/
biorseo
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Network
Create a new issue
Builds
Commits
Authored by
Louis BECQUEY
2019-03-01 11:45:23 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
494f437bed51b1f2eec812d4936bba60c5368c68
494f437b
1 parent
0a4e941b
Multithreaded load on Desc files (indev)
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
93 additions
and
3 deletions
.vscode/settings.json
cppsrc/Motif.cpp
cppsrc/Motif.h
cppsrc/Pool.cpp
cppsrc/Pool.h
cppsrc/biominserter.cpp
.vscode/settings.json
View file @
494f437
...
...
@@ -52,7 +52,8 @@
"optional"
:
"cpp"
,
"string_view"
:
"cpp"
,
"cstdarg"
:
"cpp"
,
"iomanip"
:
"cpp"
"iomanip"
:
"cpp"
,
"string"
:
"cpp"
},
"python.pythonPath"
:
"/usr/bin/python3"
,
"editor.formatOnSave"
:
true
,
...
...
cppsrc/Motif.cpp
View file @
494f437
This diff is collapsed. Click to expand it.
cppsrc/Motif.h
View file @
494f437
#ifndef MOTIF_H_
#define MOTIF_H_
#include <mutex>
#include <string>
#include <vector>
...
...
@@ -8,6 +9,16 @@ using std::pair;
using
std
::
string
;
using
std
::
vector
;
class
Motif
;
// forward declaration
typedef
struct
args_
{
const
string
&
descfile
;
string
rna
;
vector
<
Motif
>&
final_results
;
std
::
mutex
&
posInsertionSites_mutex
;
args_
(
const
string
&
descfile_
,
string
rna_
,
vector
<
Motif
>&
vector_
,
std
::
mutex
&
mutex_
)
:
descfile
(
descfile_
),
rna
(
rna_
),
final_results
(
vector_
),
posInsertionSites_mutex
(
mutex_
){}
}
args_of_parallel_func
;
typedef
struct
Comp_
{
pair
<
uint
,
uint
>
pos
;
size_t
k
;
...
...
@@ -26,7 +37,7 @@ class Motif
Motif
();
Motif
(
const
vector
<
Component
>&
v
,
string
PDB
);
void
load_from_csv
(
string
csv_line
);
static
v
ector
<
Motif
>
build_from_desc
(
const
string
&
descfile
,
string
rna
);
static
v
oid
build_from_desc
(
args_of_parallel_func
arg_struct
);
static
char
is_valid_DESC
(
const
string
&
descfile
);
string
pos_string
(
void
)
const
;
string
get_origin
(
void
)
const
;
...
...
cppsrc/Pool.cpp
0 → 100644
View file @
494f437
#include "Pool.h"
Pool
::
Pool
()
:
m_function_queue
(),
m_lock
(),
m_data_condition
(),
m_accept_functions
(
true
)
{
}
Pool
::~
Pool
()
{
}
void
Pool
::
push
(
std
::
function
<
void
()
>
func
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
m_lock
);
m_function_queue
.
push
(
func
);
// when we send the notification immediately, the consumer will try to get the lock , so unlock asap
lock
.
unlock
();
m_data_condition
.
notify_one
();
}
void
Pool
::
done
()
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
m_lock
);
m_accept_functions
=
false
;
lock
.
unlock
();
// when we send the notification immediately, the consumer will try to get the lock , so unlock asap
m_data_condition
.
notify_all
();
//notify all waiting threads.
}
void
Pool
::
infinite_loop_func
()
{
std
::
function
<
void
()
>
func
;
while
(
true
)
{
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
m_lock
);
m_data_condition
.
wait
(
lock
,
[
this
]()
{
return
!
m_function_queue
.
empty
()
||
!
m_accept_functions
;
});
if
(
!
m_accept_functions
&&
m_function_queue
.
empty
())
{
//lock will be release automatically.
//finish the thread loop and let it join in the main thread.
return
;
}
func
=
m_function_queue
.
front
();
m_function_queue
.
pop
();
//release the lock
}
func
();
}
}
\ No newline at end of file
cppsrc/Pool.h
0 → 100644
View file @
494f437
#pragma once
#include <atomic>
#include <cassert>
#include <condition_variable>
#include <functional>
#include <mutex>
#include <queue>
class
Pool
{
private
:
std
::
queue
<
std
::
function
<
void
()
>>
m_function_queue
;
std
::
mutex
m_lock
;
std
::
condition_variable
m_data_condition
;
std
::
atomic
<
bool
>
m_accept_functions
;
public
:
Pool
();
~
Pool
();
std
::
mutex
&
get_mutex_reference
(
void
);
void
push
(
std
::
function
<
void
()
>
func
);
void
done
();
void
infinite_loop_func
();
};
inline
std
::
mutex
&
Pool
::
get_mutex_reference
(
void
)
{
return
m_lock
;
}
class
quit_worker_exception
:
public
std
::
exception
{};
\ No newline at end of file
cppsrc/biominserter.cpp
View file @
494f437
...
...
@@ -8,7 +8,6 @@
#include <iostream>
#include <iterator>
#include <string>
#include <thread>
#include <vector>
#include "MOIP.h"
...
...
Please
register
or
login
to post a comment