1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include "SlsRequestPriorityClass.hxx"
23 #include <cache/SlsCacheContext.hxx>
24 #include <osl/mutex.hxx>
25 #include <svx/sdrpageuser.hxx>
29 namespace sd::slidesorter::cache
31 /** The request queue stores requests that are described by the Request
32 sorted according to priority class and then priority.
34 class RequestQueue
: public sdr::PageUser
37 explicit RequestQueue(SharedCacheContext pCacheContext
);
38 virtual ~RequestQueue();
40 /** Insert a request with highest or lowest priority in its priority
41 class. When the request is already present then it is first
42 removed. This effect is then a re-prioritization.
46 The priority class in which to insert the request with highest
48 @param bInsertWithHighestPriority
49 When this flag is <TRUE/> the request is inserted with highest
50 priority in its class. When <FALSE/> the request is inserted
53 void AddRequest(CacheKey aKey
, RequestPriorityClass eRequestClass
);
55 /** Remove the specified request from the queue.
57 It is OK when the specified request is not a member of the
60 #if OSL_DEBUG_LEVEL >= 2
65 RemoveRequest(CacheKey aKey
);
67 /** Change the priority class of the specified request.
69 void ChangeClass(CacheKey aKey
, RequestPriorityClass eNewRequestClass
);
71 /** Get the request with the highest priority int the highest priority class.
76 RequestPriorityClass
GetFrontPriorityClass();
78 /** Really a synonym for RemoveRequest(GetFront());
82 /** Returns <TRUE/> when there is no element in the queue.
86 /** Remove all requests from the queue. This resets the minimum and
87 maximum priorities to their default values.
91 /** Return the mutex that guards the access to the priority queue.
93 ::osl::Mutex
& GetMutex() { return maMutex
; }
95 /** Ensure we don't hand out a page deleted before anyone got a
98 virtual void PageInDestruction(const SdrPage
& rPage
) override
;
101 ::osl::Mutex maMutex
;
103 std::unique_ptr
<Container
> mpRequestQueue
;
104 SharedCacheContext mpCacheContext
;
106 /** A lower bound of the lowest priority of all elements in the queues.
107 The start value is 0. It is assigned and then decreased every time
108 when an element is inserted or marked as the request with lowest
111 int mnMinimumPriority
;
112 /** An upper bound of the highest priority of all elements in the queues.
113 The start value is 1. It is assigned and then increased every time
114 when an element is inserted or marked as the request with highest
117 int mnMaximumPriority
;
120 } // end of namespace ::sd::slidesorter::cache
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */