开发者

BOOST: How to implement a null named_mutex?

开发者 https://www.devze.com 2023-02-10 00:37 出处:网络
I some开发者_运维技巧times need a \"null\" implementation of named_mutex(i.e. always succeeds and does nothing).

I some开发者_运维技巧times need a "null" implementation of named_mutex(i.e. always succeeds and does nothing).

Is there is such implementation ? If not, what's the recommended way to implement?


Why not just have a class with empty definitions?

class named_mutex
{
public:
    named_mutex(create_only_t, const char *) {}
    named_mutex(open_or_create_t, const char *) {}
    named_mutex(open_only_t, const char *) {}
    ~named_mutex() {}

    void unlock() {}
    void lock() {}
    bool try_lock() {}
    bool timed_lock(const boost::posix_time::ptime &) {}

    static bool remove(const char *) {}
};

Use an instance of this as your named_mutex and it's like it never existed.

0

精彩评论

暂无评论...
验证码 换一张
取 消