Skip to content

Commit cfd517a

Browse files
authored
Merge pull request #3783 from geky/cb-deprecate-attach
Callback: Deprecate attach member function in favor of simple assignment
2 parents 4103842 + 417524f commit cfd517a

File tree

6 files changed

+352
-16
lines changed

6 files changed

+352
-16
lines changed

drivers/InterruptIn.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ InterruptIn::InterruptIn(PinName pin) : gpio(),
2727
_fall() {
2828
// No lock needed in the constructor
2929

30-
_rise.attach(donothing);
31-
_fall.attach(donothing);
30+
_rise = donothing;
31+
_fall = donothing;
3232

3333
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
3434
gpio_init_in(&gpio, pin);
@@ -53,10 +53,10 @@ void InterruptIn::mode(PinMode pull) {
5353
void InterruptIn::rise(Callback<void()> func) {
5454
core_util_critical_section_enter();
5555
if (func) {
56-
_rise.attach(func);
56+
_rise = func;
5757
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
5858
} else {
59-
_rise.attach(donothing);
59+
_rise = donothing;
6060
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
6161
}
6262
core_util_critical_section_exit();
@@ -65,10 +65,10 @@ void InterruptIn::rise(Callback<void()> func) {
6565
void InterruptIn::fall(Callback<void()> func) {
6666
core_util_critical_section_enter();
6767
if (func) {
68-
_fall.attach(func);
68+
_fall = func;
6969
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
7070
} else {
71-
_fall.attach(donothing);
71+
_fall = donothing;
7272
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
7373
}
7474
core_util_critical_section_exit();
@@ -77,8 +77,8 @@ void InterruptIn::fall(Callback<void()> func) {
7777
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
7878
InterruptIn *handler = (InterruptIn*)id;
7979
switch (event) {
80-
case IRQ_RISE: handler->_rise.call(); break;
81-
case IRQ_FALL: handler->_fall.call(); break;
80+
case IRQ_RISE: handler->_rise(); break;
81+
case IRQ_FALL: handler->_fall(); break;
8282
case IRQ_NONE: break;
8383
}
8484
}

drivers/SerialBase.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ SerialBase::SerialBase(PinName tx, PinName rx, int baud) :
3232
// No lock needed in the constructor
3333

3434
for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
35-
_irq[i].attach(donothing);
35+
_irq[i] = donothing;
3636
}
3737

3838
serial_init(&_serial, tx, rx);
@@ -73,10 +73,10 @@ void SerialBase::attach(Callback<void()> func, IrqType type) {
7373
// Disable interrupts when attaching interrupt handler
7474
core_util_critical_section_enter();
7575
if (func) {
76-
_irq[type].attach(func);
76+
_irq[type] = func;
7777
serial_irq_set(&_serial, (SerialIrq)type, 1);
7878
} else {
79-
_irq[type].attach(donothing);
79+
_irq[type] = donothing;
8080
serial_irq_set(&_serial, (SerialIrq)type, 0);
8181
}
8282
core_util_critical_section_exit();
@@ -85,7 +85,7 @@ void SerialBase::attach(Callback<void()> func, IrqType type) {
8585

8686
void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) {
8787
SerialBase *handler = (SerialBase*)id;
88-
handler->_irq[irq_type].call();
88+
handler->_irq[irq_type]();
8989
}
9090

9191
int SerialBase::_base_getc() {

drivers/Ticker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace mbed {
2525
void Ticker::detach() {
2626
core_util_critical_section_enter();
2727
remove();
28-
_function.attach(0);
28+
_function = 0;
2929
core_util_critical_section_exit();
3030
}
3131

@@ -39,7 +39,7 @@ void Ticker::setup(timestamp_t t) {
3939

4040
void Ticker::handler() {
4141
insert(event.timestamp + _delay);
42-
_function.call();
42+
_function();
4343
}
4444

4545
} // namespace mbed

drivers/Ticker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class Ticker : public TimerEvent {
101101
* @param t the time between calls in micro-seconds
102102
*/
103103
void attach_us(Callback<void()> func, timestamp_t t) {
104-
_function.attach(func);
104+
_function = func;
105105
setup(t);
106106
}
107107

features/netsocket/Socket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ nsapi_error_t Socket::open(NetworkStack *stack)
4242
}
4343

4444
_socket = socket;
45-
_event.attach(this, &Socket::event);
45+
_event = callback(this, &Socket::event);
4646
_stack->socket_attach(_socket, Callback<void()>::thunk, &_event);
4747

4848
_lock.unlock();

0 commit comments

Comments
 (0)