Minor enhancement of PriorityNotificationQueue

Discussion of ideas for features and new projects based on POCO.
Posts: 17
Joined: 27 Feb 2014, 19:57

Minor enhancement of PriorityNotificationQueue

Postby dedvalson » 05 Mar 2014, 17:29

I am trying to use the PriorityNotificationQueue as a Work Distributor as suggested in the documentation.

It works well for this, but I found that I needed an enhancement that I think would be useful to anyone using this class for this purpose.

The current method for adding a work item to the queue is

Code: Select all

void PriorityNotificationQueue::enqueueNotification(Notification::Ptr pNotification, int priority)

The problem I have is that the user may cancel or change the priority of a Work Item (A notification) after it has been en-queued but before it has been dispatched to a worker. To accommodate this, I would propose adding a member, something like:

Code: Select all

Notification* PriorityNotificationQueue::cancelNotification(Notification::Ptr pNotification)
    FastMutex::ScopedLock lock(_mutex);
    for (auto it = _nfQueue.begin(); it != _nfQueue.end(); ) {
        if ((*it).second == pNotification) {
            _nfQueue.erase (it);
            return (*it).second;
    return NULL;

This seemed to work for me and helped with the problem I had.

Posts: 1375
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Minor enhancement of PriorityNotificationQueue

Postby alex » 05 Mar 2014, 19:28

Looks good to me, except that we are not yet using C++11 features (e.g. auto) in 1.5. If you'd like to see it in, write a test case and send github pull request.

Return to “Wishlist”

Who is online

Users browsing this forum: No registered users and 1 guest