@ -433,26 +433,34 @@ private:
inline void resetImpl ( bool startNewThread ) {
inline void resetImpl ( bool startNewThread ) {
DBG < < " Reseting " < < startNewThread ;
DBG < < " Reseting " < < startNewThread ;
exit_ . store ( true ) ;
if ( loadThread_ ) { // is loading.
if ( loadThread_ ) { // is loading.
exit_ . store ( true ) ;
loadThread_ - > join ( ) ;
loadThread_ - > join ( ) ;
loadThread_ . reset ( ) ;
loadThread_ . reset ( ) ;
}
}
{
{
PyGuard g ;
PyGuard g ;
callingContexts_ . clear ( ) ;
callingContexts_ . clear ( ) ;
this - > pullCV_ . notify_one ( ) ;
}
std : : lock_guard < std : : mutex > guard ( mutexForReset_ ) ;
{
PyGuard g ;
dataPool_ . clear ( ) ;
dataPool_ . clear ( ) ;
}
}
poolActualSize_ = 0 ;
poolActualSize_ = 0 ;
exit_ = false ;
if ( startNewThread & & cache_ - > reset ( ) ) {
if ( startNewThread & & cache_ - > reset ( ) ) {
DBG < < " Start new thread. " ;
DBG < < " Start new thread. " ;
loadThread_ . reset ( new std : : thread ( [ this ] {
loadThread_ . reset ( new std : : thread ( [ this ] {
exit_ = false ;
loadThread ( ) ;
loadThread ( ) ;
} ) ) ;
} ) ) ;
callingContextCreated_ . wait ( ) ;
callingContextCreated_ . wait ( ) ;
}
}
DBG < < " Reset done " ;
DBG < < " Reset done " ;
exit_ = false ;
}
}
private :
private :
@ -465,6 +473,8 @@ private:
std : : condition_variable pullCV_ ;
std : : condition_variable pullCV_ ;
std : : mutex mtx_ ;
std : : mutex mtx_ ;
std : : mutex mutexForReset_ ;
ThreadBarrier callingContextCreated_ ;
ThreadBarrier callingContextCreated_ ;
std : : unique_ptr < IPyDataProviderCache > cache_ ;
std : : unique_ptr < IPyDataProviderCache > cache_ ;
@ -529,6 +539,7 @@ public:
* Loading a batch of data .
* Loading a batch of data .
*/
*/
int64_t getNextBatchInternal ( int64_t size_ , DataBatch * batch ) {
int64_t getNextBatchInternal ( int64_t size_ , DataBatch * batch ) {
std : : lock_guard < std : : mutex > guard ( mutexForReset_ ) ;
REGISTER_TIMER ( " PyDP2.getNextBatchInternal " )
REGISTER_TIMER ( " PyDP2.getNextBatchInternal " )
CHECK_GE ( size_ , 0 ) ;
CHECK_GE ( size_ , 0 ) ;
size_t size = ( size_t ) size_ ;
size_t size = ( size_t ) size_ ;
@ -554,6 +565,10 @@ public:
} else { // loading from cache.
} else { // loading from cache.
poolPtr = this - > cache_ - > load ( ) ;
poolPtr = this - > cache_ - > load ( ) ;
}
}
if ( exit_ ) {
// PyDataProvider is destructing.
return 0 ;
}
CHECK ( poolPtr ! = nullptr ) ;
CHECK ( poolPtr ! = nullptr ) ;
std : : deque < PyObjectPtr > & pool = * poolPtr ;
std : : deque < PyObjectPtr > & pool = * poolPtr ;