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

78 lines
1.4 KiB
C++
Raw Normal View History

2017-08-22 15:20:28 +08:00
/**
* Copyright (C) 2017-2018 IQIYI
* All rights reserved.
*
* AUTHOR(S)
* Zheng Shuxin
* E-mail: zhengshuxin@qiyi.com
*
* VERSION
* Tue 22 Aug 2017 11:09:55 AM CST
*/
#pragma once
#include "../acl_cpp_define.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>
*/
2017-08-22 15:20:28 +08:00
class ACL_CPP_API thread_mutex
{
public:
thread_mutex(void);
~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>
*/
2017-08-22 15:20:28 +08:00
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>
*/
2017-08-22 15:20:28 +08:00
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>
*/
2017-08-22 15:20:28 +08:00
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*}
*/
2017-08-22 15:20:28 +08:00
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:
thread_mutex_guard(thread_mutex& mutex);
~thread_mutex_guard(void);
private:
thread_mutex& mutex_;
};
2017-08-22 15:20:28 +08:00
} // namespace acl