mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Guard pool drain against pending layer callbacks
This commit is contained in:
1 parent
3bef9a4200
commit
689ecc40ad
1 file changed
+9
-17
@@ -427,27 +427,18 @@ static void retire_sc(struct layer *l) {
|
||||
|
||||
static void drain_and_free_pools(void) {
|
||||
int64_t deadline = now_ns() + 300000000LL;
|
||||
for (;;) {
|
||||
int pending;
|
||||
do {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
int pending = g_pending_cb;
|
||||
pending = g_pending_cb;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
if (!pending || now_ns() > deadline) break;
|
||||
usleep(2000);
|
||||
} while (1);
|
||||
if (pending) {
|
||||
droiddeck_log("layer", "pool drain deferred while %d SurfaceControl callbacks are pending", pending);
|
||||
return;
|
||||
}
|
||||
pthread_mutex_lock(&g_lock);
|
||||
for (int i = 0; i < SC_LAYER_COUNT; i++) {
|
||||
for (int j = 0; j < POOL_MAX; j++) {
|
||||
struct slot *s = &g_layers[i].slots[j];
|
||||
if (s->release_fd >= 0) { struct pollfd p = {.fd = s->release_fd, .events = POLLIN}; poll(&p, 1, 100); close(s->release_fd); }
|
||||
if (s->img) vkp_image_destroy(s->img);
|
||||
if (s->ahb) AHardwareBuffer_release(s->ahb);
|
||||
memset(s, 0, sizeof(*s));
|
||||
s->release_fd = -1;
|
||||
}
|
||||
g_layers[i].first_logged = 0;
|
||||
g_layers[i].logged_w = g_layers[i].logged_h = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
for (int i = 0; i < SC_LAYER_COUNT; i++) {
|
||||
if (g_layers[i].sc) {
|
||||
droiddeck_log("layer", "pool drain deferred while %s still owns a SurfaceControl", g_layers[i].name);
|
||||
@@ -656,7 +647,8 @@ static int take_free_slot(struct layer *l, int w, int h, uint32_t fmt, int *wait
|
||||
if (s->ahb && (s->w != w || s->h != h || s->fmt != fmt)) {
|
||||
if (fd >= 0) { close(fd); fd = -1; }
|
||||
vkp_image_destroy(s->img); AHardwareBuffer_release(s->ahb);
|
||||
memset(s, 0, sizeof(*s)); s->release_fd = -1;
|
||||
const uint64_t generation = s->generation;
|
||||
memset(s, 0, sizeof(*s)); s->release_fd = -1; s->generation = generation;
|
||||
}
|
||||
if (fd >= 0 && !vkp_can_wait_sync_fd()) {
|
||||
if (fence_wait(fd, 100) == 0) { slot_keep_fence(s, fd); return -1; }
|
||||
|
||||
Reference in new issue
Block a user