-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from DataDog/rgs/async-sample-mutex-interleav…
…ed-test fix async-sample mutex
- Loading branch information
Showing
7 changed files
with
83 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef ASYNCSAMPLEMUTEX_H | ||
#define ASYNCSAMPLEMUTEX_H | ||
|
||
#include "threadLocalData.h" | ||
|
||
// controls access to AGCT | ||
class AsyncSampleMutex { | ||
private: | ||
ThreadLocalData* _threadLocalData; | ||
bool _acquired; | ||
|
||
bool try_acquire() { | ||
if (_threadLocalData != nullptr && !_threadLocalData->is_unwinding_Java()) { | ||
_threadLocalData->set_unwinding_Java(true); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public: | ||
AsyncSampleMutex(ThreadLocalData* threadLocalData) : _threadLocalData(threadLocalData) { | ||
_acquired = try_acquire(); | ||
} | ||
|
||
AsyncSampleMutex(AsyncSampleMutex& other) = delete; | ||
|
||
~AsyncSampleMutex() { | ||
if (_acquired) { | ||
_threadLocalData->set_unwinding_Java(false); | ||
} | ||
} | ||
|
||
bool acquired() { | ||
return _acquired; | ||
} | ||
}; | ||
|
||
#endif //ASYNCSAMPLEMUTEX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef THREADLOCALDATA_H | ||
#define THREADLOCALDATA_H | ||
|
||
class ThreadLocalData { | ||
protected: | ||
bool _unwinding_Java; | ||
public: | ||
ThreadLocalData() : _unwinding_Java(false) {} | ||
virtual bool is_unwinding_Java() final { | ||
return _unwinding_Java; | ||
} | ||
|
||
virtual void set_unwinding_Java(bool unwinding_Java) final { | ||
_unwinding_Java = unwinding_Java; | ||
} | ||
}; | ||
|
||
#endif //THREADLOCALDATA_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters