src/os/win32/ngx_atomic.h - nginx source code

Data types defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_ATOMIC_H_INCLUDED_
  6. #define _NGX_ATOMIC_H_INCLUDED_


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


  9. #define NGX_HAVE_ATOMIC_OPS   1

  10. typedef int32_t                     ngx_atomic_int_t;
  11. typedef uint32_t                    ngx_atomic_uint_t;
  12. typedef volatile ngx_atomic_uint_t  ngx_atomic_t;
  13. #define NGX_ATOMIC_T_LEN            (sizeof("-2147483648") - 1)


  14. #if defined( __WATCOMC__ ) || defined( __BORLANDC__ ) || defined(__GNUC__)    \
  15.     || ( _MSC_VER >= 1300 )

  16. /* the new SDK headers */

  17. #define ngx_atomic_cmp_set(lock, old, set)                                    \
  18.     ((ngx_atomic_uint_t) InterlockedCompareExchange((long *) lock, set, old)  \
  19.                          == old)

  20. #else

  21. /* the old MS VC6.0SP2 SDK headers */

  22. #define ngx_atomic_cmp_set(lock, old, set)                                    \
  23.     (InterlockedCompareExchange((void **) lock, (void *) set, (void *) old)   \
  24.      == (void *) old)

  25. #endif


  26. #define ngx_atomic_fetch_add(p, add) InterlockedExchangeAdd((long *) p, add)


  27. #define ngx_memory_barrier()


  28. #if defined( __BORLANDC__ ) || ( __WATCOMC__ < 1230 )

  29. /*
  30. * Borland C++ 5.5 (tasm32) and Open Watcom C prior to 1.3
  31. * do not understand the "pause" instruction
  32. */

  33. #define ngx_cpu_pause()
  34. #else
  35. #define ngx_cpu_pause()       __asm { pause }
  36. #endif


  37. void ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin);

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


  40. #endif /* _NGX_ATOMIC_H_INCLUDED_ */