require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_GLIBCXX_GCC_GTHR_POSIX_H)) {
    eval 'sub _GLIBCXX_GCC_GTHR_POSIX_H () {1;}' unless defined(&_GLIBCXX_GCC_GTHR_POSIX_H);
    eval 'sub __GTHREADS () {1;}' unless defined(&__GTHREADS);
    eval 'sub __GTHREADS_CXX0X () {1;}' unless defined(&__GTHREADS_CXX0X);
    require 'pthread.ph';
    if(((defined(&_LIBOBJC) || defined(&_LIBOBJC_WEAK)) || !defined(&_GTHREAD_USE_MUTEX_TIMEDLOCK))) {
	require 'unistd.ph';
	if(defined(&_POSIX_TIMEOUTS)  && (defined(&_POSIX_TIMEOUTS) ? &_POSIX_TIMEOUTS : undef) >= 0) {
	    eval 'sub _GTHREAD_USE_MUTEX_TIMEDLOCK () {1;}' unless defined(&_GTHREAD_USE_MUTEX_TIMEDLOCK);
	} else {
	    eval 'sub _GTHREAD_USE_MUTEX_TIMEDLOCK () {0;}' unless defined(&_GTHREAD_USE_MUTEX_TIMEDLOCK);
	}
    }
    eval 'sub __GTHREAD_HAS_COND () {1;}' unless defined(&__GTHREAD_HAS_COND);
    eval 'sub __GTHREAD_MUTEX_INIT () { &PTHREAD_MUTEX_INITIALIZER;}' unless defined(&__GTHREAD_MUTEX_INIT);
    eval 'sub __GTHREAD_MUTEX_INIT_FUNCTION () { &__gthread_mutex_init_function;}' unless defined(&__GTHREAD_MUTEX_INIT_FUNCTION);
    eval 'sub __GTHREAD_ONCE_INIT () { &PTHREAD_ONCE_INIT;}' unless defined(&__GTHREAD_ONCE_INIT);
    if(defined(&PTHREAD_RECURSIVE_MUTEX_INITIALIZER)) {
	eval 'sub __GTHREAD_RECURSIVE_MUTEX_INIT () { &PTHREAD_RECURSIVE_MUTEX_INITIALIZER;}' unless defined(&__GTHREAD_RECURSIVE_MUTEX_INIT);
    }
 elsif(defined(&PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)) {
	eval 'sub __GTHREAD_RECURSIVE_MUTEX_INIT () { &PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;}' unless defined(&__GTHREAD_RECURSIVE_MUTEX_INIT);
    } else {
	eval 'sub __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION () { &__gthread_recursive_mutex_init_function;}' unless defined(&__GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION);
    }
    eval 'sub __GTHREAD_COND_INIT () { &PTHREAD_COND_INITIALIZER;}' unless defined(&__GTHREAD_COND_INIT);
    eval 'sub __GTHREAD_TIME_INIT () {{0,0};}' unless defined(&__GTHREAD_TIME_INIT);
    if(defined(&_GTHREAD_USE_MUTEX_INIT_FUNC)) {
	undef(&__GTHREAD_MUTEX_INIT) if defined(&__GTHREAD_MUTEX_INIT);
    }
    if(defined(&_GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC)) {
	undef(&__GTHREAD_RECURSIVE_MUTEX_INIT) if defined(&__GTHREAD_RECURSIVE_MUTEX_INIT);
	undef(&__GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION) if defined(&__GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION);
	eval 'sub __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION () { &__gthread_recursive_mutex_init_function;}' unless defined(&__GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION);
    }
    if(defined(&_GTHREAD_USE_COND_INIT_FUNC)) {
	undef(&__GTHREAD_COND_INIT) if defined(&__GTHREAD_COND_INIT);
	eval 'sub __GTHREAD_COND_INIT_FUNCTION () { &__gthread_cond_init_function;}' unless defined(&__GTHREAD_COND_INIT_FUNCTION);
    }
    if((defined(&__GXX_WEAK__) ? &__GXX_WEAK__ : undef)  && (defined(&_GLIBCXX_GTHREAD_USE_WEAK) ? &_GLIBCXX_GTHREAD_USE_WEAK : undef)) {
	unless(defined(&__gthrw_pragma)) {
	    eval 'sub __gthrw_pragma {
	        my($pragma) = @_;
    		eval q();
	    }' unless defined(&__gthrw_pragma);
	}
	eval 'sub __gthrw2 {
	    my($name,$name2,$type) = @_;
    	    eval q( &static  &__typeof($type) $name  &__attribute__ (( &__weakref__($name2),  &__copy__ ($type)));  &__gthrw_pragma( &weak $type));
	}' unless defined(&__gthrw2);
	eval 'sub __gthrw_ {
	    my($name) = @_;
    	    eval q( &__gthrw_  $name);
	}' unless defined(&__gthrw_);
    } else {
	eval 'sub __gthrw2 {
	    my($name,$name2,$type) = @_;
    	    eval q();
	}' unless defined(&__gthrw2);
	eval 'sub __gthrw_ {
	    my($name) = @_;
    	    eval q($name);
	}' unless defined(&__gthrw_);
    }
    eval 'sub __gthrw {
        my($name) = @_;
	    eval q( &__gthrw2( &__gthrw_  $name,$name,$name));
    }' unless defined(&__gthrw);
    unless(defined(&__BIONIC__)) {
    }
    if((defined(&_GTHREAD_USE_MUTEX_TIMEDLOCK) ? &_GTHREAD_USE_MUTEX_TIMEDLOCK : undef)) {
    }
    if(defined(&_LIBOBJC) || defined(&_LIBOBJC_WEAK)) {
	if(defined(&_POSIX_PRIORITY_SCHEDULING)) {
	    if(defined(&_POSIX_THREAD_PRIORITY_SCHEDULING)) {
	    }
	}
	if(defined(&_POSIX_THREAD_PRIORITY_SCHEDULING)) {
	}
    }
    if((defined(&__GXX_WEAK__) ? &__GXX_WEAK__ : undef)  && (defined(&_GLIBCXX_GTHREAD_USE_WEAK) ? &_GLIBCXX_GTHREAD_USE_WEAK : undef)) {
	if(defined(&__FreeBSD__) || (defined(&__sun)  && defined(&__svr4__)) || defined(&__NetBSD__)) {
	    eval 'sub __gthread_active_p {
	        my($void) = @_;
    		eval q({  &pthread_mutex_t  &__gthread_active_mutex =  &PTHREAD_MUTEX_INITIALIZER;  &pthread_once_t  &__gthread_active_once =  &PTHREAD_ONCE_INIT; \'int\'  &__gthread_active_latest_value =  &__gthread_active;  &if ( &__builtin_expect ( &__gthread_active_latest_value < 0, 0)) {  &if ( &__gthrw_( &pthread_once)) {  &__gthrw_( &pthread_mutex_lock) (& &__gthread_active_mutex);  &__gthrw_( &pthread_once) (& &__gthread_active_once,  &__gthread_trigger);  &__gthrw_( &pthread_mutex_unlock) (& &__gthread_active_mutex); }  &if ( &__gthread_active < 0)  &__gthread_active = 0;  &__gthread_active_latest_value =  &__gthread_active; }  &__gthread_active_latest_value != 0; });
	    }' unless defined(&__gthread_active_p);
	} else {
	    if(defined(&__GLIBC__)) {
		eval 'sub GTHR_ACTIVE_PROXY () { &__gthrw_( &__pthread_key_create);}' unless defined(&GTHR_ACTIVE_PROXY);
	    }
 elsif(defined (&__BIONIC__)) {
		eval 'sub GTHR_ACTIVE_PROXY () { &__gthrw_( &pthread_create);}' unless defined(&GTHR_ACTIVE_PROXY);
	    } else {
		eval 'sub GTHR_ACTIVE_PROXY () { &__gthrw_( &pthread_cancel);}' unless defined(&GTHR_ACTIVE_PROXY);
	    }
	    eval 'sub __gthread_active_p {
	        my($void) = @_;
    		eval q({ $void * &const  &__gthread_active_ptr = ($void *)  &GTHR_ACTIVE_PROXY;  &__gthread_active_ptr != 0; });
	    }' unless defined(&__gthread_active_p);
	}
    } else {
	if(defined(&__hppa__)  && defined(&__hpux__)) {
	    eval 'sub __gthread_active_p {
	        my($void) = @_;
    		eval q({ \'int\'  &__gthread_active_latest_value =  &__gthread_active; \'size_t\'  &__s;  &if ( &__builtin_expect ( &__gthread_active_latest_value < 0, 0)) {  &pthread_default_stacksize_np (0, & &__s);  &__gthread_active =  &__s ? 1: 0;  &__gthread_active_latest_value =  &__gthread_active; }  &__gthread_active_latest_value != 0; });
	    }' unless defined(&__gthread_active_p);
	} else {
	    eval 'sub __gthread_active_p {
	        my($void) = @_;
    		eval q({ 1; });
	    }' unless defined(&__gthread_active_p);
	}
    }
    if(defined(&_LIBOBJC)) {
	require 'config.ph';
	if(defined(&HAVE_SCHED_H)) {
	    require 'sched.ph';
	}
	if(defined(&_POSIX_PRIORITY_SCHEDULING)) {
	    if(defined(&_POSIX_THREAD_PRIORITY_SCHEDULING)) {
	    }
	}
	if(defined(&_POSIX_PRIORITY_SCHEDULING)) {
	    if(defined(&_POSIX_THREAD_PRIORITY_SCHEDULING)) {
	    }
	}
    } else {
	eval 'sub __gthread_create () {
	    eval q(( &__gthread_t * &__threadid,  &void *(* &__func) ( &void*),  &void * &__args) {  &__gthrw_( &pthread_create) ( &__threadid,  &NULL,  &__func,  &__args); });
	}' unless defined(&__gthread_create);
	eval 'sub __gthread_join {
	    my($__threadid,$__value_ptr) = @_;
    	    eval q({  &__gthrw_( &pthread_join) ($__threadid, $__value_ptr); });
	}' unless defined(&__gthread_join);
	eval 'sub __gthread_detach {
	    my($__threadid) = @_;
    	    eval q({  &__gthrw_( &pthread_detach) ($__threadid); });
	}' unless defined(&__gthread_detach);
	eval 'sub __gthread_equal {
	    my($__t1,$__t2) = @_;
    	    eval q({  &__gthrw_( &pthread_equal) ($__t1, $__t2); });
	}' unless defined(&__gthread_equal);
	eval 'sub __gthread_self {
	    my($void) = @_;
    	    eval q({  &__gthrw_( &pthread_self) (); });
	}' unless defined(&__gthread_self);
	eval 'sub __gthread_yield {
	    my($void) = @_;
    	    eval q({  &__gthrw_( &sched_yield) (); });
	}' unless defined(&__gthread_yield);
	eval 'sub __gthread_once () {
	    eval q(( &__gthread_once_t * &__once,  &void (* &__func) ( &void)) {  &if ( &__gthread_active_p ())  &__gthrw_( &pthread_once) ( &__once,  &__func);  &else -1; });
	}' unless defined(&__gthread_once);
	eval 'sub __gthread_key_create () {
	    eval q(( &__gthread_key_t * &__key,  &void (* &__dtor) ( &void *)) {  &__gthrw_( &pthread_key_create) ( &__key,  &__dtor); });
	}' unless defined(&__gthread_key_create);
	eval 'sub __gthread_key_delete {
	    my($__key) = @_;
    	    eval q({  &__gthrw_( &pthread_key_delete) ($__key); });
	}' unless defined(&__gthread_key_delete);
	eval 'sub __gthread_getspecific {
	    my($__key) = @_;
    	    eval q({  &__gthrw_( &pthread_getspecific) ($__key); });
	}' unless defined(&__gthread_getspecific);
	eval 'sub __gthread_setspecific {
	    my($__key,$__ptr) = @_;
    	    eval q({  &__gthrw_( &pthread_setspecific) ($__key, $__ptr); });
	}' unless defined(&__gthread_setspecific);
	eval 'sub __gthread_mutex_init_function {
	    my($__mutex) = @_;
    	    eval q({  &if ( &__gthread_active_p ())  &__gthrw_( &pthread_mutex_init) ($__mutex,  &NULL); });
	}' unless defined(&__gthread_mutex_init_function);
	eval 'sub __gthread_mutex_destroy {
	    my($__mutex) = @_;
    	    eval q({  &if ( &__gthread_active_p ())  &__gthrw_( &pthread_mutex_destroy) ($__mutex);  &else 0; });
	}' unless defined(&__gthread_mutex_destroy);
	eval 'sub __gthread_mutex_lock {
	    my($__mutex) = @_;
    	    eval q({  &if ( &__gthread_active_p ())  &__gthrw_( &pthread_mutex_lock) ($__mutex);  &else 0; });
	}' unless defined(&__gthread_mutex_lock);
	eval 'sub __gthread_mutex_trylock {
	    my($__mutex) = @_;
    	    eval q({  &if ( &__gthread_active_p ())  &__gthrw_( &pthread_mutex_trylock) ($__mutex);  &else 0; });
	}' unless defined(&__gthread_mutex_trylock);
	if((defined(&_GTHREAD_USE_MUTEX_TIMEDLOCK) ? &_GTHREAD_USE_MUTEX_TIMEDLOCK : undef)) {
	    eval 'sub __gthread_mutex_timedlock {
	        my($__mutex,$__abs_timeout) = @_;
    		eval q({  &if ( &__gthread_active_p ())  &__gthrw_( &pthread_mutex_timedlock) ($__mutex, $__abs_timeout);  &else 0; });
	    }' unless defined(&__gthread_mutex_timedlock);
	}
	eval 'sub __gthread_mutex_unlock {
	    my($__mutex) = @_;
    	    eval q({  &if ( &__gthread_active_p ())  &__gthrw_( &pthread_mutex_unlock) ($__mutex);  &else 0; });
	}' unless defined(&__gthread_mutex_unlock);
	if(!defined( (defined(&PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) ? &PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP : undef)) || defined(&_GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC)) {
	    eval 'sub __gthread_recursive_mutex_init_function {
	        my($__mutex) = @_;
    		eval q({  &if ( &__gthread_active_p ()) {  &pthread_mutexattr_t  &__attr; \'int\'  &__r;  &__r =  &__gthrw_( &pthread_mutexattr_init) (& &__attr);  &if (! &__r)  &__r =  &__gthrw_( &pthread_mutexattr_settype) (& &__attr,  &PTHREAD_MUTEX_RECURSIVE);  &if (! &__r)  &__r =  &__gthrw_( &pthread_mutex_init) ($__mutex, & &__attr);  &if (! &__r)  &__r =  &__gthrw_( &pthread_mutexattr_destroy) (& &__attr);  &__r; } 0; });
	    }' unless defined(&__gthread_recursive_mutex_init_function);
	}
	eval 'sub __gthread_recursive_mutex_lock {
	    my($__mutex) = @_;
    	    eval q({  &__gthread_mutex_lock ($__mutex); });
	}' unless defined(&__gthread_recursive_mutex_lock);
	eval 'sub __gthread_recursive_mutex_trylock {
	    my($__mutex) = @_;
    	    eval q({  &__gthread_mutex_trylock ($__mutex); });
	}' unless defined(&__gthread_recursive_mutex_trylock);
	if((defined(&_GTHREAD_USE_MUTEX_TIMEDLOCK) ? &_GTHREAD_USE_MUTEX_TIMEDLOCK : undef)) {
	    eval 'sub __gthread_recursive_mutex_timedlock {
	        my($__mutex,$__abs_timeout) = @_;
    		eval q({  &__gthread_mutex_timedlock ($__mutex, $__abs_timeout); });
	    }' unless defined(&__gthread_recursive_mutex_timedlock);
	}
	eval 'sub __gthread_recursive_mutex_unlock {
	    my($__mutex) = @_;
    	    eval q({  &__gthread_mutex_unlock ($__mutex); });
	}' unless defined(&__gthread_recursive_mutex_unlock);
	eval 'sub __gthread_recursive_mutex_destroy {
	    my($__mutex) = @_;
    	    eval q({  &__gthread_mutex_destroy ($__mutex); });
	}' unless defined(&__gthread_recursive_mutex_destroy);
	if(defined(&_GTHREAD_USE_COND_INIT_FUNC)) {
	    eval 'sub __gthread_cond_init_function {
	        my($__cond) = @_;
    		eval q({  &if ( &__gthread_active_p ())  &__gthrw_( &pthread_cond_init) ($__cond,  &NULL); });
	    }' unless defined(&__gthread_cond_init_function);
	}
	eval 'sub __gthread_cond_broadcast {
	    my($__cond) = @_;
    	    eval q({  &__gthrw_( &pthread_cond_broadcast) ($__cond); });
	}' unless defined(&__gthread_cond_broadcast);
	eval 'sub __gthread_cond_signal {
	    my($__cond) = @_;
    	    eval q({  &__gthrw_( &pthread_cond_signal) ($__cond); });
	}' unless defined(&__gthread_cond_signal);
	eval 'sub __gthread_cond_wait {
	    my($__cond,$__mutex) = @_;
    	    eval q({  &__gthrw_( &pthread_cond_wait) ($__cond, $__mutex); });
	}' unless defined(&__gthread_cond_wait);
	eval 'sub __gthread_cond_timedwait {
	    my($__cond,$__mutex,$__abs_timeout) = @_;
    	    eval q({  &__gthrw_( &pthread_cond_timedwait) ($__cond, $__mutex, $__abs_timeout); });
	}' unless defined(&__gthread_cond_timedwait);
	eval 'sub __gthread_cond_wait_recursive {
	    my($__cond,$__mutex) = @_;
    	    eval q({  &__gthread_cond_wait ($__cond, $__mutex); });
	}' unless defined(&__gthread_cond_wait_recursive);
	eval 'sub __gthread_cond_destroy {
	    my($__cond) = @_;
    	    eval q({  &__gthrw_( &pthread_cond_destroy) ($__cond); });
	}' unless defined(&__gthread_cond_destroy);
    }
}
1;
