mesa: fix locking when destroying/overwriting/adding display lists
authorMarek Olšák <marek.olsak@amd.com>
Fri, 22 Oct 2021 19:15:35 +0000 (15:15 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 29 Oct 2021 07:33:50 +0000 (07:33 +0000)
We need to hold the lock when calling destroy_list and doing
_mesa_HashInsertLocked in EndList.

So move the locking out of destroy_list.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13506>

src/mesa/main/dlist.c

index 611c4c3..895e013 100644 (file)
@@ -1453,7 +1453,7 @@ destroy_list(struct gl_context *ctx, GLuint list)
    if (list == 0)
       return;
 
-   dlist = _mesa_lookup_list(ctx, list, false);
+   dlist = _mesa_lookup_list(ctx, list, true);
    if (!dlist)
       return;
 
@@ -1467,10 +1467,8 @@ destroy_list(struct gl_context *ctx, GLuint list)
                      check_atlas_for_deleted_list, &list);
    }
 
-   _mesa_HashLockMutex(ctx->Shared->DisplayList);
    _mesa_delete_list(ctx, dlist);
    _mesa_HashRemoveLocked(ctx->Shared->DisplayList, list);
-   _mesa_HashUnlockMutex(ctx->Shared->DisplayList);
 }
 
 
@@ -13487,9 +13485,11 @@ _mesa_DeleteLists(GLuint list, GLsizei range)
       }
    }
 
+   _mesa_HashLockMutex(ctx->Shared->DisplayList);
    for (i = list; i < list + range; i++) {
       destroy_list(ctx, i);
    }
+   _mesa_HashUnlockMutex(ctx->Shared->DisplayList);
 }
 
 
@@ -13798,8 +13798,6 @@ _mesa_EndList(void)
       list->CurrentList->begins_with_a_nop = false;
    }
 
-   _mesa_HashUnlockMutex(ctx->Shared->DisplayList);
-
    /* Destroy old list, if any */
    destroy_list(ctx, ctx->ListState.CurrentList->Name);
 
@@ -13808,10 +13806,11 @@ _mesa_EndList(void)
                           ctx->ListState.CurrentList->Name,
                           ctx->ListState.CurrentList, true);
 
-
    if (MESA_VERBOSE & VERBOSE_DISPLAY_LIST)
       mesa_print_display_list(ctx->ListState.CurrentList->Name);
 
+   _mesa_HashUnlockMutex(ctx->Shared->DisplayList);
+
    ctx->ListState.CurrentList = NULL;
    ctx->ListState.CurrentBlock = NULL;
    ctx->ListState.CurrentPos = 0;