Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refs #10311. Convert FileTransfer reference counting to ReferenceCoun…

…ter.
  • Loading branch information...
commit cd996fdc97bcf8bea05096ba6b99ff5355c4349e 1 parent ad6d965
@daniel-kristjansson daniel-kristjansson authored
View
26 mythtv/programs/mythbackend/filetransfer.cpp
@@ -11,10 +11,11 @@
FileTransfer::FileTransfer(QString &filename, MythSocket *remote,
bool usereadahead, int timeout_ms) :
+ ReferenceCounter(QString("FileTransfer:%1").arg(filename)),
readthreadlive(true), readsLocked(false),
rbuffer(RingBuffer::Create(filename, false, usereadahead, timeout_ms, true)),
sock(remote), ateof(false), lock(QMutex::NonRecursive),
- refLock(QMutex::NonRecursive), refCount(0), writemode(false)
+ writemode(false)
{
pginfo = new ProgramInfo(filename);
pginfo->MarkAsInUse(true, kFileTransferInUseID);
@@ -22,10 +23,11 @@ FileTransfer::FileTransfer(QString &filename, MythSocket *remote,
}
FileTransfer::FileTransfer(QString &filename, MythSocket *remote, bool write) :
+ ReferenceCounter(QString("FileTransfer:%1").arg(filename)),
readthreadlive(true), readsLocked(false),
rbuffer(RingBuffer::Create(filename, write)),
sock(remote), ateof(false), lock(QMutex::NonRecursive),
- refLock(QMutex::NonRecursive), refCount(0), writemode(write)
+ writemode(write)
{
pginfo = new ProgramInfo(filename);
pginfo->MarkAsInUse(true, kFileTransferInUseID);
@@ -52,26 +54,6 @@ FileTransfer::~FileTransfer()
}
}
-void FileTransfer::UpRef(void)
-{
- QMutexLocker locker(&refLock);
- refCount++;
-}
-
-bool FileTransfer::DownRef(void)
-{
- int count = 0;
- {
- QMutexLocker locker(&refLock);
- count = --refCount;
- }
-
- if (count < 0)
- delete this;
-
- return (count < 0);
-}
-
bool FileTransfer::isOpen(void)
{
if (rbuffer && rbuffer->IsOpen())
View
8 mythtv/programs/mythbackend/filetransfer.h
@@ -12,12 +12,15 @@ using namespace std;
#include <QMutex>
#include <QWaitCondition>
+// MythTV headers
+#include "referencecounter.h"
+
class ProgramInfo;
class RingBuffer;
class MythSocket;
class QString;
-class FileTransfer
+class FileTransfer : public ReferenceCounter
{
friend class QObject; // quiet OSX gcc warning
@@ -33,9 +36,6 @@ class FileTransfer
void Stop(void);
- void UpRef(void);
- bool DownRef(void);
-
void Pause(void);
void Unpause(void);
int RequestBlock(int size);
View
14 mythtv/programs/mythbackend/mainserver.cpp
@@ -1571,16 +1571,20 @@ void MainServer::HandleAnnounce(QStringList &slist, QStringList commands,
ft = new FileTransfer(filename, socket, writemode);
}
else
+ {
ft = new FileTransfer(filename, socket, usereadahead, timeout_ms);
+ }
+
+ ft->IncrRef();
sockListLock.lockForWrite();
fileTransferList.push_back(ft);
sockListLock.unlock();
retlist << QString::number(socket->socket());
- ft->UpRef();
retlist << QString::number(ft->GetFileSize());
- ft->DownRef();
+
+ ft->DecrRef();
if (checkfiles.size())
{
@@ -5023,7 +5027,7 @@ void MainServer::HandleFileTransferQuery(QStringList &slist,
return;
}
- ft->UpRef();
+ ft->IncrRef();
sockListLock.unlock();
if (command == "IS_OPEN")
@@ -5074,7 +5078,7 @@ void MainServer::HandleFileTransferQuery(QStringList &slist,
retlist << "ok";
}
- ft->DownRef();
+ ft->DecrRef();
SendResponse(pbssock, retlist);
}
@@ -5775,7 +5779,7 @@ void MainServer::connectionClosed(MythSocket *socket)
MythSocket *sock = (*ft)->getSocket();
if (sock == socket)
{
- (*ft)->DownRef();
+ (*ft)->DecrRef();
fileTransferList.erase(ft);
sockListLock.unlock();
return;
Please sign in to comment.
Something went wrong with that request. Please try again.