Callback: Adopt better use of assignment/call operators

pull/3783/head
Christopher Haster 2017-02-15 15:19:38 -06:00
parent ed6fec2811
commit 417524f562
5 changed files with 16 additions and 16 deletions

View File

@ -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);
@ -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();
@ -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();
@ -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;
}
}

View File

@ -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);
@ -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();
@ -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() {

View File

@ -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();
}
@ -39,7 +39,7 @@ void Ticker::setup(timestamp_t t) {
void Ticker::handler() {
insert(event.timestamp + _delay);
_function.call();
_function();
}
} // namespace mbed

View File

@ -101,7 +101,7 @@ public:
* @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);
}

View File

@ -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();