Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-os/events/EventQueue.cpp@4:75df35ef4fb6, 2018-03-30 (annotated)
- Committer:
- borlanic
- Date:
- Fri Mar 30 14:07:05 2018 +0000
- Revision:
- 4:75df35ef4fb6
- Parent:
- 0:380207fcb5c1
commentar
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:380207fcb5c1 | 1 | /* events |
borlanic | 0:380207fcb5c1 | 2 | * Copyright (c) 2016 ARM Limited |
borlanic | 0:380207fcb5c1 | 3 | * |
borlanic | 0:380207fcb5c1 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:380207fcb5c1 | 5 | * you may not use this file except in compliance with the License. |
borlanic | 0:380207fcb5c1 | 6 | * You may obtain a copy of the License at |
borlanic | 0:380207fcb5c1 | 7 | * |
borlanic | 0:380207fcb5c1 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:380207fcb5c1 | 9 | * |
borlanic | 0:380207fcb5c1 | 10 | * Unless required by applicable law or agreed to in writing, software |
borlanic | 0:380207fcb5c1 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:380207fcb5c1 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:380207fcb5c1 | 13 | * See the License for the specific language governing permissions and |
borlanic | 0:380207fcb5c1 | 14 | * limitations under the License. |
borlanic | 0:380207fcb5c1 | 15 | */ |
borlanic | 0:380207fcb5c1 | 16 | #include "events/EventQueue.h" |
borlanic | 0:380207fcb5c1 | 17 | |
borlanic | 0:380207fcb5c1 | 18 | #include "events/mbed_events.h" |
borlanic | 0:380207fcb5c1 | 19 | #include "mbed.h" |
borlanic | 0:380207fcb5c1 | 20 | |
borlanic | 0:380207fcb5c1 | 21 | |
borlanic | 0:380207fcb5c1 | 22 | EventQueue::EventQueue(unsigned event_size, unsigned char *event_pointer) { |
borlanic | 0:380207fcb5c1 | 23 | if (!event_pointer) { |
borlanic | 0:380207fcb5c1 | 24 | equeue_create(&_equeue, event_size); |
borlanic | 0:380207fcb5c1 | 25 | } else { |
borlanic | 0:380207fcb5c1 | 26 | equeue_create_inplace(&_equeue, event_size, event_pointer); |
borlanic | 0:380207fcb5c1 | 27 | } |
borlanic | 0:380207fcb5c1 | 28 | } |
borlanic | 0:380207fcb5c1 | 29 | |
borlanic | 0:380207fcb5c1 | 30 | EventQueue::~EventQueue() { |
borlanic | 0:380207fcb5c1 | 31 | equeue_destroy(&_equeue); |
borlanic | 0:380207fcb5c1 | 32 | } |
borlanic | 0:380207fcb5c1 | 33 | |
borlanic | 0:380207fcb5c1 | 34 | void EventQueue::dispatch(int ms) { |
borlanic | 0:380207fcb5c1 | 35 | return equeue_dispatch(&_equeue, ms); |
borlanic | 0:380207fcb5c1 | 36 | } |
borlanic | 0:380207fcb5c1 | 37 | |
borlanic | 0:380207fcb5c1 | 38 | void EventQueue::break_dispatch() { |
borlanic | 0:380207fcb5c1 | 39 | return equeue_break(&_equeue); |
borlanic | 0:380207fcb5c1 | 40 | } |
borlanic | 0:380207fcb5c1 | 41 | |
borlanic | 0:380207fcb5c1 | 42 | unsigned EventQueue::tick() { |
borlanic | 0:380207fcb5c1 | 43 | return equeue_tick(); |
borlanic | 0:380207fcb5c1 | 44 | } |
borlanic | 0:380207fcb5c1 | 45 | |
borlanic | 0:380207fcb5c1 | 46 | void EventQueue::cancel(int id) { |
borlanic | 0:380207fcb5c1 | 47 | return equeue_cancel(&_equeue, id); |
borlanic | 0:380207fcb5c1 | 48 | } |
borlanic | 0:380207fcb5c1 | 49 | |
borlanic | 0:380207fcb5c1 | 50 | void EventQueue::background(Callback<void(int)> update) { |
borlanic | 0:380207fcb5c1 | 51 | _update = update; |
borlanic | 0:380207fcb5c1 | 52 | |
borlanic | 0:380207fcb5c1 | 53 | if (_update) { |
borlanic | 0:380207fcb5c1 | 54 | equeue_background(&_equeue, &Callback<void(int)>::thunk, &_update); |
borlanic | 0:380207fcb5c1 | 55 | } else { |
borlanic | 0:380207fcb5c1 | 56 | equeue_background(&_equeue, 0, 0); |
borlanic | 0:380207fcb5c1 | 57 | } |
borlanic | 0:380207fcb5c1 | 58 | } |
borlanic | 0:380207fcb5c1 | 59 | |
borlanic | 0:380207fcb5c1 | 60 | void EventQueue::chain(EventQueue *target) { |
borlanic | 0:380207fcb5c1 | 61 | if (target) { |
borlanic | 0:380207fcb5c1 | 62 | equeue_chain(&_equeue, &target->_equeue); |
borlanic | 0:380207fcb5c1 | 63 | } else { |
borlanic | 0:380207fcb5c1 | 64 | equeue_chain(&_equeue, 0); |
borlanic | 0:380207fcb5c1 | 65 | } |
borlanic | 0:380207fcb5c1 | 66 | } |