| // umlrttimerqueue.hh |
| |
| /******************************************************************************* |
| * Copyright (c) 2014-2015 Zeligsoft (2009) Limited and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| *******************************************************************************/ |
| |
| #ifndef UMLRTTIMERQUEUE_HH |
| #define UMLRTTIMERQUEUE_HH |
| |
| #include "umlrtqueue.hh" |
| #include "umlrttimespec.hh" |
| #include "umlrttimerid.hh" |
| |
| // Queue of running timers. |
| |
| struct UMLRTTimer; |
| |
| class UMLRTTimerQueue : public UMLRTQueue |
| { |
| public: |
| // Create an empty queue. |
| UMLRTTimerQueue(); |
| |
| // Remove the first timer on the queue. Returns NULL if none or the first timer has not yet expired. |
| UMLRTTimer * dequeue(); |
| |
| // Add a timer to the queue in order of when they will expire. |
| void enqueue( const UMLRTTimer * timer ); |
| |
| // Cancel a timer (remove from the queue). Return true if ok. |
| bool cancel( UMLRTTimerId id ); |
| |
| // Calculate how much time left before timer on the head of the queue is due. |
| UMLRTTimespec timeRemaining() const; |
| |
| // Return the notification file descriptor used to indicate a command is queued for execution. |
| int getNotifyFd(); |
| |
| // Clear notifications of pending commands. |
| void clearNotifyFd(); |
| |
| private: |
| // Calling this causes the notification mechanism to be 'set'. Threads waiting |
| // for notification on this queue will receive notification. |
| void sendNotification(); |
| |
| // Notification-pipe. Those waiting for an element to be queued can wait on select() on the |
| // 'getNotifyFd()' (the read-end of the pipe). |
| // Threads enqueuing messages write a byte to the pipe to notify waiting threads. |
| // Clearing the notifications involves reading until the pipe is empty. |
| int notifyFd[2]; |
| }; |
| |
| #endif // UMLRTTIMERQUEUE_HH |