"Fossies" - the Fresh Open Source Software Archive

Member "gstreamer-1.16.1/tests/benchmarks/gstclockstress.c" (19 Apr 2019, 2433 Bytes) of package /linux/misc/gstreamer-1.16.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* GStreamer
    2  * Copyright (C) <2009> Wim Taymans <wim taymans at gmail dot com>
    3  *
    4  * This library is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU Library General Public
    6  * License as published by the Free Software Foundation; either
    7  * version 2 of the License, or (at your option) any later version.
    8  *
    9  * This library is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12  * Library General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU Library General Public
   15  * License along with this library; if not, write to the
   16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
   17  * Boston, MA 02110-1301, USA.
   18  */
   19 
   20 #include <stdio.h>
   21 #include <stdlib.h>
   22 #include <gst/gst.h>
   23 #include <gst/glib-compat-private.h>
   24 
   25 #define MAX_THREADS  100
   26 
   27 static gboolean running = TRUE;
   28 static gint count = 0;
   29 
   30 static void *
   31 run_test (void *user_data)
   32 {
   33   gint prev;
   34   GstClock *sysclock = GST_CLOCK_CAST (user_data);
   35 
   36   while (running) {
   37     gst_clock_get_time (sysclock);
   38     prev = g_atomic_int_add (&count, 1);
   39     if (prev == G_MAXINT)
   40       g_warning ("overflow");
   41   }
   42   g_thread_exit (NULL);
   43   return NULL;
   44 }
   45 
   46 gint
   47 main (gint argc, gchar * argv[])
   48 {
   49   GThread *threads[MAX_THREADS];
   50   gint num_threads;
   51   gint t;
   52   GstClock *sysclock;
   53 
   54   gst_init (&argc, &argv);
   55 
   56   if (argc != 2) {
   57     g_print ("usage: %s <num_threads>\n", argv[0]);
   58     exit (-1);
   59   }
   60 
   61   num_threads = atoi (argv[1]);
   62 
   63   if (num_threads <= 0 || num_threads > MAX_THREADS) {
   64     g_print ("number of threads must be between 0 and %d\n", MAX_THREADS);
   65     exit (-2);
   66   }
   67 
   68   sysclock = gst_system_clock_obtain ();
   69 
   70   for (t = 0; t < num_threads; t++) {
   71     GError *error = NULL;
   72 
   73     threads[t] = g_thread_try_new ("clockstresstest", run_test,
   74         sysclock, &error);
   75 
   76     if (error) {
   77       printf ("ERROR: g_thread_try_new() %s\n", error->message);
   78       g_clear_error (&error);
   79       exit (-1);
   80     }
   81   }
   82   printf ("main(): Created %d threads.\n", t);
   83 
   84   /* run for 5 seconds */
   85   g_usleep (G_USEC_PER_SEC * 5);
   86 
   87   printf ("main(): Stopping threads...\n");
   88 
   89   running = FALSE;
   90 
   91   for (t = 0; t < num_threads; t++) {
   92     g_thread_join (threads[t]);
   93   }
   94 
   95   g_print ("performed %d get_time operations\n", count);
   96 
   97   gst_object_unref (sysclock);
   98 
   99   return 0;
  100 }