cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / slidesorter / cache / SlsRequestQueue.hxx
blobd9a94c862f79137ea842f02dc75f7303c8d3868c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include "SlsRequestPriorityClass.hxx"
23 #include <cache/SlsCacheContext.hxx>
24 #include <osl/mutex.hxx>
25 #include <svx/sdrpageuser.hxx>
27 #include <memory>
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
36 public:
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.
43 @param aKey
44 The request.
45 @param eRequestClass
46 The priority class in which to insert the request with highest
47 or lowest priority.
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
51 with lowest priority.
53 void AddRequest(CacheKey aKey, RequestPriorityClass eRequestClass);
55 /** Remove the specified request from the queue.
56 @param aKey
57 It is OK when the specified request is not a member of the
58 queue.
60 #if OSL_DEBUG_LEVEL >= 2
61 bool
62 #else
63 void
64 #endif
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.
73 CacheKey GetFront();
75 // For debugging.
76 RequestPriorityClass GetFrontPriorityClass();
78 /** Really a synonym for RemoveRequest(GetFront());
80 void PopFront();
82 /** Returns <TRUE/> when there is no element in the queue.
84 bool IsEmpty();
86 /** Remove all requests from the queue. This resets the minimum and
87 maximum priorities to their default values.
89 void Clear();
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
96 chance to process it
98 virtual void PageInDestruction(const SdrPage& rPage) override;
100 private:
101 ::osl::Mutex maMutex;
102 class Container;
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
109 priority.
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
115 priority.
117 int mnMaximumPriority;
120 } // end of namespace ::sd::slidesorter::cache
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */