@ -207,16 +207,14 @@ public:
const_iterator end ( ) const { return const_iterator ( * this , ( rpos + count ) % max_size ( ) ) ; }
const_iterator end ( ) const { return const_iterator ( * this , ( rpos + count ) % max_size ( ) ) ; }
template < typename F >
template < typename F >
T discard_if ( const F & func )
bool apply_first ( const F & func )
{
{
for ( auto it = begin ( ) ; it ! = end ( ) ; it + + ) {
for ( auto it = begin ( ) ; it ! = end ( ) ; it + + ) {
if ( * it ! = nullptr & & func ( * it ) ) {
if ( func ( * it ) ) {
T tmp = std : : move ( * it ) ;
return true ;
* it = nullptr ;
return tmp ;
}
}
}
}
return nullptr ;
return false ;
}
}
protected :
protected :
@ -334,24 +332,20 @@ public:
}
}
template < typename F >
template < typename F >
bool discard_if ( const F & func )
bool apply_first ( const F & func )
{
{
std : : lock_guard < std : : mutex > lock ( mutex ) ;
std : : lock_guard < std : : mutex > lock ( mutex ) ;
T tmp = circ_buffer . discard_if ( func ) ;
return circ_buffer . apply_first ( func ) ;
if ( tmp = = nullptr ) {
return false ;
}
pop_func ( tmp ) ;
return true ;
}
}
PushingFunc push_func ;
PoppingFunc pop_func ;
protected :
protected :
bool active = true ;
bool active = true ;
uint8_t nof_waiting = 0 ;
uint8_t nof_waiting = 0 ;
mutable std : : mutex mutex ;
mutable std : : mutex mutex ;
std : : condition_variable cvar_empty , cvar_full ;
std : : condition_variable cvar_empty , cvar_full ;
PushingFunc push_func ;
PoppingFunc pop_func ;
CircBuffer circ_buffer ;
CircBuffer circ_buffer ;
~ base_blocking_queue ( ) { stop ( ) ; }
~ base_blocking_queue ( ) { stop ( ) ; }
@ -596,9 +590,9 @@ public:
void set_size ( size_t size ) { base_t : : circ_buffer . set_size ( size ) ; }
void set_size ( size_t size ) { base_t : : circ_buffer . set_size ( size ) ; }
template < typename F >
template < typename F >
bool discard_if ( const F & func )
bool apply_first ( const F & func )
{
{
return base_t : : discard_if ( func ) ;
return base_t : : apply_first ( func ) ;
}
}
} ;
} ;