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
00512086
Commit
00512086
authored
Sep 18, 2015
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5349 from lupustr3:pvlasov/tls_update
parents
d2b10d8a
aa485ccd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
11 deletions
+57
-11
utility.hpp
modules/core/include/opencv2/core/utility.hpp
+12
-0
system.cpp
modules/core/src/system.cpp
+45
-11
No files found.
modules/core/include/opencv2/core/utility.hpp
View file @
00512086
...
...
@@ -520,6 +520,7 @@ protected:
TLSDataContainer
();
virtual
~
TLSDataContainer
();
void
gatherData
(
std
::
vector
<
void
*>
&
data
)
const
;
#if OPENCV_ABI_COMPATIBILITY > 300
void
*
getData
()
const
;
void
release
();
...
...
@@ -546,9 +547,20 @@ public:
inline
~
TLSData
()
{
release
();
}
// Release key and delete associated data
inline
T
*
get
()
const
{
return
(
T
*
)
getData
();
}
// Get data assosiated with key
// 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
);
}
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
// Disable TLS copy operations
TLSData
(
TLSData
&
)
{};
TLSData
&
operator
=
(
const
TLSData
&
)
{
return
*
this
;};
};
/** @brief Designed for command line parsing
...
...
modules/core/src/system.cpp
View file @
00512086
...
...
@@ -1034,7 +1034,7 @@ class TlsStorage
public
:
TlsStorage
()
{
tlsSlots
=
0
;
tlsSlots
.
reserve
(
32
)
;
threads
.
reserve
(
32
);
}
~
TlsStorage
()
...
...
@@ -1077,15 +1077,27 @@ public:
size_t
reserveSlot
()
{
AutoLock
guard
(
mtxGlobalAccess
);
tlsSlots
++
;
return
(
tlsSlots
-
1
);
// Find unused slots
for
(
size_t
slot
=
0
;
slot
<
tlsSlots
.
size
();
slot
++
)
{
if
(
!
tlsSlots
[
slot
])
{
tlsSlots
[
slot
]
=
1
;
return
slot
;
}
}
// Create new slot
tlsSlots
.
push_back
(
1
);
return
(
tlsSlots
.
size
()
-
1
);
}
// Release TLS storage index and pass assosiated data to caller
void
releaseSlot
(
size_t
slotIdx
,
std
::
vector
<
void
*>
&
dataVec
)
{
AutoLock
guard
(
mtxGlobalAccess
);
CV_Assert
(
tlsSlots
>
slotIdx
);
CV_Assert
(
tlsSlots
.
size
()
>
slotIdx
);
for
(
size_t
i
=
0
;
i
<
threads
.
size
();
i
++
)
{
...
...
@@ -1096,15 +1108,14 @@ public:
threads
[
i
]
->
slots
[
slotIdx
]
=
0
;
}
}
// If we removing last element, decriment slots size to save space
if
(
tlsSlots
-
1
==
slotIdx
)
tlsSlots
--
;
tlsSlots
[
slotIdx
]
=
0
;
}
// Get data by TLS storage index
void
*
getData
(
size_t
slotIdx
)
const
{
CV_Assert
(
tlsSlots
>
slotIdx
);
CV_Assert
(
tlsSlots
.
size
()
>
slotIdx
);
ThreadData
*
threadData
=
(
ThreadData
*
)
tls
.
GetData
();
if
(
threadData
&&
threadData
->
slots
.
size
()
>
slotIdx
)
...
...
@@ -1113,10 +1124,24 @@ public:
return
NULL
;
}
// Gather data from threads by TLS storage index
void
gather
(
size_t
slotIdx
,
std
::
vector
<
void
*>
&
dataVec
)
{
AutoLock
guard
(
mtxGlobalAccess
);
CV_Assert
(
tlsSlots
.
size
()
>
slotIdx
);
for
(
size_t
i
=
0
;
i
<
threads
.
size
();
i
++
)
{
std
::
vector
<
void
*>&
thread_slots
=
threads
[
i
]
->
slots
;
if
(
thread_slots
.
size
()
>
slotIdx
&&
thread_slots
[
slotIdx
])
dataVec
.
push_back
(
thread_slots
[
slotIdx
]);
}
}
// Set data to storage index
void
setData
(
size_t
slotIdx
,
void
*
pData
)
{
CV_Assert
(
pData
!=
NULL
);
CV_Assert
(
tlsSlots
.
size
()
>
slotIdx
&&
pData
!=
NULL
);
ThreadData
*
threadData
=
(
ThreadData
*
)
tls
.
GetData
();
if
(
!
threadData
)
...
...
@@ -1131,7 +1156,11 @@ public:
}
if
(
slotIdx
>=
threadData
->
slots
.
size
())
threadData
->
slots
.
resize
(
slotIdx
+
1
);
{
AutoLock
guard
(
mtxGlobalAccess
);
while
(
slotIdx
>=
threadData
->
slots
.
size
())
threadData
->
slots
.
push_back
(
NULL
);
}
threadData
->
slots
[
slotIdx
]
=
pData
;
}
...
...
@@ -1139,7 +1168,7 @@ private:
TlsAbstraction
tls
;
// TLS abstraction layer instance
Mutex
mtxGlobalAccess
;
// Shared objects operation guard
s
ize_t
tlsSlots
;
// TLS storage counter
s
td
::
vector
<
int
>
tlsSlots
;
// TLS keys state
std
::
vector
<
ThreadData
*>
threads
;
// Array for all allocated data. Thread data pointers are placed here to allow data cleanup
};
...
...
@@ -1159,6 +1188,11 @@ TLSDataContainer::~TLSDataContainer()
CV_Assert
(
key_
==
-
1
);
// Key must be released in child object
}
void
TLSDataContainer
::
gatherData
(
std
::
vector
<
void
*>
&
data
)
const
{
getTlsStorage
().
gather
(
key_
,
data
);
}
void
TLSDataContainer
::
release
()
{
std
::
vector
<
void
*>
data
;
...
...
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