use PTHREAD_MUTEX_INITIALIZER for static mutex 01/213301/3
authorChangyeon Lee <cyeon.lee@samsung.com>
Wed, 4 Sep 2019 05:52:29 +0000 (14:52 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Wed, 4 Sep 2019 10:23:56 +0000 (19:23 +0900)
Change-Id: Id9b175c21fe56b744f8e6a27394bcf206e927008

src/tbm_bufmgr.c
src/tbm_dummy_display.c
src/tbm_surface_internal.c
src/tbm_surface_queue.c

index e1be447..3fe38b1 100644 (file)
@@ -92,32 +92,10 @@ void _tbm_bufmgr_mutex_unlock(void);
 }
 
 /* LCOV_EXCL_START */
-static bool
-_tbm_bufmgr_mutex_init(void)
-{
-       static bool tbm_bufmgr_mutex_init = false;
-
-       if (tbm_bufmgr_mutex_init)
-               return true;
-
-       if (pthread_mutex_init(&tbm_bufmgr_lock, NULL)) {
-               TBM_ERR("fail: Cannot pthread_mutex_init for tbm_bufmgr_lock.\n");
-               return false;
-       }
-
-       tbm_bufmgr_mutex_init = true;
-
-       return true;
-}
 
 void
 _tbm_bufmgr_mutex_lock(void)
 {
-       if (!_tbm_bufmgr_mutex_init()) {
-               TBM_ERR("fail: _tbm_bufmgr_mutex_init()\n");
-               return;
-       }
-
        pthread_mutex_lock(&tbm_bufmgr_lock);
 }
 
index 6bce30c..0839cb2 100644 (file)
@@ -38,39 +38,16 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 static int init_list = 0;
 static struct list_head g_dummy_display_list;
-static pthread_mutex_t tbm_dummy_display_lock;
+static pthread_mutex_t tbm_dummy_display_lock = PTHREAD_MUTEX_INITIALIZER;
 void _tbm_dummy_display_mutex_unlock(void);
 
 struct _tbm_dummy_display {
        struct list_head link;
 };
 
-static bool
-_tbm_dummy_display_mutex_init(void)
-{
-       static bool tbm_dummy_display_mutex_init = false;
-
-       if (tbm_dummy_display_mutex_init)
-               return true;
-
-       if (pthread_mutex_init(&tbm_dummy_display_lock, NULL)) {
-               TBM_ERR("fail: pthread_mutex_init for tbm_dummy_display_lock.\n");
-               return false;
-       }
-
-       tbm_dummy_display_mutex_init = true;
-
-       return true;
-}
-
 void
 _tbm_dummy_display_mutex_lock(void)
 {
-       if (!_tbm_dummy_display_mutex_init()) {
-               TBM_ERR("fail: _tbm_dummy_display_mutex_init.\n");
-               return;
-       }
-
        pthread_mutex_lock(&tbm_dummy_display_lock);
 }
 
index ee055d7..4cc186f 100644 (file)
@@ -42,7 +42,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <pixman.h>
 
 static tbm_bufmgr g_surface_bufmgr;
-static pthread_mutex_t tbm_surface_lock;
+static pthread_mutex_t tbm_surface_lock = PTHREAD_MUTEX_INITIALIZER;
 void _tbm_surface_mutex_unlock(void);
 
 #define C(b, m)              (((b) >> (m)) & 0xFF)
@@ -220,32 +220,9 @@ _tbm_surface_internal_format_to_str(tbm_format format)
        }
 }
 
-static bool
-_tbm_surface_mutex_init(void)
-{
-       static bool tbm_surface_mutex_init = false;
-
-       if (tbm_surface_mutex_init)
-               return true;
-
-       if (pthread_mutex_init(&tbm_surface_lock, NULL)) {
-               TBM_ERR("fail: pthread_mutex_init for tbm_surface_lock.\n");
-               return false;
-       }
-
-       tbm_surface_mutex_init = true;
-
-       return true;
-}
-
 void
 _tbm_surface_mutex_lock(void)
 {
-       if (!_tbm_surface_mutex_init()) {
-               TBM_ERR("fail: _tbm_surface_mutex_init.\n");
-               return;
-       }
-
        pthread_mutex_lock(&tbm_surface_lock);
 }
 
index 06ddc5d..40b5c9d 100644 (file)
@@ -40,7 +40,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define NODE_LIST      4
 
 static tbm_bufmgr g_surf_queue_bufmgr;
-static pthread_mutex_t tbm_surf_queue_lock;
+static pthread_mutex_t tbm_surf_queue_lock = PTHREAD_MUTEX_INITIALIZER;
 void _tbm_surface_queue_mutex_unlock(void);
 
 /* check condition */
@@ -154,32 +154,9 @@ struct _tbm_surface_queue {
        unsigned int acquire_sync_count;
 };
 
-static bool
-_tbm_surf_queue_mutex_init(void)
-{
-       static bool tbm_surf_queue_mutex_init = false;
-
-       if (tbm_surf_queue_mutex_init)
-               return true;
-
-       if (pthread_mutex_init(&tbm_surf_queue_lock, NULL)) {
-               TBM_ERR("fail: pthread_mutex_init\n");
-               return false;
-       }
-
-       tbm_surf_queue_mutex_init = true;
-
-       return true;
-}
-
 static void
 _tbm_surf_queue_mutex_lock(void)
 {
-       if (!_tbm_surf_queue_mutex_init()) {
-               TBM_ERR("fail: _tbm_surf_queue_mutex_init\n");
-               return;
-       }
-
        pthread_mutex_lock(&tbm_surf_queue_lock);
 }