event_pool.h 1.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/**
 * \file imperative/src/impl/event_pool.h
 * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
 *
 * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#pragma once

#include "megbrain/comp_node.h"

namespace mgb {
namespace imperative {

class EventPool : CompNodeDepedentObject {
    CompNode::UnorderedMap<CompNode::EventPool> m_cn2pool;
    Spinlock m_lock;
    size_t m_flags;

    EventPool(size_t flags = 0);

public:
    static EventPool& with_timer();
    static EventPool& without_timer();
    CompNode::Event* alloc(CompNode cn);
    std::shared_ptr<CompNode::Event> alloc_shared(CompNode cn);
    void free(CompNode::Event* event);
    std::shared_ptr<void> on_comp_node_finalize();
    ~EventPool();
34 35

    using CompNodeDepedentObject::is_finalized;
36 37 38
};
}  // namespace imperative
}  // namespace mgb