This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[libstdc++/65033] Give alignment info to libatomic


When we fixed PR54005, making sure that atomic_is_lock_free returns the same
value for all objects of a given type, we probably should have changed the
interface so that we would pass size and alignment rather than size and object
pointer.

Instead, we decided that passing null for the object pointer would be
sufficient.  But as this PR shows, we really do need to take alignment into
account.

The following patch constructs a fake object pointer that is maximally
misaligned.  This allows the interface to both the builtin and to libatomic to
remain unchanged.  Which probably makes this back-portable to maintenance
releases as well.

I believe that for all of our current systems, size_t == uintptr_t, so the
reinterpret_cast ought not generate warnings.

The test case is problematic, as there's currently no good place to put it.
The libstdc++ testsuite doesn't have the libatomic library path configured, and
the libatomic testsuite doesn't have the libstdc++ include paths configured.
Yet another example where we really need an install tree for testing.  Thoughts?


Ok?


r~

Attachment: z
Description: Text document

// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// { dg-require-atomic-builtins "" }
// { dg-options "-std=gnu++11" }

#include <atomic>
#include <testsuite_hooks.h>

struct S2 { char a[2]; };
struct S3 { char a[3]; };

int
main()
{
  std::atomic<S2> s2;
  std::atomic<S3> s3;

  VERIFY( s2.is_lock_free() == false );
  VERIFY( s3.is_lock_free() == false );
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]