Skip to content

Commit bb733f1

Browse files
committed
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.
1 parent ea3761f commit bb733f1

File tree

11 files changed

+657
-272
lines changed

11 files changed

+657
-272
lines changed

TESTS/mbed_platform/Transaction/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ void test_Transaction_init()
5858
TEST_ASSERT_EQUAL(rx_buffer_size, test_transaction.get_transaction()->rx_length);
5959
TEST_ASSERT_EQUAL(event_id, test_transaction.get_transaction()->event);
6060
TEST_ASSERT_EQUAL(word_width, test_transaction.get_transaction()->width);
61-
TEST_ASSERT_EQUAL(callback, test_transaction.get_transaction()->callback);
61+
#if MBED_CONF_PLATFORM_CALLBACK_COMPARABLE
62+
TEST_ASSERT_TRUE(callback == test_transaction.get_transaction()->callback);
63+
#else
64+
TEST_ASSERT_FALSE(nullptr == test_transaction.get_transaction()->callback)
65+
#endif
6266
}
6367

6468
/** Test Transaction class - creation without initialisation

TESTS/network/emac/emac_util.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ char emac_if_get_trace_level();
102102

103103
void emac_if_trace_to_ascii_hex_dump(const char *prefix, int len, char *data);
104104

105-
void emac_if_link_state_change_cb(void *data, bool up);
106-
107105
unsigned char *emac_if_get_own_addr(void);
108106

109107
int emac_if_get_mtu_size();

UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# UNIT TESTS
44
####################
55

6+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_PLATFORM_CALLBACK_COMPARABLE")
7+
68
# Source files
79
set(unittest-sources
810
../features/netsocket/SocketAddress.cpp
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef MSTD_NEW_
18+
#define MSTD_NEW_
19+
20+
/* <mstd_new>
21+
*
22+
* - includes toolchain's <new>
23+
* - For all toolchains, C++17 backports:
24+
* - mstd::launder
25+
*/
26+
27+
#include <new>
28+
#if __cpp_lib_launder < 201606
29+
#include <type_traits>
30+
#endif
31+
32+
namespace mstd
33+
{
34+
using std::nothrow_t;
35+
using std::nothrow;
36+
using std::new_handler;
37+
using std::set_new_handler;
38+
39+
#if __cpp_lib_launder >= 201606
40+
using std::launder;
41+
#else
42+
template <typename T>
43+
constexpr T *launder(T *p) noexcept
44+
{
45+
static_assert(!std::is_function<T>::value && !std::is_void<T>::value, "Can only launder complete object types");
46+
#if defined __clang__ || __GNUC__ >= 9
47+
return __builtin_launder(p);
48+
#else
49+
return p;
50+
#endif
51+
}
52+
#endif
53+
54+
} // namespace mstd
55+
56+
#endif // MSTD_NEW_

UNITTESTS/target_h/platform/cxxsupport/mstd_type_traits

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,6 @@ struct remove_cvref : type_identity<std::remove_cv_t<std::remove_reference_t<T>>
300300
template <typename T>
301301
using remove_cvref_t = typename remove_cvref<T>::type;
302302

303-
/* C++20 unwrap_reference */
304-
template <typename T>
305-
struct unwrap_reference : type_identity<T> { };
306-
template <typename T>
307-
struct unwrap_reference<std::reference_wrapper<T>> : type_identity<T &> { };
308-
template <typename T>
309-
using unwrap_reference_t = typename unwrap_reference<T>::type;
310-
311-
/* C++20 unwrap_ref_decay */
312-
template <typename T>
313-
struct unwrap_ref_decay : unwrap_reference<std::decay_t<T>> { };
314-
template <typename T>
315-
using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type;
316-
317303
}
318304

319305
#if __cpp_lib_invoke < 201411

features/netsocket/NetworkInterface.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void NetworkInterface::add_event_listener(mbed::Callback<void(nsapi_event_t, int
141141
attach(mbed::callback(&call_all_event_listeners, this));
142142
}
143143

144+
#if MBED_CONF_PLATFORM_CALLBACK_COMPARABLE
144145
void NetworkInterface::remove_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb)
145146
{
146147
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,
152153
}
153154
}
154155
}
156+
#endif
155157

156158
NetworkInterface::~NetworkInterface()
157159
{

features/netsocket/NetworkInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,15 @@ class NetworkInterface: public DNS {
352352
*/
353353
void add_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
354354

355+
#if MBED_CONF_PLATFORM_CALLBACK_COMPARABLE
355356
/** Remove event listener from interface.
356357
*
357358
* Remove previously added callback from the handler list.
358359
*
359360
* @param status_cb The callback to unregister.
360361
*/
361362
void remove_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
363+
#endif
362364

363365
/** Get the connection status.
364366
*

0 commit comments

Comments
 (0)