Updated Makefiles and win32 projects and removed dead classes.

This commit is contained in:
crs
2004-02-15 18:12:35 +00:00
parent 48908242d2
commit 612a2054e6
17 changed files with 135 additions and 385 deletions

View File

@@ -15,7 +15,7 @@
#include "CFunctionEventJob.h"
//
// CFunctionJob
// CFunctionEventJob
//
CFunctionEventJob::CFunctionEventJob(

View File

@@ -1,113 +0,0 @@
/*
* 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 "CJobList.h"
#include "IJob.h"
#include "CArch.h"
//
// CJobList
//
CJobList::CJobList()
{
m_mutex = ARCH->newMutex();
}
CJobList::~CJobList()
{
ARCH->closeMutex(m_mutex);
}
void
CJobList::addJob(IJob* job)
{
// ignore bogus job
if (job == NULL) {
return;
}
// make a temporary list with the job. later we'll splice this
// list into our jobs list. since splice() never throws we
// don't have to try/catch to unlock the mutex.
CJobs tmpList;
tmpList.push_front(job);
// add job to list
ARCH->lockMutex(m_mutex);
m_jobs.splice(m_jobs.begin(), tmpList);
ARCH->unlockMutex(m_mutex);
}
void
CJobList::removeJob(IJob* job)
{
if (job != NULL) {
ARCH->lockMutex(m_mutex);
m_jobs.remove(job);
ARCH->unlockMutex(m_mutex);
}
}
void
CJobList::runJobs() const
{
// this is a little tricky. to allow any number of threads to
// traverse the list while jobs are added and removed while
// not holding the mutex when running a job (so other threads
// or the running job can add and remove jobs), we insert a
// new element into the list. this element has a NULL job and
// is a "safe place" while we traverse the list. the safe place
// is inserted at the start of the list (with the mutex locked)
// then, for each job, we lock the mutex and move the safe place
// past the next job, unlock the mutex, run the job and repeat
// until there are no more jobs. the safe place will not be
// removed by any other thread and is after every job that has
// been run and before every job that still needs to run. when
// all the jobs have been run we remove the safe place.
// add the safe place
CJobs tmpList;
tmpList.push_front(NULL);
ARCH->lockMutex(m_mutex);
m_jobs.splice(m_jobs.begin(), tmpList);
CJobs::iterator safePlace = m_jobs.begin();
// find the next non-NULL job (NULL jobs are safe places)
CJobs::iterator next = safePlace;
while (next != m_jobs.end() && *next == NULL)
++next;
while (next != m_jobs.end()) {
// found a job. run it without holding a lock. note the
// race condition here: we release the lock, allowing
// removeJob() to remove this job before we run the job.
// therefore the caller cannot safely destroy the job
// until all runJobs() complete.
IJob* job = *next;
++next;
m_jobs.splice(next, m_jobs, safePlace);
ARCH->unlockMutex(m_mutex);
job->run();
// next real job
ARCH->lockMutex(m_mutex);
next = safePlace;
while (next != m_jobs.end() && *next == NULL)
++next;
}
// remove the safe place
m_jobs.erase(safePlace);
ARCH->unlockMutex(m_mutex);
}

View File

@@ -1,72 +0,0 @@
/*
* 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 CJOBLIST_H
#define CJOBLIST_H
#include "IArchMultithread.h"
#include "stdlist.h"
class IJob;
class CJobList {
public:
CJobList();
~CJobList();
//! @name manipulators
//@{
//! Add a job
/*!
Add a job to the list. The client keeps ownership of the job.
Jobs can be safely added while \c runJobs() is executing.
*/
void addJob(IJob*);
//! Remove a job
/*!
Remove a job from the list. The client keeps ownership of the job.
Jobs can be safely removed while \c runJobs() is executing.
*/
void removeJob(IJob*);
//@}
//! @name accessors
//@{
//! Run all jobs
/*!
Run all jobs in the list. Any number of threads can call
\c runJobs() at once. Jobs can be added and removed while
\c runJobs() is executing in the same or another thread.
Any job added after \c runJobs() starts will not be run
by that call to runJobs(). Destroying a removed job
while \c runJobs() is executing is not safe unless the
removed completed before \c runJobs() started.
*/
void runJobs() const;
//@}
private:
typedef std::list<IJob*> CJobs;
typedef CJobs::iterator iterator;
CArchMutex m_mutex;
mutable CJobs m_jobs;
};
#endif

View File

@@ -29,7 +29,6 @@ libbase_a_SOURCES = \
CEventQueue.cpp \
CFunctionEventJob.cpp \
CFunctionJob.cpp \
CJobList.cpp \
CLog.cpp \
CSimpleEventQueueBuffer.cpp \
CStopwatch.cpp \
@@ -40,8 +39,8 @@ libbase_a_SOURCES = \
XBase.cpp \
CEvent.h \
CEventQueue.h \
CFunctionEventJob.h \
CFunctionJob.h \
CJobList.h \
CLog.h \
CPriorityQueue.h \
CSimpleEventQueueBuffer.h \
@@ -49,6 +48,7 @@ libbase_a_SOURCES = \
CString.h \
CStringUtil.h \
CUnicode.h \
IEventJob.h \
IEventQueue.h \
IEventQueueBuffer.h \
IJob.h \

View File

@@ -87,15 +87,27 @@ LIB32=link.exe -lib
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\CEvent.cpp
# End Source File
# Begin Source File
SOURCE=.\CEventQueue.cpp
# End Source File
# Begin Source File
SOURCE=.\CFunctionEventJob.cpp
# End Source File
# Begin Source File
SOURCE=.\CFunctionJob.cpp
# End Source File
# Begin Source File
SOURCE=.\CJobList.cpp
SOURCE=.\CLog.cpp
# End Source File
# Begin Source File
SOURCE=.\CLog.cpp
SOURCE=.\CSimpleEventQueueBuffer.cpp
# End Source File
# Begin Source File
@@ -111,6 +123,10 @@ SOURCE=.\CUnicode.cpp
# End Source File
# Begin Source File
SOURCE=.\IEventQueue.cpp
# End Source File
# Begin Source File
SOURCE=.\LogOutputters.cpp
# End Source File
# Begin Source File
@@ -123,15 +139,31 @@ SOURCE=.\XBase.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\CEvent.h
# End Source File
# Begin Source File
SOURCE=.\CEventQueue.h
# End Source File
# Begin Source File
SOURCE=.\CFunctionEventJob.h
# End Source File
# Begin Source File
SOURCE=.\CFunctionJob.h
# End Source File
# Begin Source File
SOURCE=.\CJobList.h
SOURCE=.\CLog.h
# End Source File
# Begin Source File
SOURCE=.\CLog.h
SOURCE=.\CPriorityQueue.h
# End Source File
# Begin Source File
SOURCE=.\CSimpleEventQueueBuffer.h
# End Source File
# Begin Source File
@@ -151,6 +183,18 @@ SOURCE=.\CUnicode.h
# End Source File
# Begin Source File
SOURCE=.\IEventJob.h
# End Source File
# Begin Source File
SOURCE=.\IEventQueue.h
# End Source File
# Begin Source File
SOURCE=.\IEventQueueBuffer.h
# End Source File
# Begin Source File
SOURCE=.\IJob.h
# End Source File
# Begin Source File
@@ -163,6 +207,10 @@ SOURCE=.\LogOutputters.h
# End Source File
# Begin Source File
SOURCE=.\TMethodEventJob.h
# End Source File
# Begin Source File
SOURCE=.\TMethodJob.h
# End Source File
# Begin Source File