#pragma once
#include <vector>
#include "critical_res_define.h"
class CCriticalResManager {
private:
    CCriticalResManager();
public:
    virtual ~CCriticalResManager();
    static CCriticalResManager& GetInstance()
    {
        static CCriticalResManager s_criticalResManager;

        return s_criticalResManager;
    }

    bool Acquire(int iVSMId, const std::vector<int>& vecList);
    bool CanAcquire(int iVSMId, const std::vector<int>& vecList);
    bool Release(const std::vector<int>& vecList);
    bool Acquire(int iVSMId, uint resId);
    bool CanAcquire(int iVSMId, uint resId);

    bool NotAcquired(int iVSMID, uint resId);
    /*!
     * 强制释放资源 
     * 
     * \param resId
     * \return 
     */
    bool ReleaseForce(uint resId);
    /*!
     * 释放被某个线程锁定的特定资源
     * 
     * \param iVsmId
     * \param resId
     * \return 
     */
    bool Release(int iVsmId, uint resId);
    /*!
     * 释放被某个线程锁定的所有资源
     * 
     * \param iVsmId
     * \return 
     */
    void Release(int iVsmId);
    bool CanRelease(int iVsmId, uint resId);
    bool IsAcquired(int iVSMId, uint resId);
    //int GetLastErrorCode();
    //std::string GetLastError();
private:
    QMutex mutex;
    std::map<int, CriticalRes> mapResList;

};

