[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@18.118.1.63: ~ $
	/* $Id: fpm_atomic.h,v 1.3 2008/09/18 23:34:11 anight Exp $ */
	/* (c) 2007,2008 Andrei Nigmatulin */

#ifndef FPM_ATOMIC_H
#define FPM_ATOMIC_H 1

#if HAVE_INTTYPES_H
# include <inttypes.h>
#else
# include <stdint.h>
#endif
#include <sched.h>

#ifdef HAVE_BUILTIN_ATOMIC

/**
 * all the cases below (as provided by upstream) define:
 * word as atomic_int_t, and
 * unsigned word as atomic_uint_t
 * and only use volatile atomic_uint_t as atomic_t
 */

typedef volatile unsigned long atomic_t;
#define atomic_cmp_set(a,b,c) __sync_bool_compare_and_swap(a,b,c)

#elif ( __i386__ || __i386 )

typedef int32_t                     atomic_int_t;
typedef uint32_t                    atomic_uint_t;
typedef volatile atomic_uint_t      atomic_t;


static inline atomic_int_t atomic_fetch_add(atomic_t *value, atomic_int_t add) /* {{{ */
{
	__asm__ volatile ( "lock;" "xaddl %0, %1;" :
		"+r" (add) : "m" (*value) : "memory");

	return add;
}
/* }}} */

static inline atomic_uint_t atomic_cmp_set(atomic_t *lock, atomic_uint_t old, atomic_uint_t set) /* {{{ */
{
	unsigned char res;

	__asm__ volatile ( "lock;" "cmpxchgl %3, %1;" "sete %0;" :
		"=a" (res) : "m" (*lock), "a" (old), "r" (set) : "memory");

	return res;
}
/* }}} */

#elif ( __amd64__ || __amd64 || __x86_64__ )

typedef int64_t                     atomic_int_t;
typedef uint64_t                    atomic_uint_t;
typedef volatile atomic_uint_t      atomic_t;

static inline atomic_int_t atomic_fetch_add(atomic_t *value, atomic_int_t add) /* {{{ */
{
	__asm__ volatile ( "lock;" "xaddq %0, %1;" :
		"+r" (add) : "m" (*value) : "memory");

	return add;
}
/* }}} */

static inline atomic_uint_t atomic_cmp_set(atomic_t *lock, atomic_uint_t old, atomic_uint_t set) /* {{{ */
{
	unsigned char res;

	__asm__ volatile ( "lock;" "cmpxchgq %3, %1;" "sete %0;" :
		"=a" (res) : "m" (*lock), "a" (old), "r" (set) : "memory");

	return res;
}
/* }}} */

#if (__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))

#elif ( __arm__ || __arm ) /* W-Mark Kubacki */

#if (__arch64__ || __arch64)
typedef int64_t                     atomic_int_t;
typedef uint64_t                    atomic_uint_t;
#else
typedef int32_t                     atomic_int_t;
typedef uint32_t                    atomic_uint_t;
#endif

#define atomic_cmp_set(a,b,c) __sync_bool_compare_and_swap(a,b,c)

#endif /* defined (__GNUC__) &&... */

#elif ( __sparc__ || __sparc ) /* Marcin Ochab */

#if (__sparcv9 || __sparcv9__)

#if (__arch64__ || __arch64)
typedef uint64_t                    atomic_uint_t;
typedef volatile atomic_uint_t      atomic_t;

static inline int atomic_cas_64(atomic_t *lock, atomic_uint_t old, atomic_uint_t new) /* {{{ */
{
	__asm__ __volatile__("casx [%2], %3, %0 " : "=&r"(new)  : "0"(new), "r"(lock), "r"(old): "memory");

	return new;
}
/* }}} */

static inline atomic_uint_t atomic_cmp_set(atomic_t *lock, atomic_uint_t old, atomic_uint_t set) /* {{{ */
{
	return (atomic_cas_64(lock, old, set)==old);
}
/* }}} */
#else
typedef uint32_t                    atomic_uint_t;
typedef volatile atomic_uint_t      atomic_t;

static inline int atomic_cas_32(atomic_t *lock, atomic_uint_t old, atomic_uint_t new) /* {{{ */
{
	__asm__ __volatile__("cas [%2], %3, %0 " : "=&r"(new)  : "0"(new), "r"(lock), "r"(old): "memory");

	return new;
}
/* }}} */

static inline atomic_uint_t atomic_cmp_set(atomic_t *lock, atomic_uint_t old, atomic_uint_t set) /* {{{ */
{
	return (atomic_cas_32(lock, old, set)==old);
}
/* }}} */
#endif

#else /* #if (__sparcv9 || __sparcv9__) */
#error Sparc v8 and predecessors are not and will not be supported (see bug report 53310)
#endif /* #if (__sparcv9 || __sparcv9__) */

#else

#error Unsupported processor. Please open a bug report (bugs.php.net).

#endif

static inline int fpm_spinlock(atomic_t *lock, int try_once) /* {{{ */
{
	if (try_once) {
		return atomic_cmp_set(lock, 0, 1) ? 1 : 0;
	}

	for (;;) {

		if (atomic_cmp_set(lock, 0, 1)) {
			break;
		}

		sched_yield();
	}

	return 1;
}
/* }}} */

#define fpm_unlock(lock) lock = 0

#endif


Filemanager

Name Type Size Permission Actions
events Folder 0755
fastcgi.c File 25.94 KB 0644
fastcgi.h File 4.47 KB 0644
fpm.c File 2.84 KB 0644
fpm.h File 1.13 KB 0644
fpm_arrays.h File 1.82 KB 0644
fpm_atomic.h File 3.95 KB 0644
fpm_children.c File 10.99 KB 0644
fpm_children.h File 873 B 0644
fpm_cleanup.c File 849 B 0644
fpm_cleanup.h File 519 B 0644
fpm_clock.c File 2.23 KB 0644
fpm_clock.h File 239 B 0644
fpm_conf.c File 49.14 KB 0644
fpm_conf.h File 2.43 KB 0644
fpm_env.c File 5.39 KB 0644
fpm_env.h File 491 B 0644
fpm_events.c File 11.67 KB 0644
fpm_events.h File 1.59 KB 0644
fpm_log.c File 11.53 KB 0644
fpm_log.h File 300 B 0644
fpm_main.c File 62.74 KB 0644
fpm_php.c File 6.42 KB 0644
fpm_php.h File 1.23 KB 0644
fpm_php_trace.c File 3.49 KB 0644
fpm_process_ctl.c File 13.65 KB 0644
fpm_process_ctl.h File 1.23 KB 0644
fpm_request.c File 8.01 KB 0644
fpm_request.h File 1.18 KB 0644
fpm_scoreboard.c File 7.84 KB 0644
fpm_scoreboard.h File 2.5 KB 0644
fpm_shm.c File 1.23 KB 0644
fpm_shm.h File 263 B 0644
fpm_signals.c File 4.72 KB 0644
fpm_signals.h File 315 B 0644
fpm_sockets.c File 11.39 KB 0644
fpm_sockets.h File 1006 B 0644
fpm_status.c File 13.7 KB 0644
fpm_status.h File 1.03 KB 0644
fpm_stdio.c File 7.36 KB 0644
fpm_stdio.h File 569 B 0644
fpm_str.h File 483 B 0644
fpm_systemd.c File 3.11 KB 0644
fpm_systemd.h File 275 B 0644
fpm_trace.c File 641 B 0644
fpm_trace.h File 378 B 0644
fpm_trace_ptrace.c File 1.6 KB 0644
fpm_unix.c File 19.23 KB 0644
fpm_unix.h File 518 B 0644
fpm_worker_pool.c File 1.57 KB 0644
fpm_worker_pool.h File 1.23 KB 0644
zlog.c File 4.47 KB 0644
zlog.h File 978 B 0644