github-actions[bot] commented on code in PR #63109:
URL: https://github.com/apache/doris/pull/63109#discussion_r3246444931


##########
be/src/common/thread_safety_annotations.h:
##########
@@ -119,6 +141,32 @@ class SCOPED_CAPABILITY LockGuard {
     MutexType& _mu;
 };
 
+// RAII scoped shared lock guard annotated for thread safety analysis.
+// In BE_TEST builds, injects a random sleep before acquiring and after
+// releasing the lock to exercise concurrent code paths.
+template <typename MutexType>
+class SCOPED_CAPABILITY SharedLockGuard {
+public:
+    explicit SharedLockGuard(MutexType& mu) ACQUIRE_SHARED(mu) : _mu(mu) {
+#ifdef BE_TEST
+        doris::mock_random_sleep();
+#endif
+        _mu.lock_shared();
+    }
+    ~SharedLockGuard() RELEASE() {

Review Comment:
   This currently makes the new guard fail the same Clang thread-safety 
analysis it is meant to enable. With the current header, a minimal use such as 
`SharedLockGuard g(mu); auto it = m.find(1);` under `-Wthread-safety` reports 
`warning: releasing mutex 'g' using shared access, expected exclusive access` 
at scope exit. For a `SCOPED_CAPABILITY` RAII object, the constructor records 
that it acquired `mu` in shared mode, but the no-argument destructor releases 
the scoped lock object itself, so it should use the normal release annotation 
while `AnnotatedSharedMutex::unlock_shared()` keeps `RELEASE_SHARED()`.
   
   ```suggestion
       ~SharedLockGuard() RELEASE() {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to