mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-26 04:10:09 +01:00
mesa: Fix tiny race condition in _mesa_debug_get_id
Two threads enter and see *id == 0. Both threads update the value. Upon returning, one of the threads might see the overwritten value some of the time and the updated value other times. Use cmpxchg to ensure that there's only ever one value written to *id. Reviewed-by: Matt Turner <mattst88@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12136>
This commit is contained in:
parent
5ffbee84a4
commit
5cee8434fd
1 changed files with 2 additions and 1 deletions
|
|
@ -193,7 +193,8 @@ void
|
|||
_mesa_debug_get_id(GLuint *id)
|
||||
{
|
||||
if (!(*id)) {
|
||||
*id = p_atomic_inc_return(&PrevDynamicID);
|
||||
/* Don't update *id if we raced with some other thread. */
|
||||
p_atomic_cmpxchg(id, 0, p_atomic_inc_return(&PrevDynamicID));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue