repositories
/
deb_x265.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Imported Upstream version 1.4+222+hg5f9f7194267b
[deb_x265.git]
/
source
/
common
/
threadpool.cpp
diff --git
a/source/common/threadpool.cpp
b/source/common/threadpool.cpp
index 8a2ab9dcc1f602f336643ff778b9b048c555fc38..d32e55f38d6977668e4c704f21874f34379c8889 100644
(file)
--- a/
source/common/threadpool.cpp
+++ b/
source/common/threadpool.cpp
@@
-1,6
+1,4
@@
/*****************************************************************************
/*****************************************************************************
- * x265: singleton thread pool and interface classes
- *****************************************************************************
* Copyright (C) 2013 x265 project
*
* Authors: Steve Borho <steve@borho.org>
* Copyright (C) 2013 x265 project
*
* Authors: Steve Borho <steve@borho.org>
@@
-87,7
+85,7
@@
private:
int m_numThreads;
int m_numSleepMapWords;
PoolThread *m_threads;
int m_numThreads;
int m_numSleepMapWords;
PoolThread *m_threads;
- volatile uint
64
_t *m_sleepMap;
+ volatile uint
32
_t *m_sleepMap;
/* Lock for write access to the provider lists. Threads are
* always allowed to read m_firstProvider and follow the
/* Lock for write access to the provider lists. Threads are
* always allowed to read m_firstProvider and follow the
@@
-174,8
+172,8
@@
void PoolThread::threadMain()
void ThreadPoolImpl::markThreadAsleep(int id)
{
void ThreadPoolImpl::markThreadAsleep(int id)
{
- int word = id >>
6
;
- uint
64_t bit = 1LL << (id & 63
);
+ int word = id >>
5
;
+ uint
32_t bit = 1 << (id & 31
);
ATOMIC_OR(&m_sleepMap[word], bit);
}
ATOMIC_OR(&m_sleepMap[word], bit);
}
@@
-186,16
+184,16
@@
void ThreadPoolImpl::pokeIdleThread()
* not give up until a thread is awakened or all of them are awake */
for (int i = 0; i < m_numSleepMapWords; i++)
{
* not give up until a thread is awakened or all of them are awake */
for (int i = 0; i < m_numSleepMapWords; i++)
{
- uint
64
_t oldval = m_sleepMap[i];
+ uint
32
_t oldval = m_sleepMap[i];
while (oldval)
{
unsigned long id;
while (oldval)
{
unsigned long id;
- CTZ
64
(id, oldval);
+ CTZ(id, oldval);
- uint
64_t newval = oldval & ~(1LL << id)
;
- if (ATOMIC_
CAS(&m_sleepMap[i], oldval, newval) == oldval
)
+ uint
32_t bit = 1 << id
;
+ if (ATOMIC_
AND(&m_sleepMap[i], ~bit) & bit
)
{
{
- m_threads[
(i << 6) |
id].poke();
+ m_threads[
i * 32 +
id].poke();
return;
}
return;
}
@@
-249,8
+247,8
@@
ThreadPoolImpl::ThreadPoolImpl(int numThreads)
, m_firstProvider(NULL)
, m_lastProvider(NULL)
{
, m_firstProvider(NULL)
, m_lastProvider(NULL)
{
- m_numSleepMapWords = (numThreads +
63) >> 6
;
- m_sleepMap = X265_MALLOC(uint
64
_t, m_numSleepMapWords);
+ m_numSleepMapWords = (numThreads +
31) >> 5
;
+ m_sleepMap = X265_MALLOC(uint
32
_t, m_numSleepMapWords);
char *buffer = (char*)X265_MALLOC(PoolThread, numThreads);
m_threads = reinterpret_cast<PoolThread*>(buffer);
char *buffer = (char*)X265_MALLOC(PoolThread, numThreads);
m_threads = reinterpret_cast<PoolThread*>(buffer);
@@
-259,9
+257,7
@@
ThreadPoolImpl::ThreadPoolImpl(int numThreads)
if (m_threads && m_sleepMap)
{
for (int i = 0; i < m_numSleepMapWords; i++)
if (m_threads && m_sleepMap)
{
for (int i = 0; i < m_numSleepMapWords; i++)
- {
m_sleepMap[i] = 0;
m_sleepMap[i] = 0;
- }
m_ok = true;
int i;
m_ok = true;
int i;
@@
-277,9
+273,7
@@
ThreadPoolImpl::ThreadPoolImpl(int numThreads)
}
if (m_ok)
}
if (m_ok)
- {
waitForAllIdle();
waitForAllIdle();
- }
else
{
// stop threads that did start up
else
{
// stop threads that did start up
@@
-300,12
+294,10
@@
void ThreadPoolImpl::waitForAllIdle()
int id = 0;
do
{
int id = 0;
do
{
- int word = id >>
6
;
- uint
64_t bit = 1LL << (id & 63
);
+ int word = id >>
5
;
+ uint
32_t bit = 1 << (id & 31
);
if (m_sleepMap[word] & bit)
if (m_sleepMap[word] & bit)
- {
id++;
id++;
- }
else
{
GIVE_UP_TIME();
else
{
GIVE_UP_TIME();
@@
-338,9
+330,7
@@
ThreadPoolImpl::~ThreadPoolImpl()
{
// cleanup thread handles
for (int i = 0; i < m_numThreads; i++)
{
// cleanup thread handles
for (int i = 0; i < m_numThreads; i++)
- {
m_threads[i].~PoolThread();
m_threads[i].~PoolThread();
- }
X265_FREE(reinterpret_cast<char*>(m_threads));
}
X265_FREE(reinterpret_cast<char*>(m_threads));
}