Changeset 3591


Ignore:
Timestamp:
Jan 20, 2017, 3:19:49 AM (6 years ago)
Author:
Peter
Message:

fixes #877

Generalize YAT_CXX_RVALUE into YAT_CXX_TRY_CXX11 and use that to
implement new macro YAT_CXX_ATOMIC. Use this macro in configure.ac and
use std::atomic<> conditoionally in RNG singleton.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r3581 r3591  
    9595# if CXX11 is wanted look for rvalue support
    9696yat_have_rvalue=no
     97yat_have_atomic=no
    9798AS_VAR_IF([with_cxx11], [no], [], [
    9899  YAT_CXX_RVALUE([yat_have_rvalue=yes
    99100                  AC_DEFINE([YAT_HAVE_RVALUE], [1],
    100101                            [Define if compiler support rvalues])])
     102  YAT_CXX_ATOMIC([yat_have_atomic=yes
     103                  AC_DEFINE([YAT_HAVE_ATOMIC], [1],
     104                            [Define if compiler support std::atomic])])
    101105])
    102106
     
    655659  With Bam Support:     $with_htslib
    656660  With Rvalue Support:  $yat_have_rvalue
     661  With atomic Support:  $yat_have_atomic
    657662
    658663Options used to compile and link:
  • trunk/m4/yat_cxx11.m4

    r3590 r3591  
    77# SYNOPSIS
    88#
     9#   YAT_CXX_ATOMIC([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
    910#   YAT_CXX_RVALUE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
    1011#
     
    3738#
    3839
     40# YAT_CXX_ATOMIC([action-if-found], [action-if-not-found])
     41#
     42# Test whether $CXX supports std::atomic. If not, try turning on
     43# support with a number of different switches. If a successful switch
     44# is found invoke shell action-if-found; else issue
     45# action-if-not-found.
     46AC_DEFUN([YAT_CXX_ATOMIC],
     47[
     48YAT_CXX_TRY_CXX11([atomic],
     49  [@%:@include <atomic>],
     50  [std::atomic<bool> ready(false);],
     51  [$1], [$2])
     52])
     53
     54
     55# YAT_CXX_RVALUE([action-if-found], [action-if-not-found])
     56#
     57# Test whether $CXX supports rvalue. If not, try turning on support
     58# with a number of different switches. If a successful switch is found
     59# invoke shell action-if-found; else issue action-if-not-found.
    3960AC_DEFUN([YAT_CXX_RVALUE],
    40 [AC_MSG_CHECKING([for $CXX option to enable rvalue])
    41 AC_CACHE_VAL([yat_cv_cxx_rvalue],
    42   [yat_cv_cxx_rvalue=no
    43    yat_cxx_rvalue_save_CXX=$CXX
     61[
     62YAT_CXX_TRY_CXX11([rvalue], [ dnl header
     63  @%:@include <utility>
     64
     65  class MyClass
     66  {
     67  public:
     68    MyClass(void);
     69    MyClass(const MyClass&); // copy constructor
     70    MyClass(MyClass&&); // move constructor
     71    MyClass& operator=(const MyClass&); // copy assignment
     72    MyClass& operator=(MyClass&&); // move assignment
     73  };
     74  ],[ dnl body
     75  MyClass mc;
     76  MyClass mc2 = std::move(mc);
     77  ], [# action
     78  $1
     79  ], [ # action if not found
     80  $2
     81  ])
     82]) # YAT_CXX_RVALUE
     83
     84# YAT_CXX_TRY_CXX11([feature], [header], [body], [action-if-found],
     85#                   [action-if-not-found])
     86#
     87AC_DEFUN([YAT_CXX_TRY_CXX11],
     88[AS_VAR_PUSHDEF([my_CACHE], [yat_cv_cxx_$1])dnl
     89AC_CACHE_CHECK([for $CXX option to enable $1],
     90  [my_CACHE],
     91  [my_CACHE=no
     92   AS_VAR_PUSHDEF([my_save_CXX], [yat_cxx_$1_save_CXX])dnl
     93   my_save_CXX="$CXX"
    4494# From autoconf 'c.m4' we have
    4595# GCC -std=c++11 -std=c++0x
     
    52102# but first we try with empty string, hoping compiler is modern.
    53103   for yat_arg in '' -std=c++11 -std=c++0x -qlanglvl=stdcxx11 -AA +std=c++11 "-h std=c++11" ; do
    54      CXX="$yat_cxx_rvalue_save_CXX $yat_arg"
    55      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([YAT_CXX_RVALUE_HEADER],
    56                                         [YAT_CXX_RVALUE_BODY])],
    57                        [yat_cv_cxx_rvalue="$yat_arg"],
     104     CXX="$my_save_CXX $yat_arg"
     105     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
     106                       [my_CACHE="$yat_arg"],
    58107                       [])
    59      AS_IF([test x"$yat_cv_cxx_rvalue" != x"no"], [break])
     108     AS_VAR_IF([my_CACHE], [no], [], [break])
    60109   done
    61    CXX="$yat_cxx_rvalue_save_CXX"
     110   # restore CXX
     111   CXX="$my_save_CXX"
     112
     113   AS_CASE([x"$my_CACHE"],
     114           [x], [my_CACHE="none needed"],
     115           [x"no"], [my_CACHE=unsupported])
     116
     117   AS_VAR_POPDEF([my_save_CXX])
    62118  ])
    63119
    64 AS_CASE([x"$yat_cv_cxx_rvalue"],
    65         [x], [AC_MSG_RESULT([none needed])],
    66         [x"no"], [AC_MSG_RESULT([unsupported])],
    67         [CXX="$CXX $yat_cv_cxx_rvalue"
    68          AC_MSG_RESULT([$yat_cv_cxx_rvalue])])
    69 AS_VAR_IF([yat_cv_cxx_rvalue], [no], [$2], [$1])
     120AS_CASE([$my_CACHE],
     121        ["none needed"], [$4],
     122        [unsupported], [$5],
     123        [CXX="$CXX $my_CACHE"
     124         $4])
     125AS_VAR_POPDEF([my_CACHE])
    70126])
    71 
    72 
    73 AC_DEFUN([YAT_CXX_RVALUE_HEADER],
    74 [
    75 @%:@include <utility>
    76 
    77 class MyClass
    78 {
    79 public:
    80   MyClass(void);
    81   MyClass(const MyClass&); // copy constructor
    82   MyClass(MyClass&&); // move constructor
    83   MyClass& operator=(const MyClass&); // copy assignment
    84   MyClass& operator=(MyClass&&); // move assignment
    85 };
    86 ])
    87 
    88 
    89 AC_DEFUN([YAT_CXX_RVALUE_BODY],
    90 [
    91   MyClass mc;
    92   MyClass mc2 = std::move(mc);
    93 ])
  • trunk/yat/random/random.cc

    r3579 r3591  
    3030
    3131#include <cassert>
     32#include <cstddef>
    3233#include <cstring>
    3334#include <fstream>
     
    3839namespace random {
    3940
     41#ifdef YAT_HAVE_ATOMIC
     42  std::atomic<RNG*> RNG::instance_ { nullptr };
     43#else
    4044  RNG* RNG::instance_=NULL;
     45#endif
    4146  boost::mutex RNG::init_mutex_;
    4247
  • trunk/yat/random/random.h

    r3579 r3591  
    2424*/
    2525
     26#include "yat/utility/config_public.h"
     27
    2628#include "yat/statistics/Histogram.h"
    2729#include "yat/utility/deprecate.h"
     
    3941
    4042#include <algorithm>
     43#ifdef YAT_HAVE_ATOMIC
     44#include <atomic>
     45#endif
    4146#include <string>
    4247#include <vector>
     
    193198    void rng_alloc(void) const;
    194199
     200#ifdef YAT_HAVE_ATOMIC
     201    static std::atomic<RNG*> instance_;
     202#else
    195203    static RNG* instance_;
     204#endif
    196205    // holds one gsl_rng per thread. Access through rng(void) so a
    197206    // gsl_rng is allocated if necessary.
  • trunk/yat/utility/config_public.h.in

    r3581 r3591  
    5858/// Don't turn on cxx11 features if user explicitely turned off cxx11.
    5959#ifndef YAT_WITHOUT_CXX11
    60 /// Define if compiler support rvalues */
     60/// Define if compiler supports rvalues */
    6161#undef YAT_HAVE_RVALUE
     62/// Define if compiler supports atomic */
     63#undef YAT_HAVE_ATOMIC
    6264#endif
    6365
Note: See TracChangeset for help on using the changeset viewer.