File: test-mongoc-thread.c

package info (click to toggle)
syslog-ng 3.8.1-10
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 47,320 kB
  • ctags: 43,937
  • sloc: ansic: 159,432; yacc: 25,059; sh: 13,574; makefile: 4,669; python: 3,468; java: 3,218; xml: 2,309; perl: 318; lex: 316; awk: 184
file content (36 lines) | stat: -rw-r--r-- 808 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "mongoc-thread-private.h"

#include "TestSuite.h"


static void
test_cond_wait (void)
{
   int64_t start, duration_usec;
   mongoc_mutex_t mutex;
   mongoc_cond_t cond;

   mongoc_mutex_init (&mutex);
   mongoc_cond_init (&cond);

   mongoc_mutex_lock (&mutex);
   start = bson_get_monotonic_time ();
   mongoc_cond_timedwait (&cond, &mutex, 100);
   duration_usec = bson_get_monotonic_time () - start;
   mongoc_mutex_unlock (&mutex);

   if (!((50 * 1000 < duration_usec) && (150 * 1000 > duration_usec))) {
      fprintf (stderr, "expected to wait 100ms, waited %" PRId64 "\n",
               duration_usec);
   }

   mongoc_cond_destroy (&cond);
   mongoc_mutex_destroy (&mutex);
}


void
test_thread_install (TestSuite *suite)
{
   TestSuite_Add (suite, "/Thread/cond_wait", test_cond_wait);
}