require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_SYS_MUTEX_H_)) {
    eval 'sub _SYS_MUTEX_H_ () {1;}' unless defined(&_SYS_MUTEX_H_);
    if(defined(&_KERNEL_OPT)) {
	require './sys/opt_lockdebug.ph';
    }
    if(!defined(&_KERNEL)) {
	require 'sys/types.ph';
	require 'sys/inttypes.ph';
    }
    eval("sub MUTEX_SPIN () { 0; }") unless defined(&MUTEX_SPIN);
    eval("sub MUTEX_ADAPTIVE () { 1; }") unless defined(&MUTEX_ADAPTIVE);
    eval("sub MUTEX_DEFAULT () { 2; }") unless defined(&MUTEX_DEFAULT);
    eval("sub MUTEX_DRIVER () { 3; }") unless defined(&MUTEX_DRIVER);
    eval("sub MUTEX_NODEBUG () { 4; }") unless defined(&MUTEX_NODEBUG);
    if(defined(&__MUTEX_PRIVATE)) {
	eval 'sub MUTEX_THREAD () {(( &uintptr_t)-16);}' unless defined(&MUTEX_THREAD);
	eval 'sub MUTEX_BIT_SPIN () {0x1;}' unless defined(&MUTEX_BIT_SPIN);
	eval 'sub MUTEX_BIT_WAITERS () {0x2;}' unless defined(&MUTEX_BIT_WAITERS);
	if(defined(&LOCKDEBUG)) {
	    eval 'sub MUTEX_BIT_NODEBUG () {0x4;}' unless defined(&MUTEX_BIT_NODEBUG);
	} else {
	    eval 'sub MUTEX_BIT_NODEBUG () {0x;}' unless defined(&MUTEX_BIT_NODEBUG);
	}
	eval 'sub MUTEX_SPIN_IPL {
	    my($mtx) = @_;
    	    eval q((($mtx)-> &mtx_ipl));
	}' unless defined(&MUTEX_SPIN_IPL);
	eval 'sub MUTEX_SPIN_OLDSPL {
	    my($ci) = @_;
    	    eval q((($ci)-> &ci_mtx_oldspl));
	}' unless defined(&MUTEX_SPIN_OLDSPL);
    }
    if(defined(&_KERNEL)) {
	require 'sys/intr.ph';
    }
    require 'machine/mutex.ph';
    unless(defined(&MUTEX_NO_SPIN_ACTIVE_P)) {
	eval 'sub MUTEX_NO_SPIN_ACTIVE_P {
	    my($ci) = @_;
    	    eval q((($ci)-> &ci_mtx_count == 0));
	}' unless defined(&MUTEX_NO_SPIN_ACTIVE_P);
    }
    if(defined(&_KERNEL)) {
    }
}
1;
