Ok. I was wrong... bind does make a copy... bastard...
diff --git a/src/fetch-manager.cc b/src/fetch-manager.cc
index 4fbe5bc..788d635 100644
--- a/src/fetch-manager.cc
+++ b/src/fetch-manager.cc
@@ -79,29 +79,34 @@
Name forwardingHint;
forwardingHint = m_mapping (deviceName);
- Fetcher &fetcher = *(new Fetcher (m_ccnx,
- m_executor,
- segmentCallback,
- finishCallback,
- bind (&FetchManager::DidFetchComplete, this, _1),
- bind (&FetchManager::DidNoDataTimeout, this, _1),
- deviceName, baseName, minSeqNo, maxSeqNo,
- boost::posix_time::seconds (30),
- forwardingHint));
+ unique_lock<mutex> lock (m_parellelFetchMutex);
+
+ _LOG_TRACE ("++++ Create fetcher: " << baseName);
+ Fetcher *fetcher = new Fetcher (m_ccnx,
+ m_executor,
+ segmentCallback,
+ finishCallback,
+ bind (&FetchManager::DidFetchComplete, this, _1),
+ bind (&FetchManager::DidNoDataTimeout, this, _1),
+ deviceName, baseName, minSeqNo, maxSeqNo,
+ boost::posix_time::seconds (30),
+ forwardingHint);
switch (priority)
{
case PRIORITY_HIGH:
- m_fetchList.push_front (fetcher);
+ _LOG_TRACE ("++++ Push front fetcher: " << fetcher->GetName ());
+ m_fetchList.push_front (*fetcher);
break;
case PRIORITY_NORMAL:
default:
- m_fetchList.push_back (fetcher);
+ _LOG_TRACE ("++++ Push back fetcher: " << fetcher->GetName ());
+ m_fetchList.push_back (*fetcher);
break;
}
- _LOG_DEBUG ("Reschedule fetcher task");
+ _LOG_DEBUG ("++++ Reschedule fetcher task");
m_scheduler->rescheduleTaskAt (m_scheduleFetchesTask, 0);
// ScheduleFetches (); // will start a fetch if m_currentParallelFetches is less than max, otherwise does nothing
}
@@ -136,6 +141,7 @@
_LOG_DEBUG ("Start fetching of " << item->GetName ());
m_currentParallelFetches ++;
+ _LOG_TRACE ("++++ RESTART PIPELINE: " << item->GetName ());
item->RestartPipeline ();
}
@@ -189,6 +195,7 @@
{
unique_lock<mutex> lock (m_parellelFetchMutex);
m_currentParallelFetches --;
+ _LOG_TRACE ("+++++ removing fetcher: " << fetcher.GetName ());
m_fetchList.erase_and_dispose (FetchList::s_iterator_to (fetcher), fetcher_disposer ());
}
diff --git a/src/fetcher.cc b/src/fetcher.cc
index eb40f83..13a52b3 100644
--- a/src/fetcher.cc
+++ b/src/fetcher.cc
@@ -183,7 +183,7 @@
if (m_maxInOrderRecvSeqNo == m_maxSeqNo)
{
- _LOG_TRACE ("Fetch finished");
+ _LOG_TRACE ("Fetch finished: " << m_name);
m_active = false;
// invoke callback
if (!m_finishCallback.empty ())
@@ -195,7 +195,7 @@
// tell FetchManager that we have finish our job
// m_onFetchComplete (*this);
// using executor, so we won't be deleted if there is scheduled FillPipeline call
- m_executor->execute (bind (m_onFetchComplete, *this));
+ m_executor->execute (bind (m_onFetchComplete, ref(*this)));
}
else
{
@@ -230,7 +230,7 @@
_LOG_DEBUG ("Active pipeline size should be zero: " << m_inActivePipeline.size ());
m_active = false;
- m_onFetchFailed (*this);
+ m_onFetchFailed (ref (*this));
// this is not valid anymore, but we still should be able finish work
}
}