view src/os/unix/ngx_atomic.h @ 479:c52408583801 release-0.1.14

nginx-0.1.14-RELEASE import *) Feature: the autoconfiguration directives: --http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and --http-fastcgi-temp-path=PATH *) Change: the directory name for the temporary files with the client request body is specified by directive client_body_temp_path, by default it is <prefix>/client_body_temp. *) Feature: the ngx_http_fastcgi_module and the directives: fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params, fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout, fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers, fastcgi_busy_buffers_size, fastcgi_temp_path, fastcgi_max_temp_file_size, fastcgi_temp_file_write_size, fastcgi_next_upstream, and fastcgi_x_powered_by. *) Bugfix: the "[alert] zero size buf" error; the bug had appeared in 0.1.3. *) Change: the URI must be specified after the host name in the proxy_pass directive. *) Change: the %3F symbol in the URI was considered as the argument string start. *) Feature: the unix domain sockets support in the ngx_http_proxy_module. *) Feature: the ssl_engine and ssl_ciphers directives. Thanks to Sergey Skvortsov for SSL-accelerator.
author Igor Sysoev <igor@sysoev.ru>
date Tue, 18 Jan 2005 13:03:58 +0000
parents 42d11f017717
children 975f62e77f02
line wrap: on
line source


/*
 * Copyright (C) Igor Sysoev
 */


#ifndef _NGX_ATOMIC_H_INCLUDED_
#define _NGX_ATOMIC_H_INCLUDED_


#include <ngx_config.h>
#include <ngx_core.h>


#if ( __i386__ || __amd64__ )

#define NGX_HAVE_ATOMIC_OPS  1

typedef volatile uint32_t  ngx_atomic_t;

#if (NGX_SMP)
#define NGX_SMP_LOCK  "lock;"
#else
#define NGX_SMP_LOCK
#endif


static ngx_inline uint32_t ngx_atomic_inc(ngx_atomic_t *value)
{
    uint32_t  old;

    __asm__ volatile (

        NGX_SMP_LOCK
    "   xaddl  %0, %2;   "
    "   incl   %0;       "

    : "=q" (old) : "0" (1), "m" (*value));

    return old;
}


#if 0

static ngx_inline uint32_t ngx_atomic_dec(ngx_atomic_t *value)
{
    uint32_t  old;

    __asm__ volatile (

        NGX_SMP_LOCK
    "   xaddl  %0, %1;   "
    "   decl   %0;       "

    : "=q" (old) : "0" (-1), "m" (*value));

    return old;
}

#endif


static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock,
                                              ngx_atomic_t old,
                                              ngx_atomic_t set)
{
    uint32_t  res;

    __asm__ volatile (

        NGX_SMP_LOCK
    "   cmpxchgl  %3, %1;   "
    "   setz      %%al;     "
    "   movzbl    %%al, %0; "

    : "=a" (res) : "m" (*lock), "a" (old), "q" (set));

    return res;
}


#elif ( __sparc__ )

#define NGX_HAVE_ATOMIC_OPS  1

typedef volatile uint32_t  ngx_atomic_t;


static ngx_inline uint32_t ngx_atomic_inc(ngx_atomic_t *value)
{
    uint32_t  old, new, res;

    old = *value;

    for ( ;; ) {

        new = old + 1;
        res = new;

        __asm__ volatile (

        "casa [%1] 0x80, %2, %0"

        : "+r" (res) : "r" (value), "r" (old));

        if (res == old) {
            return new;
        }

        old = res;
    }
}


static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock,
                                              ngx_atomic_t old,
                                              ngx_atomic_t set)
{
    uint32_t  res = (uint32_t) set;

    __asm__ volatile (

    "casa [%1] 0x80, %2, %0"

    : "+r" (res) : "r" (lock), "r" (old));

    return (res == old);
}

#else

#define NGX_HAVE_ATOMIC_OPS  0

typedef volatile uint32_t  ngx_atomic_t;

#define ngx_atomic_inc(x)  ++(*(x));

static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock,
                                              ngx_atomic_t old,
                                              ngx_atomic_t set)
{
     return 1;
}

#endif


void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin);

#define ngx_trylock(lock)  (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1))
#define ngx_unlock(lock)    *(lock) = 0


#endif /* _NGX_ATOMIC_H_INCLUDED_ */