Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
semaphore-tests.cc File Reference
#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread.hpp>
#include <gtest/gtest.h>
#include <scroom/function-additor.hh>
#include <scroom/semaphore.hh>
#include "helpers.hh"
Include dependency graph for semaphore-tests.cc:

Functions

void test_count_equals (Semaphore *s, int i)
 
 ASSERT_FALSE (s1.try_P())
 
 ASSERT_TRUE (s2.try_P())
 
 ASSERT_FALSE (s2.try_P())
 
s V ()
 
boost::thread t (5 *pass(&s))
 
t timed_join (millisec(250))
 
 ASSERT_TRUE (success)
 
 if (!success)
 
 ASSERT_FALSE (s.P(millisec(250)))
 
 ASSERT_TRUE (s.P(millisec(250)))
 

Variables

Semaphore s2 (1)
 
test_count_equalss
 
bool const success = boost::thread::id() == t.get_id()
 

Function Documentation

◆ ASSERT_FALSE() [1/3]

ASSERT_FALSE ( s.  Pmillisec(250))

◆ ASSERT_FALSE() [2/3]

ASSERT_FALSE ( s1.  try_P())

Referenced by test_count_equals().

Here is the caller graph for this function:

◆ ASSERT_FALSE() [3/3]

ASSERT_FALSE ( s2.  try_P())

◆ ASSERT_TRUE() [1/3]

ASSERT_TRUE ( s.  Pmillisec(250))

◆ ASSERT_TRUE() [2/3]

ASSERT_TRUE ( s2.  try_P())

Referenced by if(), and test_count_equals().

Here is the caller graph for this function:

◆ ASSERT_TRUE() [3/3]

ASSERT_TRUE ( success  )

◆ if()

if ( success)
105 {
106 t.interrupt();
107 t.timed_join(millisec(250));
108 ASSERT_TRUE(boost::thread::id() == t.get_id());
109 }
ASSERT_TRUE(s2.try_P())
ThreadPool t(0)
Here is the call graph for this function:

◆ t()

boost::thread t ( 5 *pass s)

◆ test_count_equals()

void test_count_equals ( Semaphore s,
int  i 
)
26{
27 for(int actual = 0; actual < i; actual++)
28 {
29 ASSERT_TRUE(s->try_P()) << "Could only decrement " << actual << " times, instead of " << i;
30 }
31 ASSERT_FALSE(s->try_P()) << "Can decrement " << (i + 1) << " times, instead of " << i;
32}
ASSERT_FALSE(s1.try_P())
test_count_equals & s
Definition semaphore-tests.cc:48
Here is the call graph for this function:

◆ timed_join()

t timed_join ( millisec(250)  )

◆ V()

s V ( )

Variable Documentation

◆ s

Initial value:
{
Definition semaphore.hh:16

Referenced by test_count_equals().

◆ s2

Semaphore s2(1) ( )

◆ success

bool const success = boost::thread::id() == t.get_id()