Renamed XThreadUnavailable to XMTThreadUnavailable and derived it

from XBase so it can be caught normally.  Changed client and server
to handle unavailable threads (in main loop, anyway).
This commit is contained in:
crs 2002-10-15 22:01:41 +00:00
parent abee021db2
commit c405c58c64
7 changed files with 86 additions and 8 deletions

View File

@ -31,6 +31,7 @@
#include "CLock.h"
#include "CThread.h"
#include "CTimerThread.h"
#include "XMT.h"
#include "XThread.h"
#include "CLog.h"
#include "CStopwatch.h"
@ -209,6 +210,14 @@ CClient::mainLoop()
deleteSession();
LOG((CLOG_NOTE "stopping client \"%s\"", m_name.c_str()));
}
catch (XMT& e) {
LOG((CLOG_ERR "client error: %s", e.what()));
// clean up
deleteSession();
LOG((CLOG_NOTE "stopping client \"%s\"", m_name.c_str()));
throw;
}
catch (XBase& e) {
LOG((CLOG_ERR "client error: %s", e.what()));

View File

@ -16,6 +16,7 @@
#include "CLock.h"
#include "CMutex.h"
#include "CThread.h"
#include "XMT.h"
#include "XThread.h"
#include "CLog.h"
#include "IJob.h"
@ -113,7 +114,7 @@ CThreadRep::CThreadRep(IJob* job, void* userData) :
status = pthread_create(&m_thread, &attr, threadFunc, (void*)this);
pthread_sigmask(SIG_SETMASK, &oldsigset, NULL);
if (status != 0) {
throw XThreadUnavailable();
throw XMTThreadUnavailable();
}
#elif WINDOWS_LIKE
unsigned int id;
@ -121,7 +122,7 @@ CThreadRep::CThreadRep(IJob* job, void* userData) :
threadFunc, (void*)this, 0, &id));
m_id = static_cast<DWORD>(id);
if (m_thread == 0) {
throw XThreadUnavailable();
throw XMTThreadUnavailable();
}
#endif

View File

@ -31,12 +31,14 @@ libmt_a_SOURCES = \
CThread.cpp \
CThreadRep.cpp \
CTimerThread.cpp \
XMT.cpp \
CCondVar.h \
CLock.h \
CMutex.h \
CThread.h \
CThreadRep.h \
CTimerThread.h \
XMT.h \
XThread.h \
$(NULL)
INCLUDES = \

25
lib/mt/XMT.cpp Normal file
View File

@ -0,0 +1,25 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "XMT.h"
//
// XMTThreadUnavailable
//
CString
XMTThreadUnavailable::getWhat() const throw()
{
return format("XMTThreadUnavailable", "cannot create thread");
}

33
lib/mt/XMT.h Normal file
View File

@ -0,0 +1,33 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef XMT_H
#define XMT_H
#include "XBase.h"
//! Generic multithreading exception
class XMT : public XBase { };
//! Thread creation exception
/*!
Thrown when a thread cannot be created.
*/
class XMTThreadUnavailable : public XMT {
protected:
// XBase overrides
virtual CString getWhat() const throw();
};
#endif

View File

@ -16,6 +16,11 @@
#define XTHREAD_H
//! Generic thread exception
/*!
Exceptions derived from this class are used by the multithreading
library to perform stack unwinding when a thread terminates. These
exceptions must always be rethrown by clients when caught.
*/
class XThread { };
//! Thread exception to exit
@ -41,12 +46,6 @@ must rethrow it if caught (by XThreadCancel, XThread, or ...).
*/
class XThreadCancel : public XThread { };
//! Thread creation exception
/*!
Thrown when a thread cannot be created.
*/
class XThreadUnavailable { };
/*!
\def RETHROW_XTHREAD
Convenience macro to rethrow an XThread exception but ignore other

View File

@ -31,6 +31,7 @@
#include "CLock.h"
#include "CThread.h"
#include "CTimerThread.h"
#include "XMT.h"
#include "XThread.h"
#include "CFunctionJob.h"
#include "CLog.h"
@ -130,6 +131,14 @@ CServer::mainLoop()
} while (false)
FINALLY;
}
catch (XMT& e) {
LOG((CLOG_ERR "server error: %s", e.what()));
// clean up
LOG((CLOG_NOTE "stopping server"));
FINALLY;
throw;
}
catch (XBase& e) {
LOG((CLOG_ERR "server error: %s", e.what()));