require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_I386_LOCK_H_)) {
    eval 'sub _I386_LOCK_H_ () {1;}' unless defined(&_I386_LOCK_H_);
    eval 'sub __SIMPLELOCK_LOCKED () {1;}' unless defined(&__SIMPLELOCK_LOCKED);
    eval 'sub __SIMPLELOCK_UNLOCKED () {0;}' unless defined(&__SIMPLELOCK_UNLOCKED);
    eval 'sub __lockbarrier () {
        eval q( &__asm  &__volatile(\\"\\": : :\\"memory\\"));
    }' unless defined(&__lockbarrier);
    if(defined(&LOCKDEBUG)) {
    } else {
	require 'machine/atomic.ph';
	eval 'sub __cpu_simple_lock_init {
	    local($lockp) = @_;
    	    eval q({ *$lockp =  &__SIMPLELOCK_UNLOCKED;  &__lockbarrier(); });
	}' unless defined(&__cpu_simple_lock_init);
	eval 'sub __cpu_simple_lock {
	    local($lockp) = @_;
    	    eval q({  &while ( &i386_atomic_testset_i($lockp,  &__SIMPLELOCK_LOCKED) ==  &__SIMPLELOCK_LOCKED) {  &continue; }  &__lockbarrier(); });
	}' unless defined(&__cpu_simple_lock);
	eval 'sub __cpu_simple_lock_try {
	    local($lockp) = @_;
    	    eval q({ \'int\'  &r = ( &i386_atomic_testset_i($lockp,  &__SIMPLELOCK_LOCKED) ==  &__SIMPLELOCK_UNLOCKED);  &__lockbarrier(); ( &r); });
	}' unless defined(&__cpu_simple_lock_try);
	eval 'sub __cpu_simple_unlock {
	    local($lockp) = @_;
    	    eval q({  &__lockbarrier(); *$lockp =  &__SIMPLELOCK_UNLOCKED; });
	}' unless defined(&__cpu_simple_unlock);
    }
}
1;
