Fix atomicity svace problem 59/160659/10
authorChangyeon Lee <cyeon.lee@samsung.com>
Fri, 17 Nov 2017 08:32:32 +0000 (17:32 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 20 Nov 2017 00:28:53 +0000 (00:28 +0000)
Change-Id: I90571af7f4f04b2fd1508dac760b899fb2406efb

src/tbm_surface_internal.c
src/tbm_surface_queue.c

index 8c356c1..3f5c61b 100644 (file)
@@ -1091,6 +1091,9 @@ tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
 {
        struct _tbm_surface *surf;
        tbm_bo_handle bo_handles[4];
+       int num_bos = 0;
+       tbm_bo bos[4];
+       int planes_bo_idx[TBM_SURF_PLANE_MAX];
        int i, j;
 
        _tbm_surface_mutex_lock();
@@ -1109,23 +1112,34 @@ tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
        info->size = surf->info.size;
        info->num_planes = surf->info.num_planes;
 
+       for (i = 0; i < surf->info.num_planes; i++) {
+               info->planes[i].size = surf->info.planes[i].size;
+               info->planes[i].offset = surf->info.planes[i].offset;
+               info->planes[i].stride = surf->info.planes[i].stride;
+               planes_bo_idx[i] = surf->planes_bo_idx[i];
+       }
+
+       for (i = 0; i < surf->num_bos; i++)
+               bos[i] = surf->bos[i];
+
+       num_bos = surf->num_bos;
+
        if (map == 1) {
-               for (i = 0; i < surf->num_bos; i++) {
-                       _tbm_surface_mutex_unlock();
-                       bo_handles[i] = tbm_bo_map(surf->bos[i], TBM_DEVICE_CPU, opt);
-                       _tbm_surface_mutex_lock();
+               _tbm_surface_mutex_unlock();
+               for (i = 0; i < num_bos; i++) {
+                       bo_handles[i] = tbm_bo_map(bos[i], TBM_DEVICE_CPU, opt);
                        if (bo_handles[i].ptr == NULL) {
                                for (j = 0; j < i; j++)
-                                       tbm_bo_unmap(surf->bos[j]);
+                                       tbm_bo_unmap(bos[j]);
 
                                TBM_LOG_E("error: tbm_surface(%p) opt(%d) map(%d)\n", surface, opt, map);
-                               _tbm_surface_mutex_unlock();
                                return 0;
                        }
                }
+               _tbm_surface_mutex_lock();
        } else {
-               for (i = 0; i < surf->num_bos; i++) {
-                       bo_handles[i] = tbm_bo_get_handle(surf->bos[i], TBM_DEVICE_CPU);
+               for (i = 0; i < num_bos; i++) {
+                       bo_handles[i] = tbm_bo_get_handle(bos[i], TBM_DEVICE_CPU);
                        if (bo_handles[i].ptr == NULL) {
                                TBM_LOG_E("error: tbm_surface(%p) opt(%d) map(%d)\n", surface, opt, map);
                                _tbm_surface_mutex_unlock();
@@ -1134,14 +1148,9 @@ tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
                }
        }
 
-       for (i = 0; i < surf->info.num_planes; i++) {
-               info->planes[i].size = surf->info.planes[i].size;
-               info->planes[i].offset = surf->info.planes[i].offset;
-               info->planes[i].stride = surf->info.planes[i].stride;
-
-               if (bo_handles[surf->planes_bo_idx[i]].ptr)
-                       info->planes[i].ptr = bo_handles[surf->planes_bo_idx[i]].ptr +
-                                             surf->info.planes[i].offset;
+       for (i = 0; i < info->num_planes; i++) {
+               if (bo_handles[planes_bo_idx[i]].ptr)
+                       info->planes[i].ptr = bo_handles[planes_bo_idx[i]].ptr + info->planes[i].offset;
        }
 
        TBM_TRACE("tbm_surface(%p) opt(%d) map(%d)\n", surface, opt, map);
index 9fe4066..3b89da1 100644 (file)
@@ -1305,17 +1305,7 @@ tbm_surface_queue_can_dequeue(tbm_surface_queue_h surface_queue, int wait)
                                                QUEUE_NODE_TYPE_ACQUIRE)) {
                _tbm_surf_queue_mutex_unlock();
                pthread_cond_wait(&surface_queue->free_cond, &surface_queue->lock);
-               _tbm_surf_queue_mutex_lock();
-
-               if (!_tbm_surface_queue_is_valid(surface_queue)) {
-                       TBM_LOG_E("surface_queue:%p is invalid", surface_queue);
-                       pthread_mutex_unlock(&surface_queue->lock);
-                       _tbm_surf_queue_mutex_unlock();
-                       return 0;
-               }
-
                pthread_mutex_unlock(&surface_queue->lock);
-               _tbm_surf_queue_mutex_unlock();
                return 1;
        }
 
@@ -1538,17 +1528,7 @@ tbm_surface_queue_can_acquire(tbm_surface_queue_h surface_queue, int wait)
                                                QUEUE_NODE_TYPE_DEQUEUE)) {
                _tbm_surf_queue_mutex_unlock();
                pthread_cond_wait(&surface_queue->dirty_cond, &surface_queue->lock);
-               _tbm_surf_queue_mutex_lock();
-
-               if (!_tbm_surface_queue_is_valid(surface_queue)) {
-                       TBM_LOG_E("surface_queue:%p is invalid", surface_queue);
-                       pthread_mutex_unlock(&surface_queue->lock);
-                       _tbm_surf_queue_mutex_unlock();
-                       return 0;
-               }
-
                pthread_mutex_unlock(&surface_queue->lock);
-               _tbm_surf_queue_mutex_unlock();
                return 1;
        }