acl/lib_acl_cpp/include/acl_cpp/stdlib/thread_mutex.hpp

71 lines
1.4 KiB
C++
Raw Normal View History

#pragma once
#include "../acl_cpp_define.hpp"
#include "noncopyable.hpp"
#if !defined(_WIN32) && !defined(_WIN64)
# include <pthread.h>
# ifndef acl_pthread_mutex_t
# define acl_pthread_mutex_t pthread_mutex_t
# endif
#else
struct acl_pthread_mutex_t;
#endif
namespace acl {
/**
* <EFBFBD>̻߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
class ACL_CPP_API thread_mutex : public noncopyable
{
public:
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param recursive {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>õݹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
*/
thread_mutex(bool recursive = true);
~thread_mutex(void);
/**
* <EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ʧ<EFBFBD><EFBFBD>(һ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false ˵<EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
bool lock(void);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>۳ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>񶼻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
*/
bool try_lock(void);
/**
* <EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD>п<EFBFBD><EFBFBD><EFBFBD>֮ǰ<EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
bool unlock(void);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> acl <EFBFBD><EFBFBD> C <EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD>
* @return {acl_pthread_mutex_t*}
*/
acl_pthread_mutex_t* get_mutex(void) const;
private:
acl_pthread_mutex_t* mutex_;
#if !defined(_WIN32) && !defined(_WIN64)
pthread_mutexattr_t mutex_attr_;
#endif
};
class ACL_CPP_API thread_mutex_guard : public noncopyable
{
public:
thread_mutex_guard(thread_mutex& mutex);
~thread_mutex_guard(void);
private:
thread_mutex& mutex_;
};
} // namespace acl