Brian Silverman | 70325d6 | 2015-09-20 17:00:43 -0400 | [diff] [blame] | 1 | # Check whether InterlockedExchange() takes a LONG or a volatile LONG |
| 2 | # as its first argument. InterlockedCompareExchange is a windows |
| 3 | # function; obviously, this macro is useful only for cygwin and mingw, |
| 4 | # and other systems that compile against the windows API. |
| 5 | # |
| 6 | # Apparently the interface for this function is a bit inconsistent. |
| 7 | # Windows likes volatile LONG, but mingw and cygwin don't, at least |
| 8 | # for the versions I'm using. But rather than try to guess who |
| 9 | # supports what, let's just check at configure time. (Note: this |
| 10 | # is an error in C++ but only a warning in C, so we test in the former.) |
| 11 | # |
| 12 | # This function returns 'yes' if the type does not need volatile, |
| 13 | # and defines the symbol INTERLOCKED_EXCHANGE_NONVOLATILE. (This |
| 14 | # is the expected case for mingw and cygwin). It returns 'no', |
| 15 | # and defines no symbol, otherwise. (This is the expected case for |
| 16 | # MSVC.) The return value was sset this way so that we don't need |
| 17 | # to define any symbols on windows, which doesn't run configure. |
| 18 | |
| 19 | AC_DEFUN([AC_INTERLOCKED_EXCHANGE_NONVOLATILE], |
| 20 | [ |
| 21 | AC_MSG_CHECKING(whether first argument to InterlockedExchange omits volatile) |
| 22 | AC_CACHE_VAL(ac_cv_interlocked_exchange_nonvolatile, |
| 23 | [AC_LANG_SAVE |
| 24 | AC_LANG_CPLUSPLUS |
| 25 | AC_TRY_COMPILE([#include <windows.h>], |
| 26 | [volatile LONG once; InterlockedExchange(&once, 1);], |
| 27 | ac_cv_interlocked_exchange_nonvolatile="no", |
| 28 | ac_cv_interlocked_exchange_nonvolatile="yes") |
| 29 | AC_LANG_RESTORE |
| 30 | ]) |
| 31 | if test "$ac_cv_interlocked_exchange_nonvolatile" = "yes"; then |
| 32 | AC_DEFINE(INTERLOCKED_EXCHANGE_NONVOLATILE, 1, |
| 33 | [define if first argument to InterlockedExchange is just LONG]) |
| 34 | fi |
| 35 | AC_MSG_RESULT($ac_cv_interlocked_exchange_nonvolatile) |
| 36 | ]) |