Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
emper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Fischer
emper
Commits
08bbef86
Commit
08bbef86
authored
3 years ago
by
Florian Fischer
Browse files
Options
Downloads
Patches
Plain Diff
[fsearch] add global semaphore to limit the amount of concurrent requests
parent
11aa4a38
No related branches found
No related tags found
No related merge requests found
Pipeline
#65970
passed
3 years ago
Stage: smoke-test
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/fsearch/fsearch.cpp
+18
-2
18 additions, 2 deletions
apps/fsearch/fsearch.cpp
emper/Semaphore.hpp
+3
-0
3 additions, 0 deletions
emper/Semaphore.hpp
with
21 additions
and
2 deletions
apps/fsearch/fsearch.cpp
+
18
−
2
View file @
08bbef86
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#include
"CountingPrivateSemaphore.hpp"
#include
"CountingPrivateSemaphore.hpp"
#include
"Fiber.hpp"
#include
"Fiber.hpp"
#include
"Runtime.hpp"
#include
"Runtime.hpp"
#include
"Semaphore.hpp"
#include
"emper.hpp"
#include
"emper.hpp"
#include
"io.hpp"
#include
"io.hpp"
...
@@ -25,7 +26,13 @@ namespace fs = std::filesystem;
...
@@ -25,7 +26,13 @@ namespace fs = std::filesystem;
const
char
*
needle
;
const
char
*
needle
;
size_t
needle_len
;
size_t
needle_len
;
emper
::
Semaphore
*
max_running
;
void
search
(
const
std
::
string
&
path
)
{
void
search
(
const
std
::
string
&
path
)
{
if
(
max_running
)
{
max_running
->
acquire
();
}
int
fd
=
emper
::
io
::
openAndWait
(
path
.
c_str
(),
O_RDONLY
);
int
fd
=
emper
::
io
::
openAndWait
(
path
.
c_str
(),
O_RDONLY
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
DIE_MSG_ERRNO
(
"open failed"
);
DIE_MSG_ERRNO
(
"open failed"
);
...
@@ -50,6 +57,10 @@ void search(const std::string& path) {
...
@@ -50,6 +57,10 @@ void search(const std::string& path) {
}
}
out
:
out
:
if
(
max_running
)
{
max_running
->
release
();
}
emper
::
io
::
closeAndForget
(
fd
);
emper
::
io
::
closeAndForget
(
fd
);
}
}
...
@@ -67,8 +78,12 @@ void walk_dir() {
...
@@ -67,8 +78,12 @@ void walk_dir() {
auto
main
(
int
argc
,
char
*
argv
[])
->
int
{
auto
main
(
int
argc
,
char
*
argv
[])
->
int
{
if
(
argc
<
2
)
{
if
(
argc
<
2
)
{
std
::
cerr
<<
"Usage: "
<<
argv
[
0
]
<<
" <needle>"
<<
std
::
endl
;
std
::
cerr
<<
"Usage: "
<<
argv
[
0
]
<<
" <needle> [max fibers]"
<<
std
::
endl
;
return
EXIT_FAILURE
;
return
EXIT_SUCCESS
;
}
if
(
argc
==
3
)
{
max_running
=
new
emper
::
Semaphore
(
std
::
stoi
(
argv
[
2
]));
}
}
needle
=
argv
[
1
];
needle
=
argv
[
1
];
...
@@ -80,4 +95,5 @@ auto main(int argc, char* argv[]) -> int {
...
@@ -80,4 +95,5 @@ auto main(int argc, char* argv[]) -> int {
runtime
.
scheduleFromAnywhere
(
*
dirWalker
);
runtime
.
scheduleFromAnywhere
(
*
dirWalker
);
runtime
.
waitUntilFinished
();
runtime
.
waitUntilFinished
();
return
EXIT_SUCCESS
;
}
}
This diff is collapsed.
Click to expand it.
emper/Semaphore.hpp
+
3
−
0
View file @
08bbef86
...
@@ -17,6 +17,9 @@ class Semaphore {
...
@@ -17,6 +17,9 @@ class Semaphore {
std
::
mutex
mutex
;
std
::
mutex
mutex
;
public:
public:
Semaphore
()
=
default
;
Semaphore
(
unsigned
int
count
)
:
count
(
count
){};
auto
acquire
()
->
bool
{
auto
acquire
()
->
bool
{
bool
blocked
;
bool
blocked
;
mutex
.
lock
();
mutex
.
lock
();
...
...
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