- Revision
- 219760
- Author
- [email protected]
- Date
- 2017-07-22 00:27:00 -0700 (Sat, 22 Jul 2017)
Log Message
[WTF] Extend ThreadGroup::add results from bool to ThreadGroupAddResult
https://bugs.webkit.org/show_bug.cgi?id=174705
Reviewed by Mark Lam.
Source/WTF:
After starting using ThreadGroup to bookkeep active threads for Signals,
we would like to know tristate of ThreadGroup::add result, NewlyAdded, AlreadyAdded, NotAdded.
This patch extends the result of ThreadGroup::add from bool to ThreadGroupAddResult tristate.
Note that NotAdded is returned if the target thread is dying.
* wtf/ThreadGroup.cpp:
(WTF::ThreadGroup::add):
(WTF::ThreadGroup::addCurrentThread):
* wtf/ThreadGroup.h:
* wtf/Threading.cpp:
(WTF::Thread::addToThreadGroup):
* wtf/Threading.h:
* wtf/threads/Signals.cpp:
(WTF::registerThreadForMachExceptionHandling):
Tools:
* TestWebKitAPI/Tests/WTF/ThreadGroup.cpp:
(TestWebKitAPI::testThreadGroup):
(TestWebKitAPI::TEST):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (219759 => 219760)
--- trunk/Source/WTF/ChangeLog 2017-07-22 05:14:15 UTC (rev 219759)
+++ trunk/Source/WTF/ChangeLog 2017-07-22 07:27:00 UTC (rev 219760)
@@ -1,3 +1,25 @@
+2017-07-22 Yusuke Suzuki <[email protected]>
+
+ [WTF] Extend ThreadGroup::add results from bool to ThreadGroupAddResult
+ https://bugs.webkit.org/show_bug.cgi?id=174705
+
+ Reviewed by Mark Lam.
+
+ After starting using ThreadGroup to bookkeep active threads for Signals,
+ we would like to know tristate of ThreadGroup::add result, NewlyAdded, AlreadyAdded, NotAdded.
+ This patch extends the result of ThreadGroup::add from bool to ThreadGroupAddResult tristate.
+ Note that NotAdded is returned if the target thread is dying.
+
+ * wtf/ThreadGroup.cpp:
+ (WTF::ThreadGroup::add):
+ (WTF::ThreadGroup::addCurrentThread):
+ * wtf/ThreadGroup.h:
+ * wtf/Threading.cpp:
+ (WTF::Thread::addToThreadGroup):
+ * wtf/Threading.h:
+ * wtf/threads/Signals.cpp:
+ (WTF::registerThreadForMachExceptionHandling):
+
2017-07-21 Commit Queue <[email protected]>
Unreviewed, rolling out r219732.
Modified: trunk/Source/WTF/wtf/ThreadGroup.cpp (219759 => 219760)
--- trunk/Source/WTF/wtf/ThreadGroup.cpp 2017-07-22 05:14:15 UTC (rev 219759)
+++ trunk/Source/WTF/wtf/ThreadGroup.cpp 2017-07-22 07:27:00 UTC (rev 219760)
@@ -37,21 +37,22 @@
thread->removeFromThreadGroup(locker, *this);
}
-bool ThreadGroup::add(const AbstractLocker& locker, Thread& thread)
+ThreadGroupAddResult ThreadGroup::add(const AbstractLocker& locker, Thread& thread)
{
return thread.addToThreadGroup(locker, *this);
}
-bool ThreadGroup::add(Thread& thread)
+ThreadGroupAddResult ThreadGroup::add(Thread& thread)
{
auto locker = holdLock(m_lock);
return add(locker, thread);
}
-void ThreadGroup::addCurrentThread()
+ThreadGroupAddResult ThreadGroup::addCurrentThread()
{
- bool isAdded = add(Thread::current());
- ASSERT_UNUSED(isAdded, isAdded);
+ auto result = add(Thread::current());
+ ASSERT(result != ThreadGroupAddResult::NotAdded);
+ return result;
}
} // namespace WTF
Modified: trunk/Source/WTF/wtf/ThreadGroup.h (219759 => 219760)
--- trunk/Source/WTF/wtf/ThreadGroup.h 2017-07-22 05:14:15 UTC (rev 219759)
+++ trunk/Source/WTF/wtf/ThreadGroup.h 2017-07-22 07:27:00 UTC (rev 219760)
@@ -32,6 +32,8 @@
namespace WTF {
+enum class ThreadGroupAddResult { NewlyAdded, AlreadyAdded, NotAdded };
+
class ThreadGroup : public std::enable_shared_from_this<ThreadGroup> {
public:
friend class Thread;
@@ -41,9 +43,9 @@
return std::make_shared<ThreadGroup>();
}
- WTF_EXPORT_PRIVATE bool add(Thread&);
- WTF_EXPORT_PRIVATE bool add(const AbstractLocker&, Thread&);
- WTF_EXPORT_PRIVATE void addCurrentThread();
+ WTF_EXPORT_PRIVATE ThreadGroupAddResult add(Thread&);
+ WTF_EXPORT_PRIVATE ThreadGroupAddResult add(const AbstractLocker&, Thread&);
+ WTF_EXPORT_PRIVATE ThreadGroupAddResult addCurrentThread();
const ListHashSet<Ref<Thread>>& threads(const AbstractLocker&) const { return m_threads; }
@@ -67,3 +69,4 @@
}
using WTF::ThreadGroup;
+using WTF::ThreadGroupAddResult;
Modified: trunk/Source/WTF/wtf/Threading.cpp (219759 => 219760)
--- trunk/Source/WTF/wtf/Threading.cpp 2017-07-22 05:14:15 UTC (rev 219759)
+++ trunk/Source/WTF/wtf/Threading.cpp 2017-07-22 07:27:00 UTC (rev 219760)
@@ -173,15 +173,17 @@
m_didExit = true;
}
-bool Thread::addToThreadGroup(const AbstractLocker& threadGroupLocker, ThreadGroup& threadGroup)
+ThreadGroupAddResult Thread::addToThreadGroup(const AbstractLocker& threadGroupLocker, ThreadGroup& threadGroup)
{
UNUSED_PARAM(threadGroupLocker);
std::lock_guard<std::mutex> locker(m_mutex);
if (m_isShuttingDown)
- return false;
- if (threadGroup.m_threads.add(*this).isNewEntry)
+ return ThreadGroupAddResult::NotAdded;
+ if (threadGroup.m_threads.add(*this).isNewEntry) {
m_threadGroups.append(threadGroup.weakFromThis());
- return true;
+ return ThreadGroupAddResult::NewlyAdded;
+ }
+ return ThreadGroupAddResult::AlreadyAdded;
}
void Thread::removeFromThreadGroup(const AbstractLocker& threadGroupLocker, ThreadGroup& threadGroup)
Modified: trunk/Source/WTF/wtf/Threading.h (219759 => 219760)
--- trunk/Source/WTF/wtf/Threading.h 2017-07-22 05:14:15 UTC (rev 219759)
+++ trunk/Source/WTF/wtf/Threading.h 2017-07-22 07:27:00 UTC (rev 219760)
@@ -52,6 +52,8 @@
class AbstractLocker;
class ThreadMessageData;
+enum class ThreadGroupAddResult;
+
using ThreadIdentifier = uint32_t;
typedef void (*ThreadFunction)(void* argument);
@@ -182,7 +184,7 @@
bool hasExited() { return m_didExit; }
// These functions are only called from ThreadGroup.
- bool addToThreadGroup(const AbstractLocker& threadGroupLocker, ThreadGroup&);
+ ThreadGroupAddResult addToThreadGroup(const AbstractLocker& threadGroupLocker, ThreadGroup&);
void removeFromThreadGroup(const AbstractLocker& threadGroupLocker, ThreadGroup&);
// WordLock & Lock rely on ThreadSpecific. But Thread object can be destroyed even after ThreadSpecific things are destroyed.
Modified: trunk/Source/WTF/wtf/threads/Signals.cpp (219759 => 219760)
--- trunk/Source/WTF/wtf/threads/Signals.cpp 2017-07-22 05:14:15 UTC (rev 219759)
+++ trunk/Source/WTF/wtf/threads/Signals.cpp 2017-07-22 07:27:00 UTC (rev 219760)
@@ -236,7 +236,7 @@
void registerThreadForMachExceptionHandling(Thread& thread)
{
auto locker = holdLock(activeThreads().getLock());
- if (activeThreads().add(locker, thread))
+ if (activeThreads().add(locker, thread) == ThreadGroupAddResult::NewlyAdded)
setExceptionPorts(locker, thread);
}
Modified: trunk/Tools/ChangeLog (219759 => 219760)
--- trunk/Tools/ChangeLog 2017-07-22 05:14:15 UTC (rev 219759)
+++ trunk/Tools/ChangeLog 2017-07-22 07:27:00 UTC (rev 219760)
@@ -1,3 +1,14 @@
+2017-07-22 Yusuke Suzuki <[email protected]>
+
+ [WTF] Extend ThreadGroup::add results from bool to ThreadGroupAddResult
+ https://bugs.webkit.org/show_bug.cgi?id=174705
+
+ Reviewed by Mark Lam.
+
+ * TestWebKitAPI/Tests/WTF/ThreadGroup.cpp:
+ (TestWebKitAPI::testThreadGroup):
+ (TestWebKitAPI::TEST):
+
2017-07-21 Jonathan Bedard <[email protected]>
Fail gracefully when xcrun fails in IOSSimulatorPort constructor
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/ThreadGroup.cpp (219759 => 219760)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/ThreadGroup.cpp 2017-07-22 05:14:15 UTC (rev 219759)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/ThreadGroup.cpp 2017-07-22 07:27:00 UTC (rev 219760)
@@ -57,7 +57,7 @@
});
});
if (mode == Mode::Add)
- EXPECT_EQ(threadGroup->add(*thread), true);
+ EXPECT_TRUE(threadGroup->add(*thread) == ThreadGroupAddResult::NewlyAdded);
threads.append(thread);
}
@@ -104,7 +104,7 @@
std::shared_ptr<ThreadGroup> threadGroup = ThreadGroup::create();
RefPtr<Thread> thread = Thread::create("ThreadGroupWorker", [&] { });
thread->waitForCompletion();
- EXPECT_EQ(threadGroup->add(*thread), false);
+ EXPECT_TRUE(threadGroup->add(*thread) == ThreadGroupAddResult::NotAdded);
auto threadGroupLocker = holdLock(threadGroup->getLock());
EXPECT_EQ(threadGroup->threads(threadGroupLocker).size(), 0u);
@@ -122,8 +122,8 @@
return restarting;
});
});
- EXPECT_EQ(threadGroup->add(*thread), true);
- EXPECT_EQ(threadGroup->add(*thread), true);
+ EXPECT_TRUE(threadGroup->add(*thread) == ThreadGroupAddResult::NewlyAdded);
+ EXPECT_TRUE(threadGroup->add(*thread) == ThreadGroupAddResult::AlreadyAdded);
{
auto threadGroupLocker = holdLock(threadGroup->getLock());