feat update
Some checks are pending
linux-x64-gcc / linux-gcc (Debug) (push) Waiting to run
linux-x64-gcc / linux-gcc (Release) (push) Waiting to run

This commit is contained in:
tqcq 2024-03-13 22:44:23 +08:00
parent 3ca77d457b
commit 016eadb3d9
5 changed files with 55 additions and 15 deletions

View File

@ -1,5 +1,41 @@
#pragma once #pragma once
#ifndef SLED_LANG_ATTRIBUTES_H #ifndef SLED_LANG_ATTRIBUTES_H
#define 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 #endif// SLED_LANG_ATTRIBUTES_H

View File

@ -36,7 +36,7 @@ public:
Mutex mutex_; Mutex mutex_;
ConditionVariable cv_; ConditionVariable cv_;
const bool is_manual_reset_; const bool is_manual_reset_;
bool event_status_; bool event_status_ GUARDED_BY(mutex_);
}; };
}// namespace sled }// namespace sled

View File

@ -5,10 +5,10 @@
**/ **/
#pragma once #pragma once
#include "marl/conditionvariable.h"
#ifndef SLED_SYNCHRONIZATION_MUTEX_H #ifndef SLED_SYNCHRONIZATION_MUTEX_H
#define SLED_SYNCHRONIZATION_MUTEX_H #define SLED_SYNCHRONIZATION_MUTEX_H
#include "marl/conditionvariable.h"
#include "sled/lang/attributes.h" #include "sled/lang/attributes.h"
#include "sled/units/time_delta.h" #include "sled/units/time_delta.h"
#include <chrono> #include <chrono>
@ -61,13 +61,13 @@ public:
RecursiveMutex(const RecursiveMutex &) = delete; RecursiveMutex(const RecursiveMutex &) = delete;
RecursiveMutex &operator=(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 bool TryLock() { return impl_.try_lock(); }
inline void AssertHeld() {} inline void AssertHeld() {}
inline void Unlock() { impl_.unlock(); } inline void Unlock() UNLOCK_FUNCTION() { impl_.unlock(); }
private: private:
std::recursive_mutex impl_; std::recursive_mutex impl_;
@ -76,14 +76,17 @@ private:
template<typename TLock, template<typename TLock,
typename std::enable_if<internal::HasLockAndUnlock<TLock>::value, typename std::enable_if<internal::HasLockAndUnlock<TLock>::value,
TLock>::type * = nullptr> TLock>::type * = nullptr>
class SLED_DEPRECATED LockGuard final { class SLED_DEPRECATED() LockGuard final {
public: public:
LockGuard(const LockGuard &) = delete; LockGuard(const LockGuard &) = delete;
LockGuard &operator=(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: private:
TLock *mutex_; TLock *mutex_;
@ -102,11 +105,11 @@ private:
marl::lock lock_; marl::lock lock_;
}; };
using MutexGuard SLED_DEPRECATED = MutexLock; using MutexGuard SLED_DEPRECATED() = MutexLock;
// using MutexGuard = marl::lock; // using MutexGuard = marl::lock;
// using MutexLock = LockGuard<Mutex>; // using MutexLock = LockGuard<Mutex>;
// using MutexGuard = LockGuard<Mutex>; // using MutexGuard = LockGuard<Mutex>;
using RecursiveMutexLock SLED_DEPRECATED = LockGuard<RecursiveMutex>; using RecursiveMutexLock SLED_DEPRECATED() = LockGuard<RecursiveMutex>;
// class MutexLock final { // class MutexLock final {
// public: // public:

View File

@ -25,7 +25,7 @@ public:
} }
private: private:
bool happended_ = false; bool happended_ GUARDED_BY(mutex_) = false;
Mutex mutex_; Mutex mutex_;
}; };

View File

@ -159,9 +159,9 @@ private:
void ClearCurrentTaskQueue(); void ClearCurrentTaskQueue();
mutable Mutex mutex_; mutable Mutex mutex_;
std::queue<std::function<void()>> messages_; std::queue<std::function<void()>> messages_ GUARDED_BY(mutex_);
std::priority_queue<DelayedMessage> delayed_messages_; std::priority_queue<DelayedMessage> delayed_messages_ GUARDED_BY(mutex_);
uint32_t delayed_next_num_; uint32_t delayed_next_num_ GUARDED_BY(mutex_);
bool fInitialized_; bool fInitialized_;
bool fDestroyed_; bool fDestroyed_;
std::atomic<int> stop_; std::atomic<int> stop_;
@ -183,8 +183,9 @@ public:
AutoSocketServerThread(const AutoSocketServerThread &) = delete; AutoSocketServerThread(const AutoSocketServerThread &) = delete;
AutoSocketServerThread &operator=(const AutoSocketServerThread &) = delete; AutoSocketServerThread &operator=(const AutoSocketServerThread &) = delete;
private: private:
Thread* old_thread_; Thread *old_thread_;
}; };
}// namespace sled }// namespace sled