|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-08-21 17:14:05
Howard Hinnant wrote:
> Did I make more sense this time? I often complain when people use too
> much English and not enough C++ in their arguments, and then I find
> myself being guilty of the same thing. :-)
Hmmm. Maybe I need to heed this advice as well.
template<class M> class condition
{
public:
explicit condition( M * pm = 0 )
{
__cndcheck_init( this, pm );
}
wait( Lock & lk )
{
__cndcheck_wait( this, lk.mutex() );
// ...
}
};
// Release mode (duh)
void __cndcheck_init( void * pc, void * pm )
{
}
void __cndcheck_wait( void * pc, void * pm2 )
{
}
// Debug mode
map< void*, void* > __cndcheck_state; // must be synchronized
void __cndcheck_init( void * pc, void * pm )
{
__cndcheck_state[ pc ] = pm;
}
void __cndcheck_wait( void * pc, void * pm2 )
{
assert( __cndcheck_state.count( pc ) );
assert( __cndcheck_state[ pc ] == 0 || __cndcheck_state[ pc ] == pm2 );
}
// Checked release mode
struct __cndcheck_item // must be atomic
{
void * pc_;
void * pm_;
};
__cndcheck_item __cndcheck_state[ 17041 ];
void __cndcheck_init( void * pc, void * pm )
{
__cndcheck_state[ (size_t)pc % 17041 ] = { pc, pm }; // atomic store
}
void __cndcheck_wait( void * pc, void * pm2 )
{
__cndcheck_item it = __cndcheck_state[ (size_t)pc % 17041 ]; // atomic
load
if( it.pc_ == pc )
{
assert( it.pm_ == 0 || it.pm_ == pm2 );
}
}
Or something along those lines. :-)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk