Skip to content

Callback: Deprecate attach member function in favor of simple assignment #3783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions drivers/InterruptIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ InterruptIn::InterruptIn(PinName pin) : gpio(),
_fall() {
// No lock needed in the constructor

_rise.attach(donothing);
_fall.attach(donothing);
_rise = donothing;
_fall = donothing;

gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
gpio_init_in(&gpio, pin);
Expand All @@ -53,10 +53,10 @@ void InterruptIn::mode(PinMode pull) {
void InterruptIn::rise(Callback<void()> func) {
core_util_critical_section_enter();
if (func) {
_rise.attach(func);
_rise = func;
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
} else {
_rise.attach(donothing);
_rise = donothing;
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
}
core_util_critical_section_exit();
Expand All @@ -65,10 +65,10 @@ void InterruptIn::rise(Callback<void()> func) {
void InterruptIn::fall(Callback<void()> func) {
core_util_critical_section_enter();
if (func) {
_fall.attach(func);
_fall = func;
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
} else {
_fall.attach(donothing);
_fall = donothing;
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
}
core_util_critical_section_exit();
Expand All @@ -77,8 +77,8 @@ void InterruptIn::fall(Callback<void()> func) {
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
InterruptIn *handler = (InterruptIn*)id;
switch (event) {
case IRQ_RISE: handler->_rise.call(); break;
case IRQ_FALL: handler->_fall.call(); break;
case IRQ_RISE: handler->_rise(); break;
case IRQ_FALL: handler->_fall(); break;
case IRQ_NONE: break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions drivers/SerialBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SerialBase::SerialBase(PinName tx, PinName rx, int baud) :
// No lock needed in the constructor

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

serial_init(&_serial, tx, rx);
Expand Down Expand Up @@ -73,10 +73,10 @@ void SerialBase::attach(Callback<void()> func, IrqType type) {
// Disable interrupts when attaching interrupt handler
core_util_critical_section_enter();
if (func) {
_irq[type].attach(func);
_irq[type] = func;
serial_irq_set(&_serial, (SerialIrq)type, 1);
} else {
_irq[type].attach(donothing);
_irq[type] = donothing;
serial_irq_set(&_serial, (SerialIrq)type, 0);
}
core_util_critical_section_exit();
Expand All @@ -85,7 +85,7 @@ void SerialBase::attach(Callback<void()> func, IrqType type) {

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

int SerialBase::_base_getc() {
Expand Down
4 changes: 2 additions & 2 deletions drivers/Ticker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace mbed {
void Ticker::detach() {
core_util_critical_section_enter();
remove();
_function.attach(0);
_function = 0;
core_util_critical_section_exit();
}

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

void Ticker::handler() {
insert(event.timestamp + _delay);
_function.call();
_function();
}

} // namespace mbed
2 changes: 1 addition & 1 deletion drivers/Ticker.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Ticker : public TimerEvent {
* @param t the time between calls in micro-seconds
*/
void attach_us(Callback<void()> func, timestamp_t t) {
_function.attach(func);
_function = func;
setup(t);
}

Expand Down
2 changes: 1 addition & 1 deletion features/netsocket/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ nsapi_error_t Socket::open(NetworkStack *stack)
}

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

_lock.unlock();
Expand Down
Loading