Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
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
Harbor 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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
63401691
Commit
63401691
authored
12 years ago
by
Eric Cano
Browse files
Options
Downloads
Patches
Plain Diff
Fixed lock leaks by using stack based automatic release (RAII).
parent
b84dde36
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
castor/common/CastorConfiguration.cpp
+6
-11
6 additions, 11 deletions
castor/common/CastorConfiguration.cpp
castor/common/CastorConfiguration.hpp
+22
-0
22 additions, 0 deletions
castor/common/CastorConfiguration.hpp
with
28 additions
and
11 deletions
castor/common/CastorConfiguration.cpp
+
6
−
11
View file @
63401691
...
...
@@ -77,8 +77,8 @@ castor::common::CastorConfiguration::getConfEnt(const std::string &category,
throw
(
castor
::
exception
::
Exception
)
{
// check whether we need to reload the configuration
checkAndRenewConfig
();
// get read lock
pthread_rwlock_rdlock
(
&
m_lock
);
// get read lock
. No need to be fancy, just let it auto-release on exit.
smartReadLockTaker
srl
(
&
m_lock
);
// get the category
Configuration
::
const_iterator
catIt
=
find
(
category
);
if
(
end
()
==
catIt
)
{
...
...
@@ -91,9 +91,6 @@ castor::common::CastorConfiguration::getConfEnt(const std::string &category,
castor
::
exception
::
NoEntry
e
;
throw
e
;
}
// release read lock
pthread_rwlock_unlock
(
&
m_lock
);
// return
return
entIt
->
second
;
}
...
...
@@ -118,19 +115,17 @@ void castor::common::CastorConfiguration::checkAndRenewConfig()
// no need to renew
return
;
}
// we should probably renew. First take the write lock
pthread_rwlock_wrlock
(
&
m_lock
);
// we should probably renew. First take the write lock.
// No need to be fancy, just let it auto-release on exit.
smartWriteLockTaker
swl
(
&
m_lock
);
// now check that we should really renew, because someone may have done it
// while we waited for the lock
if
(
currentTime
<
m_lastUpdateTime
+
timeout
)
{
// indeed, someone renew it for us, so give up
pthread_rwlock_unlock
(
&
m_lock
);
return
;
return
;
}
// now we should really renew
renewConfig
();
// release the write lock
pthread_rwlock_unlock
(
&
m_lock
);
}
//------------------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
castor/common/CastorConfiguration.hpp
+
22
−
0
View file @
63401691
...
...
@@ -115,6 +115,28 @@ namespace castor {
*/
time_t
m_lastUpdateTime
;
/**
* Scoped lock allowing safe lock release in all execution pathes
*/
class
smartLockTaker
{
protected:
smartLockTaker
(
pthread_rwlock_t
*
lk
)
:
m_reld
(
false
),
m_lock
(
lk
)
{};
bool
m_reld
;
pthread_rwlock_t
*
m_lock
;
public
:
void
release
()
{
if
(
!
m_reld
)
pthread_rwlock_unlock
(
m_lock
);
m_reld
=
true
;
}
~
smartLockTaker
()
{
release
();
}
};
class
smartReadLockTaker
:
public
smartLockTaker
{
public:
smartReadLockTaker
(
pthread_rwlock_t
*
lk
)
:
smartLockTaker
(
lk
)
{
pthread_rwlock_rdlock
(
m_lock
);
}
};
class
smartWriteLockTaker
:
public
smartLockTaker
{
public:
smartWriteLockTaker
(
pthread_rwlock_t
*
lk
)
:
smartLockTaker
(
lk
)
{
pthread_rwlock_wrlock
(
m_lock
);
}
};
/**
* lock to garantee safe access to the configuration
*/
...
...
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