File: deferred_deleter.h

package info (click to toggle)
intel-compute-runtime 25.35.35096.9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,324 kB
  • sloc: cpp: 926,243; lisp: 3,433; sh: 715; makefile: 162; python: 21
file content (57 lines) | stat: -rw-r--r-- 1,426 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Copyright (C) 2018-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/utilities/idlist.h"

#include <atomic>
#include <condition_variable>
#include <mutex>

namespace NEO {
class DeferrableDeletion;
class Thread;
class DeferredDeleter : NEO::NonCopyableAndNonMovableClass {
  public:
    DeferredDeleter();
    virtual ~DeferredDeleter();

    MOCKABLE_VIRTUAL void deferDeletion(DeferrableDeletion *deletion);

    MOCKABLE_VIRTUAL void addClient();

    MOCKABLE_VIRTUAL void removeClient();

    MOCKABLE_VIRTUAL void drain(bool blocking, bool hostptrsOnly);

    MOCKABLE_VIRTUAL bool areElementsReleased(bool hostptrsOnly);

  protected:
    void stop();
    void safeStop();
    void ensureThread();
    MOCKABLE_VIRTUAL void clearQueue(bool hostptrsOnly);
    MOCKABLE_VIRTUAL bool shouldStop();

    static void *run(void *);

    std::atomic<bool> exitedMainLoop = false;
    std::atomic<bool> doWorkInBackground = false;
    std::atomic<int> elementsToRelease = 0;
    std::atomic<int> hostptrsToRelease = 0;
    std::unique_ptr<Thread> worker;
    int32_t numClients = 0;
    IDList<DeferrableDeletion, true> queue;
    std::mutex queueMutex;
    std::mutex threadMutex;
    std::condition_variable condition;
};

static_assert(NEO::NonCopyableAndNonMovable<DeferredDeleter>);

} // namespace NEO