mirror of https://github.com/ARMmbed/mbed-os.git
Callback updates
* Optimise clearing by adding `nullptr` overload. This overload means `Callback(NULL)` or `Callback(0)` will no longer work; users must use `Callback(nullptr)` or `Callback()`. * Optimise clearing by not clearing storage - increases code size of comparison, but that is extremely rare. * Reduce ROM used by trivial functors - share copy/destroy code. * Config option to force trivial functors - major ROM saving by eliminating the "operations" table. * Config option to eliminate comparison altogether - minor ROM saving by eliminating zero padding. * Conform more to `std::function` API.pull/12036/head
parent
ea3761f38d
commit
bb733f1ee8
|
@ -58,7 +58,11 @@ void test_Transaction_init()
|
|||
TEST_ASSERT_EQUAL(rx_buffer_size, test_transaction.get_transaction()->rx_length);
|
||||
TEST_ASSERT_EQUAL(event_id, test_transaction.get_transaction()->event);
|
||||
TEST_ASSERT_EQUAL(word_width, test_transaction.get_transaction()->width);
|
||||
TEST_ASSERT_EQUAL(callback, test_transaction.get_transaction()->callback);
|
||||
#if MBED_CONF_PLATFORM_CALLBACK_COMPARABLE
|
||||
TEST_ASSERT_TRUE(callback == test_transaction.get_transaction()->callback);
|
||||
#else
|
||||
TEST_ASSERT_FALSE(nullptr == test_transaction.get_transaction()->callback)
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Test Transaction class - creation without initialisation
|
||||
|
|
|
@ -102,8 +102,6 @@ char emac_if_get_trace_level();
|
|||
|
||||
void emac_if_trace_to_ascii_hex_dump(const char *prefix, int len, char *data);
|
||||
|
||||
void emac_if_link_state_change_cb(void *data, bool up);
|
||||
|
||||
unsigned char *emac_if_get_own_addr(void);
|
||||
|
||||
int emac_if_get_mtu_size();
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_PLATFORM_CALLBACK_COMPARABLE")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/netsocket/SocketAddress.cpp
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2019 ARM Limited
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MSTD_NEW_
|
||||
#define MSTD_NEW_
|
||||
|
||||
/* <mstd_new>
|
||||
*
|
||||
* - includes toolchain's <new>
|
||||
* - For all toolchains, C++17 backports:
|
||||
* - mstd::launder
|
||||
*/
|
||||
|
||||
#include <new>
|
||||
#if __cpp_lib_launder < 201606
|
||||
#include <type_traits>
|
||||
#endif
|
||||
|
||||
namespace mstd
|
||||
{
|
||||
using std::nothrow_t;
|
||||
using std::nothrow;
|
||||
using std::new_handler;
|
||||
using std::set_new_handler;
|
||||
|
||||
#if __cpp_lib_launder >= 201606
|
||||
using std::launder;
|
||||
#else
|
||||
template <typename T>
|
||||
constexpr T *launder(T *p) noexcept
|
||||
{
|
||||
static_assert(!std::is_function<T>::value && !std::is_void<T>::value, "Can only launder complete object types");
|
||||
#if defined __clang__ || __GNUC__ >= 9
|
||||
return __builtin_launder(p);
|
||||
#else
|
||||
return p;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace mstd
|
||||
|
||||
#endif // MSTD_NEW_
|
|
@ -300,20 +300,6 @@ struct remove_cvref : type_identity<std::remove_cv_t<std::remove_reference_t<T>>
|
|||
template <typename T>
|
||||
using remove_cvref_t = typename remove_cvref<T>::type;
|
||||
|
||||
/* C++20 unwrap_reference */
|
||||
template <typename T>
|
||||
struct unwrap_reference : type_identity<T> { };
|
||||
template <typename T>
|
||||
struct unwrap_reference<std::reference_wrapper<T>> : type_identity<T &> { };
|
||||
template <typename T>
|
||||
using unwrap_reference_t = typename unwrap_reference<T>::type;
|
||||
|
||||
/* C++20 unwrap_ref_decay */
|
||||
template <typename T>
|
||||
struct unwrap_ref_decay : unwrap_reference<std::decay_t<T>> { };
|
||||
template <typename T>
|
||||
using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type;
|
||||
|
||||
}
|
||||
|
||||
#if __cpp_lib_invoke < 201411
|
||||
|
|
|
@ -141,6 +141,7 @@ void NetworkInterface::add_event_listener(mbed::Callback<void(nsapi_event_t, int
|
|||
attach(mbed::callback(&call_all_event_listeners, this));
|
||||
}
|
||||
|
||||
#if MBED_CONF_PLATFORM_CALLBACK_COMPARABLE
|
||||
void NetworkInterface::remove_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb)
|
||||
{
|
||||
iface_eventlist_t *event_list = get_interface_event_list_head();
|
||||
|
@ -152,6 +153,7 @@ void NetworkInterface::remove_event_listener(mbed::Callback<void(nsapi_event_t,
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
NetworkInterface::~NetworkInterface()
|
||||
{
|
||||
|
|
|
@ -352,6 +352,7 @@ public:
|
|||
*/
|
||||
void add_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
|
||||
|
||||
#if MBED_CONF_PLATFORM_CALLBACK_COMPARABLE
|
||||
/** Remove event listener from interface.
|
||||
*
|
||||
* Remove previously added callback from the handler list.
|
||||
|
@ -359,6 +360,7 @@ public:
|
|||
* @param status_cb The callback to unregister.
|
||||
*/
|
||||
void remove_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
|
||||
#endif
|
||||
|
||||
/** Get the connection status.
|
||||
*
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -123,6 +123,14 @@
|
|||
"help": "The maximum CThunk objects used at the same time. This must be greater than 0 and less 256",
|
||||
"value": 8
|
||||
},
|
||||
"callback-nontrivial": {
|
||||
"help": "Enables support for non-trivial callable objects in Callback. Can be disabled to save ROM if no-one is using non-trivial types. Changing this value may cause incompatibility with pre-built binaries.",
|
||||
"value": true
|
||||
},
|
||||
"callback-comparable": {
|
||||
"help": "Enables support for comparing two Callbacks. See notes on operator== for limitations. Can be disabled to save ROM if not required.",
|
||||
"value": true
|
||||
},
|
||||
"crash-capture-enabled": {
|
||||
"help": "Enables crash context capture when the system enters a fatal error/crash.",
|
||||
"value": false
|
||||
|
|
|
@ -34,11 +34,8 @@
|
|||
*/
|
||||
#ifndef __error_t_defined
|
||||
#define __error_t_defined 1
|
||||
#include <errno.h>
|
||||
#undef __error_t_defined
|
||||
#else
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
/* We can get the following standard types from sys/types for gcc, but we
|
||||
* need to define the types ourselves for the other compilers that normally
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
|
||||
#include "platform/mbed_preprocessor.h"
|
||||
|
||||
/* Workaround to prevent GCC library defining error_t, which can collide */
|
||||
#ifndef __error_t_defined
|
||||
#define __error_t_defined 1
|
||||
#endif
|
||||
|
||||
// Warning for unsupported compilers
|
||||
#if !defined(__GNUC__) /* GCC */ \
|
||||
|
|
Loading…
Reference in New Issue