Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope file handles to BundleResource and BundleResourceStream life-times, resolves #309 #390

Draft
wants to merge 35 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f34df25
Implemented strategy for scoping file handle
achristoforides Sep 25, 2019
1d49256
Added comments to explain functionality of new function
achristoforides Sep 26, 2019
a8d9ec3
Cleaned up bundle ref count management
achristoforides Sep 26, 2019
4ebe4c4
Tightened up code for ref counting opened bundle resources
achristoforides Sep 26, 2019
ba9b044
Re-added constness to BundleArchives
achristoforides Sep 30, 2019
675c3d3
Added test to verify that the containers are closed properly
achristoforides Oct 1, 2019
ebbdb65
Properly terminated the added unit test
achristoforides Oct 1, 2019
37f748f
Added explicit BundleUninstall to try to fix build issues
achristoforides Oct 1, 2019
28ec100
Restructured test to not have invalid reads
achristoforides Oct 1, 2019
1dee8a8
Added code to close resource container after bundle was made
achristoforides Oct 1, 2019
268e905
Disabled OpenFileHandle tests for Mac
achristoforides Oct 3, 2019
57a4474
Defined helper function on both windows and linux instead of commenting
achristoforides Oct 3, 2019
9f157a2
CTest coverage output is made quiet
achristoforides Oct 4, 2019
868be61
Removed quiet since it breaks CI
achristoforides Oct 4, 2019
6deb489
Made changes requested by reviewer
achristoforides Oct 4, 2019
0dcf4dc
Fixed indentation
achristoforides Oct 4, 2019
b51f277
Formatted file
achristoforides Oct 4, 2019
97b0269
Uncommented first test for OpenFileHandleTest on mac
achristoforides Oct 11, 2019
b0383b4
Made changes requested by reviewer
achristoforides Oct 16, 2019
38c2233
Hopefully resolved file conflict with .travis.yml
achristoforides Oct 16, 2019
24f5493
Parallelize builds on travis
achristoforides Oct 16, 2019
5177f19
Changed -j to -j 2 so Travis doesn't run out of memory
achristoforides Oct 16, 2019
d642697
Reverted to not using mutable to see if it fixes codecov
achristoforides Oct 16, 2019
d2dc576
Added comment to fix code coverage issue
achristoforides Oct 17, 2019
b899960
Removed dead code
achristoforides Oct 17, 2019
421f232
Made changes requested by reviewer
achristoforides Oct 22, 2019
a51e7d2
Made other changes requested by reviewer
achristoforides Oct 22, 2019
8ec17d6
Made changes requested in code review
achristoforides Oct 22, 2019
cc0efa2
Added mutex to prevent data races for numOpenResources
achristoforides Oct 22, 2019
52cbfb4
Removed mutex and replaced with atmoic
achristoforides Nov 21, 2019
989c9f3
Merge branch 'development' into 309-scope-file-handle
achristoforides Nov 21, 2019
bbed7c8
Reverted back to mutex strategy
achristoforides Nov 22, 2019
7e41447
Merge branch 'development' into 309-scope-file-handle
achristoforides Aug 3, 2020
332303e
Re-added some of the code removed in the merge
achristoforides Aug 3, 2020
bd0d9fc
Fixed parameter order in BundleArchive
achristoforides Aug 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions framework/src/bundle/BundleArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const std::string BundleArchive::AUTOSTART_SETTING_ACTIVATION_POLICY =
"activation_policy";

BundleArchive::BundleArchive()
: storage(nullptr), numOpenResources(0)
: storage(nullptr)
, numOpenResources(0)
{}

BundleArchive::BundleArchive(
Expand Down Expand Up @@ -147,16 +148,16 @@ std::shared_ptr<BundleResourceContainer> BundleArchive::GetResourceContainer()
return resourceContainer;
}

void BundleArchive::RegisterOpenedResource() const
{
std::lock_guard<std::mutex> lock(numOpenResourcesLock);
numOpenResources++;
void BundleArchive::RegisterOpenedResource() const
{
uint32_t expected = 0;
while(!numOpenResources.compare_exchange_weak(expected, expected + 1));
}

void BundleArchive::UnregisterOpenedResource() const
{
std::lock_guard<std::mutex> lock(numOpenResourcesLock);
numOpenResources--;
void BundleArchive::UnregisterOpenedResource() const
{
uint32_t expected = 0;
while(!numOpenResources.compare_exchange_weak(expected, expected - 1));
if (numOpenResources == 0) {
resourceContainer->CloseContainer();
achristoforides marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
7 changes: 3 additions & 4 deletions framework/src/bundle/BundleArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#ifndef CPPMICROSERVICES_BUNDLEARCHIVE_H
#define CPPMICROSERVICES_BUNDLEARCHIVE_H

#include <atomic>
#include <chrono>
#include <memory>
#include <mutex>
#include <string>
#include <vector>

Expand Down Expand Up @@ -164,7 +164,7 @@ struct BundleArchive : std::enable_shared_from_this<BundleArchive>

/**
* Decrement the number of open resources by one.
*
*
* Note: If the number of opened resources is 0, then the ResourceContainer
* associated with this BundleArchive object is closed.
*/
Expand All @@ -175,8 +175,7 @@ struct BundleArchive : std::enable_shared_from_this<BundleArchive>
const std::unique_ptr<Data> data;
const std::shared_ptr<BundleResourceContainer> resourceContainer;
const std::string resourcePrefix;
mutable uint32_t numOpenResources;
mutable std::mutex numOpenResourcesLock;
mutable std::atomic<uint32_t> numOpenResources;
const std::string location;
};
}
Expand Down