feat update
This commit is contained in:
parent
3ca77d457b
commit
016eadb3d9
@ -1,5 +1,41 @@
|
||||
#pragma once
|
||||
#ifndef SLED_LANG_ATTRIBUTES_H
|
||||
#define SLED_LANG_ATTRIBUTES_H
|
||||
#define SLED_DEPRECATED __attribute__((deprecated))
|
||||
|
||||
#define SLED_DEPRECATED() __attribute__((deprecated))
|
||||
#if defined(__GNUC__) && defined(__SUPPORT_TS_ANNOTATION__) && !defined(SWIG)
|
||||
#define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
|
||||
#elif defined(__clang__)
|
||||
#define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
|
||||
#else
|
||||
#define THREAD_ANNOTATION_ATTRIBUTE__(x)
|
||||
#endif
|
||||
|
||||
#if defined(GUARDED_BY)
|
||||
#undef GUARDED_BY
|
||||
#endif
|
||||
#define GUARDED_BY(x) __attribute__((guarded_by(x)))
|
||||
|
||||
#if defined(__clang__)
|
||||
#define EXCLUSIVE_TRYLOCK_FUNCTION(...) \
|
||||
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__))
|
||||
|
||||
#define EXCLUSIVE_LOCK_FUNCTION(...) \
|
||||
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__))
|
||||
|
||||
#define UNLOCK_FUNCTION(...) \
|
||||
THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__))
|
||||
|
||||
#define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
|
||||
|
||||
#else
|
||||
|
||||
#define EXCLUSIVE_TRYLOCK_FUNCTION(...) \
|
||||
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock(__VA_ARGS__))
|
||||
#define EXCLUSIVE_LOCK_FUNCTION(...) \
|
||||
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock(__VA_ARGS__))
|
||||
#define UNLOCK_FUNCTION(...) THREAD_ANNOTATION_ATTRIBUTE__(unlock(__VA_ARGS__))
|
||||
#define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(point_to_guarded_by(x))
|
||||
#endif
|
||||
|
||||
#endif// SLED_LANG_ATTRIBUTES_H
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
Mutex mutex_;
|
||||
ConditionVariable cv_;
|
||||
const bool is_manual_reset_;
|
||||
bool event_status_;
|
||||
bool event_status_ GUARDED_BY(mutex_);
|
||||
};
|
||||
|
||||
}// namespace sled
|
||||
|
@ -5,10 +5,10 @@
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
#include "marl/conditionvariable.h"
|
||||
#ifndef SLED_SYNCHRONIZATION_MUTEX_H
|
||||
#define SLED_SYNCHRONIZATION_MUTEX_H
|
||||
|
||||
#include "marl/conditionvariable.h"
|
||||
#include "sled/lang/attributes.h"
|
||||
#include "sled/units/time_delta.h"
|
||||
#include <chrono>
|
||||
@ -61,13 +61,13 @@ public:
|
||||
RecursiveMutex(const RecursiveMutex &) = delete;
|
||||
RecursiveMutex &operator=(const RecursiveMutex &) = delete;
|
||||
|
||||
inline void Lock() { impl_.lock(); }
|
||||
inline void Lock() EXCLUSIVE_LOCK_FUNCTION() { impl_.lock(); }
|
||||
|
||||
inline bool TryLock() { return impl_.try_lock(); }
|
||||
|
||||
inline void AssertHeld() {}
|
||||
|
||||
inline void Unlock() { impl_.unlock(); }
|
||||
inline void Unlock() UNLOCK_FUNCTION() { impl_.unlock(); }
|
||||
|
||||
private:
|
||||
std::recursive_mutex impl_;
|
||||
@ -76,14 +76,17 @@ private:
|
||||
template<typename TLock,
|
||||
typename std::enable_if<internal::HasLockAndUnlock<TLock>::value,
|
||||
TLock>::type * = nullptr>
|
||||
class SLED_DEPRECATED LockGuard final {
|
||||
class SLED_DEPRECATED() LockGuard final {
|
||||
public:
|
||||
LockGuard(const LockGuard &) = delete;
|
||||
LockGuard &operator=(const LockGuard &) = delete;
|
||||
|
||||
explicit LockGuard(TLock *lock) : mutex_(lock) { mutex_->Lock(); };
|
||||
explicit LockGuard(TLock *lock) EXCLUSIVE_LOCK_FUNCTION() : mutex_(lock)
|
||||
{
|
||||
mutex_->Lock();
|
||||
};
|
||||
|
||||
~LockGuard() { mutex_->Unlock(); };
|
||||
~LockGuard() UNLOCK_FUNCTION() { mutex_->Unlock(); };
|
||||
|
||||
private:
|
||||
TLock *mutex_;
|
||||
@ -102,11 +105,11 @@ private:
|
||||
marl::lock lock_;
|
||||
};
|
||||
|
||||
using MutexGuard SLED_DEPRECATED = MutexLock;
|
||||
using MutexGuard SLED_DEPRECATED() = MutexLock;
|
||||
// using MutexGuard = marl::lock;
|
||||
// using MutexLock = LockGuard<Mutex>;
|
||||
// using MutexGuard = LockGuard<Mutex>;
|
||||
using RecursiveMutexLock SLED_DEPRECATED = LockGuard<RecursiveMutex>;
|
||||
using RecursiveMutexLock SLED_DEPRECATED() = LockGuard<RecursiveMutex>;
|
||||
|
||||
// class MutexLock final {
|
||||
// public:
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
bool happended_ = false;
|
||||
bool happended_ GUARDED_BY(mutex_) = false;
|
||||
Mutex mutex_;
|
||||
};
|
||||
|
||||
|
@ -159,9 +159,9 @@ private:
|
||||
void ClearCurrentTaskQueue();
|
||||
|
||||
mutable Mutex mutex_;
|
||||
std::queue<std::function<void()>> messages_;
|
||||
std::priority_queue<DelayedMessage> delayed_messages_;
|
||||
uint32_t delayed_next_num_;
|
||||
std::queue<std::function<void()>> messages_ GUARDED_BY(mutex_);
|
||||
std::priority_queue<DelayedMessage> delayed_messages_ GUARDED_BY(mutex_);
|
||||
uint32_t delayed_next_num_ GUARDED_BY(mutex_);
|
||||
bool fInitialized_;
|
||||
bool fDestroyed_;
|
||||
std::atomic<int> stop_;
|
||||
@ -183,8 +183,9 @@ public:
|
||||
|
||||
AutoSocketServerThread(const AutoSocketServerThread &) = delete;
|
||||
AutoSocketServerThread &operator=(const AutoSocketServerThread &) = delete;
|
||||
|
||||
private:
|
||||
Thread* old_thread_;
|
||||
Thread *old_thread_;
|
||||
};
|
||||
|
||||
}// namespace sled
|
||||
|
Loading…
Reference in New Issue
Block a user