File: Sat.cc

package info (click to toggle)
libzypp 17.25.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 30,144 kB
  • sloc: cpp: 94,656; xml: 2,575; sh: 700; makefile: 34; python: 12
file content (121 lines) | stat: -rw-r--r-- 2,868 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>

#include <boost/thread.hpp>
#include <boost/thread/thread_time.hpp>
namespace boost
{
  namespace detail
  {
    inline std::ostream & operator<<( std::ostream & str, const thread_data_base & obj )
    { return str << &obj; }
  }
}

#include <zypp/ByteCount.h>
#include <zypp/Pathname.h>
#include <zypp/base/Logger.h>
#include <zypp/base/LogControl.h>

using std::endl;
using namespace zypp;

#undef MIL
#define MIL MilSync( L_BASEFILE, __FUNCTION__, __LINE__ )._str

#ifdef _REENTRANT
#warning _REENTRANT
#else
#warning NOT_REENTRANT
#endif

template <class Derived>
struct ClassLevelLockable
{
  typedef boost::recursive_mutex Lockable;

  typedef boost::lock_guard<Lockable> Lock;
  struct Lock
  {
    Lock( const Derived & obj )
    {}
    ~Lock
  };

  Lockable _mutex;
};

template <class Derived>
struct ObjectLevelLockable
{
  typedef boost::recursive_mutex Lockable;
  typedef boost::lock_guard<Lockable> Lock;

};


struct MilSync
{
  MilSync( const char * file_r, const char * func_r, const int line_r )
    : _guard( _mutex )
    , _str( zypp::base::logger::getStream( ZYPP_BASE_LOGGER_LOGGROUP, zypp::base::logger::E_MIL, file_r, func_r, line_r ) )
  {}
  typedef boost::recursive_mutex Lockable;
  static Lockable             _mutex;
  boost::lock_guard<Lockable> _guard;
  std::ostream & _str;
};
MilSync::Lockable MilSync::_mutex;

struct ThreadExcl
{
  ThreadExcl()
  {
    MIL << "+TE" << boost::this_thread::get_id() << endl;
    boost::this_thread::sleep(  boost::posix_time::seconds(1) );
  }

  ~ThreadExcl()
  {
    MIL << "-TE" << boost::this_thread::get_id() << endl;
  }
};

void t_exit()
{
  MIL << "---" << boost::this_thread::get_id() << endl;
}

void t_main()
{
  MIL << "+++" << boost::this_thread::get_id() << " " << boost::this_thread::interruption_enabled() << endl;
  boost::this_thread::at_thread_exit( t_exit );
  ThreadExcl a;
  while( true )
    boost::this_thread::sleep(  boost::posix_time::seconds(1) );
}

int main( int argc, char * argv[] )
{
  //zypp::base::LogControl::instance().logfile( "log.restrict" );
  INT << "===[START]==========================================" << endl;

  MIL << "M+++" << boost::this_thread::get_id() << endl;
  boost::thread_group mthreads;

  mthreads.create_thread( t_main );
  mthreads.create_thread( t_main );
  mthreads.create_thread( t_main );
  mthreads.create_thread( t_main );
  mthreads.create_thread( t_main );

  MIL << "M???" << boost::this_thread::get_id() << endl;
  //boost::this_thread::sleep(  boost::posix_time::seconds(10) );
  mthreads.interrupt_all();
  mthreads.join_all();
  MIL << "M---" << boost::this_thread::get_id() << endl;

  ///////////////////////////////////////////////////////////////////
  INT << "===[END]============================================" << endl << endl;
  zypp::base::LogControl::instance().logNothing();
  return 0;
}