require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_MPLOCK_H_)) {
    eval 'sub _MPLOCK_H_ () {1;}' unless defined(&_MPLOCK_H_);
    eval 'sub SIMPLELOCK () { &__mp_lock;}' unless defined(&SIMPLELOCK);
    eval 'sub SIMPLE_LOCK_INIT () { &__mp_lock_init;}' unless defined(&SIMPLE_LOCK_INIT);
    eval 'sub SIMPLE_LOCK () { &__mp_lock;}' unless defined(&SIMPLE_LOCK);
    eval 'sub SIMPLE_UNLOCK () { &__mp_unlock;}' unless defined(&SIMPLE_UNLOCK);
    eval 'sub __mp_lock_init {
        my($lock) = @_;
	    eval q({  &__cpu_simple_lock_init( ($lock->{mpl_lock}));  ($lock->{mpl_cpu}) =  &LK_NOCPU;  ($lock->{mpl_count}) = 0; });
    }' unless defined(&__mp_lock_init);
    if(defined( &MP_LOCKDEBUG)) {
	unless(defined(&DDB)) {
	    die("MP_LOCKDEBUG requires DDB");
	}
    }
# some #ifdef were dropped here -- fill in the blanks
    eval 'sub __mp_lock {
        my($lock) = @_;
	    eval q({ \'int\'  &s =  &spllock();  &if ( ($lock->{mpl_cpu}) !=  &cpu_number()) {  ($lock->{mpl_cpu}) =  &cpu_number(); }  ($lock->{mpl_count})++;  &splx( &s); });
    }' unless defined(&__mp_lock);
# some #ifdef were dropped here -- fill in the blanks
    eval 'sub __mp_unlock {
        my($lock) = @_;
	    eval q({ \'int\'  &s =  &spllock();  &if (-- ($lock->{mpl_count}) == 0) {  ($lock->{mpl_cpu}) =  &LK_NOCPU;  &__cpu_simple_unlock( ($lock->{mpl_lock})); }  &splx( &s); });
    }' unless defined(&__mp_unlock);
# some #ifdef were dropped here -- fill in the blanks
    eval 'sub __mp_release_all {
        my($lock) = @_;
	    eval q({ \'int\'  &s =  &spllock(); \'int\'  &rv =  ($lock->{mpl_count});  ($lock->{mpl_cpu}) =  &LK_NOCPU;  ($lock->{mpl_count}) = 0;  &__cpu_simple_unlock( ($lock->{mpl_lock}));  &splx( &s); ( &rv); });
    }' unless defined(&__mp_release_all);
# some #ifdef were dropped here -- fill in the blanks
    eval 'sub __mp_release_all_but_one {
        my($lock) = @_;
	    eval q({ \'int\'  &s =  &spllock(); \'int\'  &rv =  ($lock->{mpl_count}) - 1;  ($lock->{mpl_count}) = 1;  &splx( &s); ( &rv); });
    }' unless defined(&__mp_release_all_but_one);
    eval 'sub __mp_acquire_count {
        my($lock,$count) = @_;
	    eval q({ \'int\'  &s =  &spllock();  &while ($count--)  &__mp_lock($lock);  &splx( &s); });
    }' unless defined(&__mp_acquire_count);
    eval 'sub __mp_lock_held {
        my($lock) = @_;
	    eval q({  ($lock->{mpl_count})  &&  ($lock->{mpl_cpu}) ==  &cpu_number(); });
    }' unless defined(&__mp_lock_held);
}
1;
