Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
ec7f74f7
Commit
ec7f74f7
authored
8 years ago
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core(TLS): add cleanup() method
parent
526220a1
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
utility.hpp
modules/core/include/opencv2/core/utility.hpp
+6
-1
system.cpp
modules/core/src/system.cpp
+14
-4
No files found.
modules/core/include/opencv2/core/utility.hpp
View file @
ec7f74f7
...
...
@@ -627,6 +627,9 @@ public:
virtual
void
deleteDataInstance
(
void
*
pData
)
const
=
0
;
int
key_
;
public
:
void
cleanup
();
//! Release created TLS data container objects. It is similar to release() call, but it keeps TLS container valid.
};
// Main TLS data class
...
...
@@ -638,13 +641,15 @@ public:
inline
~
TLSData
()
{
release
();
}
// Release key and delete associated data
inline
T
*
get
()
const
{
return
(
T
*
)
getData
();
}
// Get data associated with key
// Get data from all threads
// Get data from all threads
inline
void
gather
(
std
::
vector
<
T
*>
&
data
)
const
{
std
::
vector
<
void
*>
&
dataVoid
=
reinterpret_cast
<
std
::
vector
<
void
*>&>
(
data
);
gatherData
(
dataVoid
);
}
inline
void
cleanup
()
{
TLSDataContainer
::
cleanup
();
}
private
:
virtual
void
*
createDataInstance
()
const
{
return
new
T
;}
// Wrapper to allocate data by template
virtual
void
deleteDataInstance
(
void
*
pData
)
const
{
delete
(
T
*
)
pData
;}
// Wrapper to release data by template
...
...
This diff is collapsed.
Click to expand it.
modules/core/src/system.cpp
View file @
ec7f74f7
...
...
@@ -1086,7 +1086,7 @@ public:
}
// Release TLS storage index and pass associated data to caller
void
releaseSlot
(
size_t
slotIdx
,
std
::
vector
<
void
*>
&
dataVec
)
void
releaseSlot
(
size_t
slotIdx
,
std
::
vector
<
void
*>
&
dataVec
,
bool
keepSlot
=
false
)
{
AutoLock
guard
(
mtxGlobalAccess
);
CV_Assert
(
tlsSlots
.
size
()
>
slotIdx
);
...
...
@@ -1099,12 +1099,13 @@ public:
if
(
thread_slots
.
size
()
>
slotIdx
&&
thread_slots
[
slotIdx
])
{
dataVec
.
push_back
(
thread_slots
[
slotIdx
]);
thread
s
[
i
]
->
slots
[
slotIdx
]
=
0
;
thread
_slots
[
slotIdx
]
=
NULL
;
}
}
}
tlsSlots
[
slotIdx
]
=
0
;
if
(
!
keepSlot
)
tlsSlots
[
slotIdx
]
=
0
;
}
// Get data by TLS storage index
...
...
@@ -1196,9 +1197,18 @@ void TLSDataContainer::release()
std
::
vector
<
void
*>
data
;
data
.
reserve
(
32
);
getTlsStorage
().
releaseSlot
(
key_
,
data
);
// Release key and get stored data for proper destruction
key_
=
-
1
;
for
(
size_t
i
=
0
;
i
<
data
.
size
();
i
++
)
// Delete all associated data
deleteDataInstance
(
data
[
i
]);
}
void
TLSDataContainer
::
cleanup
()
{
std
::
vector
<
void
*>
data
;
data
.
reserve
(
32
);
getTlsStorage
().
releaseSlot
(
key_
,
data
,
true
);
// Extract stored data with removal from TLS tables
for
(
size_t
i
=
0
;
i
<
data
.
size
();
i
++
)
// Delete all associated data
deleteDataInstance
(
data
[
i
]);
key_
=
-
1
;
}
void
*
TLSDataContainer
::
getData
()
const
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment