Skip to content

Commit

Permalink
Conditional for SPARC and ARM architectures. Compliments to Marcin Oc…
Browse files Browse the repository at this point in the history
…hab and W-Mark Kubacki
  • Loading branch information
dreamcat4 committed Sep 24, 2009
1 parent d3c30cc commit 53346d9
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ac/fpm_checks.m4
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ AC_DEFUN([AC_FPM_TRACE],
AC_TRY_RUN([
#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64
#if HAVE_INTTYPES_H
#include <inttypes.h>
#else
#include <stdint.h>
#endif
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down
5 changes: 5 additions & 0 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ AC_DEFUN([AC_FPM_TRACE],
AC_TRY_RUN([
#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64
#if HAVE_INTTYPES_H
#include <inttypes.h>
#else
#include <stdint.h>
#endif
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down
56 changes: 55 additions & 1 deletion fpm/fpm_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#ifndef FPM_ATOMIC_H
#define FPM_ATOMIC_H 1

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

#if ( __i386__ || __i386 )
Expand Down Expand Up @@ -57,9 +61,59 @@ static inline atomic_uint_t atomic_cmp_set(atomic_t *lock, atomic_uint_t old, at
return res;
}

#ifdef (__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 (__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

#error unsupported processor. please write a patch and send it to me
#error unsupported architecture. please write a patch and send it in

#endif

Expand Down
5 changes: 5 additions & 0 deletions fpm/fpm_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#if HAVE_INTTYPES_H
#include <inttypes.h>
#else
#include <stdint.h>
#endif

#include <stdio.h>
#include <unistd.h>

Expand Down
48 changes: 48 additions & 0 deletions fpm/fpm_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@
#include "zlog.h"

#ifndef HAVE_SETENV
#ifdef (__sparc__ || __sparc)
int setenv(name, value, clobber)
char *name;
char *value;
int clobber;
{
char *malloc();
char *getenv();
char *cp;

if (clobber == 0 && getenv(name) != 0)
return (0);
if ((cp = malloc(strlen(name) + strlen(value) + 2)) == 0)
return (1);
sprintf(cp, "%s=%s", name, value);
return (putenv(cp));
}
#else
int setenv(char *name, char *value, int overwrite)
{
int name_len = strlen(name);
Expand All @@ -32,6 +50,7 @@ int setenv(char *name, char *value, int overwrite)
return putenv(var);
}
#endif
#endif

#ifndef HAVE_CLEARENV
void clearenv()
Expand All @@ -55,6 +74,35 @@ void clearenv()
}
#endif

#ifndef HAVE_UNSETENV
void unsetenv(const char *name)
{
if(getenv(name)!=NULL)
{
int ct=0;
int del=0;

while(environ[ct] != NULL)
{
if (nvmatch(name, environ[ct]) != 0) del=ct;
ct++;
}
// isn't needed free here??
environ[del]=environ[ct-1];
environ[ct-1]=NULL;
}
}
static char * nvmatch(s1, s2)
register char *s1, *s2;
{
while(*s1 == *s2++)
if(*s1++ == '=')
return(s2);
if(*s1 == '\0' && *(s2-1) == '=')
return(s2);
return(NULL);
}
#endif

int fpm_env_init_child(struct fpm_worker_pool_s *wp)
{
Expand Down
5 changes: 5 additions & 0 deletions fpm/fpm_php_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

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

#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
Expand Down
5 changes: 5 additions & 0 deletions fpm/fpm_trace_pread.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

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


#include "fpm_trace.h"
#include "fpm_process_ctl.h"
Expand Down
5 changes: 5 additions & 0 deletions fpm/xml_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
#ifndef XML_CONFIG_H
#define XML_CONFIG_H 1

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


struct xml_value_parser;

Expand Down

0 comments on commit 53346d9

Please sign in to comment.