Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review 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
mantidproject
mantid
Commits
39f32529
Commit
39f32529
authored
9 years ago
by
Anton Piccardo-Selg
Browse files
Options
Downloads
Patches
Plain Diff
Refs #15288 Add mutex to DiskBuffer
parent
84b7a4c0
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Framework/Kernel/src/DiskBuffer.cpp
+10
-17
10 additions, 17 deletions
Framework/Kernel/src/DiskBuffer.cpp
Framework/Kernel/test/DiskBufferTest.h
+1
-2
1 addition, 2 deletions
Framework/Kernel/test/DiskBufferTest.h
with
11 additions
and
19 deletions
Framework/Kernel/src/DiskBuffer.cpp
+
10
−
17
View file @
39f32529
...
@@ -52,19 +52,18 @@ void DiskBuffer::toWrite(ISaveable *item) {
...
@@ -52,19 +52,18 @@ void DiskBuffer::toWrite(ISaveable *item) {
// its size in memory
// its size in memory
{
{
// forget old memory size
// forget old memory size
m_mutex
.
lock
(
);
Kernel
::
UniqueLockMutex
uniqueLock
(
m_mutex
);
m_writeBufferUsed
-=
item
->
getBufferSize
();
m_writeBufferUsed
-=
item
->
getBufferSize
();
// add new size
// add new size
size_t
newMemorySize
=
item
->
getDataMemorySize
();
size_t
newMemorySize
=
item
->
getDataMemorySize
();
m_writeBufferUsed
+=
newMemorySize
;
m_writeBufferUsed
+=
newMemorySize
;
m_mutex
.
unlock
();
uniqueLock
.
unlock
();
item
->
setBufferSize
(
newMemorySize
);
item
->
setBufferSize
(
newMemorySize
);
}
else
{
}
else
{
m_m
utex
.
lock
();
Kernel
::
LockGuardM
utex
lock
(
m_mutex
);
m_toWriteBuffer
.
push_front
(
item
);
m_toWriteBuffer
.
push_front
(
item
);
m_writeBufferUsed
+=
item
->
setBufferPosition
(
m_toWriteBuffer
.
begin
());
m_writeBufferUsed
+=
item
->
setBufferPosition
(
m_toWriteBuffer
.
begin
());
m_nObjectsToWrite
++
;
m_nObjectsToWrite
++
;
m_mutex
.
unlock
();
}
}
// Should we now write out the old data?
// Should we now write out the old data?
...
@@ -84,19 +83,18 @@ void DiskBuffer::objectDeleted(ISaveable *item) {
...
@@ -84,19 +83,18 @@ void DiskBuffer::objectDeleted(ISaveable *item) {
if
(
item
==
nullptr
)
if
(
item
==
nullptr
)
return
;
return
;
// have it ever been in the buffer?
// have it ever been in the buffer?
m_mutex
.
lock
(
);
Kernel
::
UniqueLockMutex
uniqueLock
(
m_mutex
);
auto
opt2it
=
item
->
getBufPostion
();
auto
opt2it
=
item
->
getBufPostion
();
if
(
opt2it
)
{
if
(
opt2it
)
{
m_writeBufferUsed
-=
item
->
getBufferSize
();
m_writeBufferUsed
-=
item
->
getBufferSize
();
m_toWriteBuffer
.
erase
(
*
opt2it
);
m_toWriteBuffer
.
erase
(
*
opt2it
);
}
else
{
}
else
{
m_mutex
.
unlock
();
return
;
return
;
}
}
// indicate to the object that it is not stored in memory any more
// indicate to the object that it is not stored in memory any more
item
->
clearBufferState
();
item
->
clearBufferState
();
m_mutex
.
unlock
();
uniqueLock
.
unlock
();
// Mark the amount of space used on disk as free
// Mark the amount of space used on disk as free
if
(
item
->
wasSaved
())
if
(
item
->
wasSaved
())
...
@@ -109,7 +107,7 @@ void DiskBuffer::objectDeleted(ISaveable *item) {
...
@@ -109,7 +107,7 @@ void DiskBuffer::objectDeleted(ISaveable *item) {
*/
*/
void
DiskBuffer
::
writeOldObjects
()
{
void
DiskBuffer
::
writeOldObjects
()
{
Poco
::
ScopedLock
<
Kernel
::
Mutex
>
_lock
(
m_mutex
);
Kernel
::
LockGuard
Mutex
_lock
(
m_mutex
);
// Holder for any objects that you were NOT able to write.
// Holder for any objects that you were NOT able to write.
std
::
list
<
ISaveable
*>
couldNotWrite
;
std
::
list
<
ISaveable
*>
couldNotWrite
;
size_t
objectsNotWritten
(
0
);
size_t
objectsNotWritten
(
0
);
...
@@ -208,7 +206,7 @@ void DiskBuffer::flushCache() {
...
@@ -208,7 +206,7 @@ void DiskBuffer::flushCache() {
void
DiskBuffer
::
freeBlock
(
uint64_t
const
pos
,
uint64_t
const
size
)
{
void
DiskBuffer
::
freeBlock
(
uint64_t
const
pos
,
uint64_t
const
size
)
{
if
(
size
==
0
||
size
==
std
::
numeric_limits
<
uint64_t
>::
max
())
if
(
size
==
0
||
size
==
std
::
numeric_limits
<
uint64_t
>::
max
())
return
;
return
;
m_free
Mutex
.
lock
();
Kernel
::
LockGuard
Mutex
lock
(
m_freeMutex
);
// Make the block
// Make the block
FreeBlock
newBlock
(
pos
,
size
);
FreeBlock
newBlock
(
pos
,
size
);
...
@@ -219,7 +217,6 @@ void DiskBuffer::freeBlock(uint64_t const pos, uint64_t const size) {
...
@@ -219,7 +217,6 @@ void DiskBuffer::freeBlock(uint64_t const pos, uint64_t const size) {
// Or, if the map has only 1 item then it cannot do any merging. This solves a
// Or, if the map has only 1 item then it cannot do any merging. This solves a
// hanging bug in MacOS. Refs #3652
// hanging bug in MacOS. Refs #3652
if
(
!
p
.
second
||
m_free
.
size
()
<=
1
)
{
if
(
!
p
.
second
||
m_free
.
size
()
<=
1
)
{
m_freeMutex
.
unlock
();
return
;
return
;
}
}
...
@@ -254,8 +251,6 @@ void DiskBuffer::freeBlock(uint64_t const pos, uint64_t const size) {
...
@@ -254,8 +251,6 @@ void DiskBuffer::freeBlock(uint64_t const pos, uint64_t const size) {
m_free
.
erase
(
it_after
);
m_free
.
erase
(
it_after
);
}
}
}
}
m_freeMutex
.
unlock
();
}
}
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
...
@@ -264,7 +259,7 @@ void DiskBuffer::freeBlock(uint64_t const pos, uint64_t const size) {
...
@@ -264,7 +259,7 @@ void DiskBuffer::freeBlock(uint64_t const pos, uint64_t const size) {
* automatically defrags neighboring blocks.
* automatically defrags neighboring blocks.
*/
*/
void
DiskBuffer
::
defragFreeBlocks
()
{
void
DiskBuffer
::
defragFreeBlocks
()
{
m_free
Mutex
.
lock
();
Kernel
::
LockGuard
Mutex
lock
(
m_freeMutex
);
freeSpace_t
::
iterator
it
=
m_free
.
begin
();
freeSpace_t
::
iterator
it
=
m_free
.
begin
();
FreeBlock
thisBlock
;
FreeBlock
thisBlock
;
...
@@ -289,7 +284,6 @@ void DiskBuffer::defragFreeBlocks() {
...
@@ -289,7 +284,6 @@ void DiskBuffer::defragFreeBlocks() {
thisBlock
=
*
it
;
thisBlock
=
*
it
;
}
}
}
}
m_freeMutex
.
unlock
();
}
}
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
...
@@ -300,7 +294,7 @@ void DiskBuffer::defragFreeBlocks() {
...
@@ -300,7 +294,7 @@ void DiskBuffer::defragFreeBlocks() {
* @return a new position at which the data can be saved.
* @return a new position at which the data can be saved.
*/
*/
uint64_t
DiskBuffer
::
allocate
(
uint64_t
const
newSize
)
{
uint64_t
DiskBuffer
::
allocate
(
uint64_t
const
newSize
)
{
m_freeMutex
.
lock
(
);
Kernel
::
UniqueLockMutex
uniqueLock
(
m_freeMutex
);
// Now, find the first available block of sufficient size.
// Now, find the first available block of sufficient size.
freeSpace_bySize_t
::
iterator
it
;
freeSpace_bySize_t
::
iterator
it
;
...
@@ -318,7 +312,6 @@ uint64_t DiskBuffer::allocate(uint64_t const newSize) {
...
@@ -318,7 +312,6 @@ uint64_t DiskBuffer::allocate(uint64_t const newSize) {
// And we assume the file will grow by this much.
// And we assume the file will grow by this much.
m_fileLength
+=
newSize
;
m_fileLength
+=
newSize
;
// Will place the new block at the end of the file
// Will place the new block at the end of the file
m_freeMutex
.
unlock
();
return
retVal
;
return
retVal
;
}
else
{
}
else
{
// std::cout << "Block found for allocate " << newSize << std::endl;
// std::cout << "Block found for allocate " << newSize << std::endl;
...
@@ -326,7 +319,7 @@ uint64_t DiskBuffer::allocate(uint64_t const newSize) {
...
@@ -326,7 +319,7 @@ uint64_t DiskBuffer::allocate(uint64_t const newSize) {
uint64_t
foundSize
=
it
->
getSize
();
uint64_t
foundSize
=
it
->
getSize
();
// Remove the free block you found - it is no longer free
// Remove the free block you found - it is no longer free
m_free_bySize
.
erase
(
it
);
m_free_bySize
.
erase
(
it
);
m_freeMutex
.
unlock
();
uniqueLock
.
unlock
();
// Block was too large - free the bit of space after it.
// Block was too large - free the bit of space after it.
if
(
foundSize
>
newSize
)
{
if
(
foundSize
>
newSize
)
{
this
->
freeBlock
(
foundPos
+
newSize
,
foundSize
-
newSize
);
this
->
freeBlock
(
foundPos
+
newSize
,
foundSize
-
newSize
);
...
...
This diff is collapsed.
Click to expand it.
Framework/Kernel/test/DiskBufferTest.h
+
1
−
2
View file @
39f32529
...
@@ -736,7 +736,7 @@ public:
...
@@ -736,7 +736,7 @@ public:
/// Fake a seek followed by a write
/// Fake a seek followed by a write
static
void
fakeSeekAndWrite
(
uint64_t
newPos
)
{
static
void
fakeSeekAndWrite
(
uint64_t
newPos
)
{
stream
Mutex
.
lock
();
Kernel
::
LockGuard
Mutex
lock
(
streamMutex
);
int64_t
seek
=
int64_t
(
filePos
)
-
int64_t
(
newPos
);
int64_t
seek
=
int64_t
(
filePos
)
-
int64_t
(
newPos
);
if
(
seek
<
0
)
if
(
seek
<
0
)
seek
=
-
seek
;
seek
=
-
seek
;
...
@@ -748,7 +748,6 @@ public:
...
@@ -748,7 +748,6 @@ public:
while
(
tim
.
elapsed_no_reset
()
<
seekTime
)
{
/*Wait*/
while
(
tim
.
elapsed_no_reset
()
<
seekTime
)
{
/*Wait*/
}
}
filePos
=
newPos
;
filePos
=
newPos
;
streamMutex
.
unlock
();
}
}
virtual
void
load
()
{
virtual
void
load
()
{
if
(
this
->
wasSaved
()
&&
!
this
->
isLoaded
())
{
if
(
this
->
wasSaved
()
&&
!
this
->
isLoaded
())
{
...
...
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