This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Re: [PATCH] PR libstdc++/86846 Alternative to pointer-width atomics


On 14/08/18 14:13, Jonathan Wakely wrote:
Define a class using std::mutex for when std::atomic<memory_resource*>
cannot be used to implement the default memory resource.

When std::mutex constructor is not constexpr the constant_init trick
won't work, so just define a global and use init_priority for it. The
compiler warns about using reserved priority, so put the definition in a
header file using #pragma GCC system_header to suppress the warning.

     PR libstdc++/86846
     * src/c++17/default_resource.h: New file, defining default_res.
     * src/c++17/memory_resource.cc [ATOMIC_POINTER_LOCK_FREE != 2]
     (atomic_mem_res): Define alternative for atomic<memory_resource*>
     using a mutex instead of atomics.

Tested x86_64-linux, committed to trunk.


build fails with arm-none-eabi target:

Making all in c++17
make[4]: Entering directory '/B/arm-none-eabi/libstdc++-v3/src/c++17'
/bin/sh ../../libtool --tag CXX --tag disable-shared --mode=compile /B/./gcc/xgcc -shared-libgcc -B/B/./gcc -nostdinc++ -L/B/arm-none-eabi/libstdc++-v3/src -L/B/arm-none-eabi/libstdc++-v3/src/.libs -L/B/arm-none-eabi/libstdc++-v3/libsupc++/.libs -B/P/arm-none-eabi/bin/ -B/P/arm-none-eabi/lib/ -isystem /P/arm-none-eabi/include -isystem /P/arm-none-eabi/sys-include -I/S/libstdc++-v3/../libgcc -I/B/arm-none-eabi/libstdc++-v3/include/arm-none-eabi -I/B/arm-none-eabi/libstdc++-v3/include -I/S/libstdc++-v3/libsupc++ -std=gnu++17 -fno-implicit-templates -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi=2 -fdiagnostics-show-location=once -ffunction-sections -fdata-sections -frandom-seed=memory_resource.lo -g -ffunction-sections -fdata-sections -O2 -c -o memory_resource.lo /S/libstdc++-v3/src/c++17/memory_resource.cc libtool: compile: /B/./gcc/xgcc -shared-libgcc -B/B/./gcc -nostdinc++ -L/B/arm-none-eabi/libstdc++-v3/src -L/B/arm-none-eabi/libstdc++-v3/src/.libs -L/B/arm-none-eabi/libstdc++-v3/libsupc++/.libs -B/P/arm-none-eabi/bin/ -B/P/arm-none-eabi/lib/ -isystem /P/arm-none-eabi/include -isystem /P/arm-none-eabi/sys-include -I/S/libstdc++-v3/../libgcc -I/B/arm-none-eabi/libstdc++-v3/include/arm-none-eabi -I/B/arm-none-eabi/libstdc++-v3/include -I/S/libstdc++-v3/libsupc++ -std=gnu++17 -fno-implicit-templates -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi=2 -fdiagnostics-show-location=once -ffunction-sections -fdata-sections -frandom-seed=memory_resource.lo -g -ffunction-sections -fdata-sections -O2 -c /S/libstdc++-v3/src/c++17/memory_resource.cc -o memory_resource.o
/S/libstdc++-v3/src/c++17/memory_resource.cc:102:7: error: 'mutex' does not name a type
102 |       mutex mx;
    |       ^~~~~
/S/libstdc++-v3/src/c++17/memory_resource.cc: In member function 'std::pmr::memory_resource* std::pmr::{anonymous}::atomic_mem_res::load()':
/S/libstdc++-v3/src/c++17/memory_resource.cc:107:13: error: 'mutex' was not declared in this scope
107 |  lock_guard<mutex> lock(mx);
    |             ^~~~~
/S/libstdc++-v3/src/c++17/memory_resource.cc:107:18: error: template argument 1 is invalid
107 |  lock_guard<mutex> lock(mx);
    |                  ^
/S/libstdc++-v3/src/c++17/memory_resource.cc:107:25: error: 'mx' was not declared in this scope
107 |  lock_guard<mutex> lock(mx);
    |                         ^~
/S/libstdc++-v3/src/c++17/memory_resource.cc:107:25: note: suggested alternative: 'max'
107 |  lock_guard<mutex> lock(mx);
    |                         ^~
    |                         max
/S/libstdc++-v3/src/c++17/memory_resource.cc:107:20: warning: unused variable 'lock' [-Wunused-variable]
107 |  lock_guard<mutex> lock(mx);
    |                    ^~~~
/S/libstdc++-v3/src/c++17/memory_resource.cc: In member function 'std::pmr::memory_resource* std::pmr::{anonymous}::atomic_mem_res::exchange(std::pmr::memory_resource*)':
/S/libstdc++-v3/src/c++17/memory_resource.cc:113:13: error: 'mutex' was not declared in this scope
113 |  lock_guard<mutex> lock(mx);
    |             ^~~~~
/S/libstdc++-v3/src/c++17/memory_resource.cc:113:18: error: template argument 1 is invalid
113 |  lock_guard<mutex> lock(mx);
    |                  ^
/S/libstdc++-v3/src/c++17/memory_resource.cc:113:25: error: 'mx' was not declared in this scope
113 |  lock_guard<mutex> lock(mx);
    |                         ^~
/S/libstdc++-v3/src/c++17/memory_resource.cc:113:25: note: suggested alternative: 'max'
113 |  lock_guard<mutex> lock(mx);
    |                         ^~
    |                         max
/S/libstdc++-v3/src/c++17/memory_resource.cc:113:20: warning: unused variable 'lock' [-Wunused-variable]
113 |  lock_guard<mutex> lock(mx);
    |                    ^~~~
make[4]: *** [Makefile:471: memory_resource.lo] Error 1
make[4]: Leaving directory '/B/arm-none-eabi/libstdc++-v3/src/c++17'
make[3]: *** [Makefile:643: all-recursive] Error 1
make[3]: Leaving directory '/B/arm-none-eabi/libstdc++-v3/src'
make[2]: *** [Makefile:510: all-recursive] Error 1
make[2]: Leaving directory '/B/arm-none-eabi/libstdc++-v3'
make[1]: *** [Makefile:417: all] Error 2
make[1]: Leaving directory '/B/arm-none-eabi/libstdc++-v3'
make: *** [Makefile:10864: all-target-libstdc++-v3] Error 2
make: *** Waiting for unfinished jobs....


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