summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceUtil/Thread.cpp22
-rw-r--r--cpp/src/IceUtil/ThreadException.cpp23
2 files changed, 42 insertions, 3 deletions
diff --git a/cpp/src/IceUtil/Thread.cpp b/cpp/src/IceUtil/Thread.cpp
index 29853280530..067bd721d76 100644
--- a/cpp/src/IceUtil/Thread.cpp
+++ b/cpp/src/IceUtil/Thread.cpp
@@ -22,6 +22,7 @@ using namespace std;
IceUtil::ThreadControl::ThreadControl() :
_handle(new HandleWrapper(0)),
+ _detached(false),
_id(GetCurrentThreadId())
{
HANDLE proc = GetCurrentProcess();
@@ -35,8 +36,8 @@ IceUtil::ThreadControl::ThreadControl() :
IceUtil::ThreadControl::ThreadControl(const HandleWrapperPtr& handle, unsigned id) :
_handle(handle),
- _id(id),
- _detached(false)
+ _detached(false),
+ _id(id)
{
}
@@ -109,6 +110,7 @@ IceUtil::ThreadControl::yield()
}
IceUtil::Thread::Thread() :
+ _started(false),
_id(0),
_handle(new HandleWrapper(0))
{
@@ -156,6 +158,12 @@ startHook(void* arg)
IceUtil::ThreadControl
IceUtil::Thread::start()
{
+ if(_started)
+ {
+ throw ThreadStartedException(__FILE__, __LINE__);
+ }
+ _started = true;
+
//
// It's necessary to increment the reference count since
// pthread_create won't necessarily call the thread function until
@@ -275,7 +283,9 @@ IceUtil::ThreadControl::yield()
sched_yield();
}
-IceUtil::Thread::Thread()
+IceUtil::Thread::Thread() :
+ _started(false),
+ _id(0)
{
}
@@ -321,6 +331,12 @@ startHook(void* arg)
IceUtil::ThreadControl
IceUtil::Thread::start()
{
+ if(_started)
+ {
+ throw ThreadStartedException(__FILE__, __LINE__);
+ }
+ _started = true;
+
//
// It's necessary to increment the reference count since
// pthread_create won't necessarily call the thread function until
diff --git a/cpp/src/IceUtil/ThreadException.cpp b/cpp/src/IceUtil/ThreadException.cpp
index 709a048df30..6860de992aa 100644
--- a/cpp/src/IceUtil/ThreadException.cpp
+++ b/cpp/src/IceUtil/ThreadException.cpp
@@ -102,3 +102,26 @@ IceUtil::ThreadLockedException::ice_throw() const
{
throw *this;
}
+
+IceUtil::ThreadStartedException::ThreadStartedException(const char* file, int line) :
+ Exception(file, line)
+{
+}
+
+string
+IceUtil::ThreadStartedException::ice_name() const
+{
+ return "IceUtil::ThreadStartedException";
+}
+
+IceUtil::Exception*
+IceUtil::ThreadStartedException::ice_clone() const
+{
+ return new ThreadStartedException(*this);
+}
+
+void
+IceUtil::ThreadStartedException::ice_throw() const
+{
+ throw *this;
+}