Allow callers of SkEventTracer::SetInstance to avoid installing atexit() callback.
Bug: skia:13178 Change-Id: I9505b211e6afa6872ac51837964394f2a1a84916 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/534500 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
13fda2a4e7
commit
93b0629262
@ -27,8 +27,14 @@ public:
|
||||
* If this is the first call to SetInstance or GetInstance then the passed instance is
|
||||
* installed and true is returned. Otherwise, false is returned. In either case ownership of the
|
||||
* tracer is transferred and it will be deleted when no longer needed.
|
||||
*
|
||||
* Not deleting the tracer on process exit should not cause problems as
|
||||
* the whole heap is about to go away with the process. This can also
|
||||
* improve performance by reducing the amount of work needed.
|
||||
*
|
||||
* @param leakTracer Do not delete tracer on process exit.
|
||||
*/
|
||||
static bool SetInstance(SkEventTracer*);
|
||||
static bool SetInstance(SkEventTracer*, bool leakTracer = false);
|
||||
|
||||
/**
|
||||
* Gets the event tracer. If this is the first call to SetInstance or GetIntance then a default
|
||||
|
@ -43,13 +43,17 @@ class SkDefaultEventTracer : public SkEventTracer {
|
||||
// We prefer gUserTracer if it's been set, otherwise we fall back on a default tracer;
|
||||
static std::atomic<SkEventTracer*> gUserTracer{nullptr};
|
||||
|
||||
bool SkEventTracer::SetInstance(SkEventTracer* tracer) {
|
||||
bool SkEventTracer::SetInstance(SkEventTracer* tracer, bool leakTracer) {
|
||||
SkEventTracer* expected = nullptr;
|
||||
if (!gUserTracer.compare_exchange_strong(expected, tracer)) {
|
||||
delete tracer;
|
||||
return false;
|
||||
}
|
||||
atexit([]() { delete gUserTracer.load(); });
|
||||
// If leaking the tracer is accepted then there is no need to install
|
||||
// the atexit.
|
||||
if (!leakTracer) {
|
||||
atexit([]() { delete gUserTracer.load(); });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user