Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rlib
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
rlib
Commits
9a6d0c7b
There was an error fetching the commit references. Please try again later.
Commit
9a6d0c7b
authored
5 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
add more test, fix size() bug. TODO: add one more smart dynamic pool
parent
f14b1940
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
pool.hpp
+1
-0
1 addition, 0 deletions
pool.hpp
test/src/pool.cc
+44
-1
44 additions, 1 deletion
test/src/pool.cc
with
45 additions
and
1 deletion
pool.hpp
+
1
−
0
View file @
9a6d0c7b
...
@@ -116,6 +116,7 @@ namespace rlib {
...
@@ -116,6 +116,7 @@ namespace rlib {
typename
buffer_t
::
iterator
elem_iter
(
which
);
typename
buffer_t
::
iterator
elem_iter
(
which
);
elem_iter
.
get_extra_info
()
=
true
;
// mark as free.
elem_iter
.
get_extra_info
()
=
true
;
// mark as free.
new_obj_ready
=
true
;
new_obj_ready
=
true
;
--
curr_size
;
}
// lock released.
}
// lock released.
borrow_cv
.
notify_one
();
borrow_cv
.
notify_one
();
}
}
...
...
This diff is collapsed.
Click to expand it.
test/src/pool.cc
+
44
−
1
View file @
9a6d0c7b
...
@@ -18,11 +18,21 @@ struct pooled_obj_t {
...
@@ -18,11 +18,21 @@ struct pooled_obj_t {
string
arg2
;
string
arg2
;
};
};
struct
pooled_obj2_t
{
pooled_obj2_t
(
string
arg1
)
:
arg1
(
arg1
)
{}
pooled_obj2_t
(
const
pooled_obj2_t
&
another
)
=
delete
;
pooled_obj2_t
()
=
delete
;
string
arg1
;
};
TEST_CASE
(
"fixed object pool"
)
{
TEST_CASE
(
"fixed object pool"
)
{
size_t
pool_size
=
8
;
size_t
pool_size
=
8
;
const
auto
arg1
=
666
;
const
auto
arg1
=
666
;
const
auto
arg2
=
string
(
"fuck you"
);
const
auto
arg2
=
string
(
"fuck you"
);
rlib
::
object_pool
<
rlib
::
object_pool_policy_fixed
,
pooled_obj_t
,
int
,
string
>
rlib
::
object_pool
<
rlib
::
object_pool_policy_fixed
,
pooled_obj_t
,
decltype
(
arg1
),
decltype
(
arg2
)
>
fixed_pool
(
rlib
::
object_pool_policy_fixed
(
pool_size
),
arg1
,
arg2
);
fixed_pool
(
rlib
::
object_pool_policy_fixed
(
pool_size
),
arg1
,
arg2
);
auto
res
=
fixed_pool
.
try_borrow_one
();
auto
res
=
fixed_pool
.
try_borrow_one
();
...
@@ -49,5 +59,38 @@ TEST_CASE("fixed object pool") {
...
@@ -49,5 +59,38 @@ TEST_CASE("fixed object pool") {
objs
.
pop_front
();
objs
.
pop_front
();
}
}
}
}
REQUIRE
(
fixed_pool
.
size
()
==
1
);
}
TEST_CASE
(
"infinite dynamic object pool"
)
{
const
auto
arg1
=
string
(
"fuck you 2"
);
rlib
::
object_pool
<
rlib
::
object_pool_policy_dynamic_never_free
,
pooled_obj2_t
,
decltype
(
arg1
)
>
inf_pool
(
rlib
::
object_pool_policy_dynamic_never_free
(),
arg1
);
auto
res
=
inf_pool
.
try_borrow_one
();
REQUIRE
(
res
!=
nullptr
);
REQUIRE
(
res
->
arg1
==
arg1
);
size_t
pool_size
=
16
;
size_t
test_rounds
=
512
;
for
(
auto
_
=
0
;
_
<
test_rounds
;
++
_
)
{
std
::
list
<
decltype
(
res
)
>
objs
;
for
(
auto
cter
=
0
;
cter
<
pool_size
;
++
cter
)
{
auto
ptr
=
inf_pool
.
try_borrow_one
();
REQUIRE
(
ptr
!=
nullptr
);
REQUIRE
(
ptr
->
arg1
==
arg1
);
inf_pool
.
reconstruct_one
(
ptr
);
REQUIRE
(
ptr
->
arg1
==
arg1
);
objs
.
push_back
(
ptr
);
}
for
(
auto
cter
=
0
;
cter
<
pool_size
-
1
;
++
cter
)
{
inf_pool
.
release_one
(
*
objs
.
begin
());
objs
.
pop_front
();
}
// "Leak" one object.
}
REQUIRE
(
inf_pool
.
size
()
==
1
+
test_rounds
);
}
}
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