tinyds: use 'rand_r' instead of function 'rand' 47/280847/1
authorduna.oh <duna.oh@samsung.com>
Fri, 2 Sep 2022 06:28:39 +0000 (15:28 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Tue, 6 Sep 2022 01:55:54 +0000 (10:55 +0900)
For thread safety, rand_r is preferred to use.

Change-Id: I56fef4a94ee5110b090add7c1449797956c93db3

examples/tinyds-tdm.c

index 8ffaec5..26ff72c 100644 (file)
@@ -430,6 +430,8 @@ view_handle_surface_commit(struct wl_listener *listener,
 static void
 server_new_xdg_surface(struct wl_listener *listener, void *data)
 {
+    static unsigned int seedx = 1;
+    static unsigned int seedy = 43210;
     struct tinyds_server *server;
     struct tinyds_view *view;
     struct ds_xdg_surface *xdg_surface;
@@ -462,8 +464,8 @@ server_new_xdg_surface(struct wl_listener *listener, void *data)
             ds_xdg_surface_get_surface(xdg_surface),
             &view->surface_commit);
 
-    view->x = rand() % 1000;
-    view->y = rand() % 500;
+    view->x = rand_r(&seedx) % 1000;
+    view->y = rand_r(&seedy) % 500;
 
     view->hwc_window = ds_tdm_output_hwc_window_create(server->output->hwc);
     assert(view->hwc_window);