mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2026-01-09 10:01:41 +01:00
JBR-6522: ensure thread-safety in MTLGC_DestroyMTLGraphicsConfig (pthread_mutex_t)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@@ -29,6 +29,8 @@
|
||||
#import "ThreadUtilities.h"
|
||||
#import "awt.h"
|
||||
|
||||
static pthread_mutex_t destroy_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/**
|
||||
* Disposes all memory and resources associated with the given
|
||||
* MTLGraphicsConfigInfo (including its native MTLContext data).
|
||||
@@ -46,10 +48,16 @@ MTLGC_DestroyMTLGraphicsConfig(jlong pConfigInfo)
|
||||
return;
|
||||
}
|
||||
|
||||
MTLContext *mtlc = (MTLContext*)mtlinfo->context;
|
||||
if (mtlc != NULL) {
|
||||
[mtlinfo->context release];
|
||||
mtlinfo->context = nil;
|
||||
if (mtlinfo->context != NULL) {
|
||||
// Ensure thread-safe free:
|
||||
pthread_mutex_lock(&destroy_mutex);
|
||||
|
||||
const MTLContext *mtlc = (MTLContext*)mtlinfo->context;
|
||||
if (mtlc != NULL) {
|
||||
mtlinfo->context = nil;
|
||||
[mtlc release];
|
||||
}
|
||||
pthread_mutex_unlock(&destroy_mutex);
|
||||
}
|
||||
free(mtlinfo);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user