Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
68f912e8
Kaydet (Commit)
68f912e8
authored
Eki 31, 2014
tarafından
Michael Meeks
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
thread-pool: fix waiting until all tasks are complete.
Change-Id: Iaf5a3bf28879f229a223a8760fd878f96958a53c
üst
fc9e78f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
9 deletions
+41
-9
threadpool.cxx
comphelper/source/misc/threadpool.cxx
+34
-6
threadpool.hxx
include/comphelper/threadpool.hxx
+7
-3
No files found.
comphelper/source/misc/threadpool.cxx
Dosyayı görüntüle @
68f912e8
...
...
@@ -20,10 +20,15 @@ class ThreadPool::ThreadWorker : public salhelper::Thread
{
ThreadPool
*
mpPool
;
osl
::
Condition
maNewWork
;
bool
mbWorking
;
public
:
ThreadWorker
(
ThreadPool
*
pPool
)
:
salhelper
::
Thread
(
"thread-pool"
),
mpPool
(
pPool
)
{}
mpPool
(
pPool
),
mbWorking
(
false
)
{
}
virtual
void
execute
()
SAL_OVERRIDE
{
...
...
@@ -45,6 +50,9 @@ public:
while
(
!
pRet
)
{
if
(
mbWorking
)
mpPool
->
stopWork
();
mbWorking
=
false
;
maNewWork
.
reset
();
if
(
mpPool
->
mbTerminate
)
...
...
@@ -59,6 +67,13 @@ public:
pRet
=
mpPool
->
popWork
();
}
if
(
pRet
)
{
if
(
!
mbWorking
)
mpPool
->
startWork
();
mbWorking
=
true
;
}
return
pRet
;
}
...
...
@@ -78,12 +93,13 @@ public:
};
ThreadPool
::
ThreadPool
(
sal_Int32
nWorkers
)
:
mnThreadsWorking
(
0
),
mbTerminate
(
false
)
{
for
(
sal_Int32
i
=
0
;
i
<
nWorkers
;
i
++
)
maWorkers
.
push_back
(
new
ThreadWorker
(
this
)
);
maTasks
Empty
.
reset
();
maTasks
Complete
.
reset
();
osl
::
MutexGuard
aGuard
(
maGuard
);
for
(
size_t
i
=
0
;
i
<
maWorkers
.
size
();
i
++
)
...
...
@@ -136,10 +152,11 @@ void ThreadPool::pushTask( ThreadTask *pTask )
{
osl
::
MutexGuard
aGuard
(
maGuard
);
maTasks
.
insert
(
maTasks
.
begin
(),
pTask
);
// horrible beyond belief:
for
(
size_t
i
=
0
;
i
<
maWorkers
.
size
();
i
++
)
maWorkers
[
i
]
->
signalNewWork
();
maTasks
Empty
.
reset
();
maTasks
Complete
.
reset
();
}
ThreadTask
*
ThreadPool
::
popWork
()
...
...
@@ -151,8 +168,19 @@ ThreadTask *ThreadPool::popWork()
return
pTask
;
}
else
maTasksEmpty
.
set
();
return
NULL
;
return
NULL
;
}
void
ThreadPool
::
startWork
()
{
mnThreadsWorking
++
;
}
void
ThreadPool
::
stopWork
()
{
assert
(
mnThreadsWorking
>
0
);
if
(
--
mnThreadsWorking
==
0
)
maTasksComplete
.
set
();
}
void
ThreadPool
::
waitUntilEmpty
()
...
...
@@ -171,7 +199,7 @@ void ThreadPool::waitUntilEmpty()
else
{
aGuard
.
clear
();
maTasks
Empty
.
wait
();
maTasks
Complete
.
wait
();
aGuard
.
reset
();
}
assert
(
maTasks
.
empty
()
);
...
...
include/comphelper/threadpool.hxx
Dosyayı görüntüle @
68f912e8
...
...
@@ -54,10 +54,14 @@ private:
ThreadTask
*
waitForWork
(
osl
::
Condition
&
rNewWork
);
ThreadTask
*
popWork
();
void
startWork
();
void
stopWork
();
osl
::
Mutex
maGuard
;
osl
::
Condition
maTasksEmpty
;
bool
mbTerminate
;
osl
::
Mutex
maGuard
;
sal_Int32
mnThreadsWorking
;
/// signalled when all in-progress tasks are complete
osl
::
Condition
maTasksComplete
;
bool
mbTerminate
;
std
::
vector
<
rtl
::
Reference
<
ThreadWorker
>
>
maWorkers
;
std
::
vector
<
ThreadTask
*
>
maTasks
;
};
...
...
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