mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-08 18:19:42 +00:00
Store the forked calls in boost::shared_ptr rather than a raw pointer.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8518 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
5a59ab2c37
commit
e942a15dd8
@ -1,3 +1,9 @@
|
||||
2004-03-23 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* ispell.C (LaunchIspell):
|
||||
* lyx_cb.C (AutoSaveBuffer): change the signature of clone to return
|
||||
a boost::shred_ptr rather than a std::auto_ptr.
|
||||
|
||||
2004-03-22 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
|
||||
|
||||
* lyxfunc.C (getStatus): handle read-only buffers correctly;
|
||||
|
@ -30,13 +30,14 @@
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
|
||||
using boost::shared_ptr;
|
||||
|
||||
#ifndef CXX_GLOBAL_CSTD
|
||||
using std::strcpy;
|
||||
using std::strlen;
|
||||
using std::strpbrk;
|
||||
#endif
|
||||
|
||||
using std::auto_ptr;
|
||||
using std::endl;
|
||||
using std::max;
|
||||
using std::string;
|
||||
@ -45,14 +46,15 @@ using std::string;
|
||||
namespace {
|
||||
|
||||
class LaunchIspell : public lyx::support::ForkedProcess {
|
||||
typedef lyx::support::ForkedProcess ForkedProcess;
|
||||
public:
|
||||
///
|
||||
LaunchIspell(BufferParams const & p, string const & l,
|
||||
int * in, int * out, int * err)
|
||||
: params(p), lang(l), pipein(in), pipeout(out), pipeerr(err) {}
|
||||
///
|
||||
virtual auto_ptr<lyx::support::ForkedProcess> clone() const {
|
||||
return auto_ptr<lyx::support::ForkedProcess>(new LaunchIspell(*this));
|
||||
virtual shared_ptr<ForkedProcess> clone() const {
|
||||
return shared_ptr<ForkedProcess>(new LaunchIspell(*this));
|
||||
}
|
||||
///
|
||||
int start();
|
||||
|
10
src/lyx_cb.C
10
src/lyx_cb.C
@ -44,6 +44,8 @@
|
||||
#include "support/path_defines.h"
|
||||
#include "support/systemcall.h"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <cerrno>
|
||||
#include <fstream>
|
||||
|
||||
@ -71,7 +73,8 @@ using lyx::support::user_lyxdir;
|
||||
|
||||
namespace os = lyx::support::os;
|
||||
|
||||
using std::auto_ptr;
|
||||
using boost::shared_ptr;
|
||||
|
||||
using std::back_inserter;
|
||||
using std::copy;
|
||||
using std::endl;
|
||||
@ -221,8 +224,9 @@ public:
|
||||
AutoSaveBuffer(BufferView & bv, string const & fname)
|
||||
: bv_(bv), fname_(fname) {}
|
||||
///
|
||||
virtual auto_ptr<ForkedProcess> clone() const {
|
||||
return auto_ptr<ForkedProcess>(new AutoSaveBuffer(*this));
|
||||
virtual shared_ptr<ForkedProcess> clone() const
|
||||
{
|
||||
return shared_ptr<ForkedProcess>(new AutoSaveBuffer(*this));
|
||||
}
|
||||
///
|
||||
int start();
|
||||
|
@ -1,3 +1,11 @@
|
||||
2004-03-23 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* forkedcall.h (ForkedProcess, Forkedcall): change the signature of
|
||||
clone to return a boost::shred_ptr rather than a std::auto_ptr.
|
||||
|
||||
* forkedcontr.[Ch]: store the forked calls as boost::shared_ptrs rather
|
||||
than raw pointers.
|
||||
|
||||
2004-03-22 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* forkedcontr.[Ch] (childrenChanged, getPIDs, getCommand): remove
|
||||
|
@ -32,8 +32,6 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
|
||||
@ -52,7 +50,7 @@ public:
|
||||
///
|
||||
virtual ~ForkedProcess() {}
|
||||
///
|
||||
virtual std::auto_ptr<ForkedProcess> clone() const = 0;
|
||||
virtual boost::shared_ptr<ForkedProcess> clone() const = 0;
|
||||
|
||||
/** A SignalType signal is can be emitted once the forked process
|
||||
* has finished. It passes:
|
||||
@ -141,8 +139,8 @@ private:
|
||||
class Forkedcall : public ForkedProcess {
|
||||
public:
|
||||
///
|
||||
virtual std::auto_ptr<ForkedProcess> clone() const {
|
||||
return std::auto_ptr<ForkedProcess>(new Forkedcall(*this));
|
||||
virtual boost::shared_ptr<ForkedProcess> clone() const {
|
||||
return boost::shared_ptr<ForkedProcess>(new Forkedcall(*this));
|
||||
}
|
||||
|
||||
/** Start the child process.
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "frontends/Timeout.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/iterator/indirect_iterator.hpp>
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
@ -65,11 +66,6 @@ ForkedcallsController::ForkedcallsController()
|
||||
// I want to print or something.
|
||||
ForkedcallsController::~ForkedcallsController()
|
||||
{
|
||||
for (ListType::iterator it = forkedCalls.begin();
|
||||
it != forkedCalls.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
delete timeout_;
|
||||
}
|
||||
|
||||
@ -79,7 +75,7 @@ void ForkedcallsController::addCall(ForkedProcess const & newcall)
|
||||
if (!timeout_->running())
|
||||
timeout_->start();
|
||||
|
||||
forkedCalls.push_back(newcall.clone().release());
|
||||
forkedCalls.push_back(newcall.clone());
|
||||
}
|
||||
|
||||
|
||||
@ -90,7 +86,7 @@ void ForkedcallsController::timer()
|
||||
ListType::iterator it = forkedCalls.begin();
|
||||
ListType::iterator end = forkedCalls.end();
|
||||
while (it != end) {
|
||||
ForkedProcess * actCall = *it;
|
||||
ForkedProcess * actCall = it->get();
|
||||
|
||||
pid_t pid = actCall->pid();
|
||||
int stat_loc;
|
||||
@ -134,10 +130,8 @@ void ForkedcallsController::timer()
|
||||
}
|
||||
|
||||
if (remove_it) {
|
||||
forkedCalls.erase(it);
|
||||
|
||||
actCall->emitSignal();
|
||||
delete actCall;
|
||||
forkedCalls.erase(it);
|
||||
|
||||
/* start all over: emiting the signal can result
|
||||
* in changing the list (Ab)
|
||||
@ -158,19 +152,21 @@ void ForkedcallsController::timer()
|
||||
// within tolerance secs
|
||||
void ForkedcallsController::kill(pid_t pid, int tolerance)
|
||||
{
|
||||
ListType::iterator it =
|
||||
find_if(forkedCalls.begin(), forkedCalls.end(),
|
||||
lyx::compare_memfun(&Forkedcall::pid, pid));
|
||||
typedef boost::indirect_iterator<ListType::iterator> iterator;
|
||||
|
||||
if (it == forkedCalls.end())
|
||||
iterator begin = boost::make_indirect_iterator(forkedCalls.begin());
|
||||
iterator end = boost::make_indirect_iterator(forkedCalls.end());
|
||||
iterator it = find_if(begin, end,
|
||||
lyx::compare_memfun(&Forkedcall::pid, pid));
|
||||
|
||||
if (it == end)
|
||||
return;
|
||||
|
||||
(*it)->kill(tolerance);
|
||||
forkedCalls.erase(it);
|
||||
it->kill(tolerance);
|
||||
forkedCalls.erase(it.base());
|
||||
|
||||
if (forkedCalls.empty()) {
|
||||
if (forkedCalls.empty())
|
||||
timeout_->stop();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace support
|
||||
|
@ -16,8 +16,8 @@
|
||||
#ifndef FORKEDCONTR_H
|
||||
#define FORKEDCONTR_H
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <sys/types.h> // needed for pid_t
|
||||
|
||||
#include <list>
|
||||
|
||||
class Timeout;
|
||||
@ -54,7 +54,8 @@ private:
|
||||
void timer();
|
||||
|
||||
/// The child processes
|
||||
typedef std::list<ForkedProcess *> ListType;
|
||||
typedef boost::shared_ptr<ForkedProcess> ForkedProcessPtr;
|
||||
typedef std::list<ForkedProcessPtr> ListType;
|
||||
///
|
||||
ListType forkedCalls;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user