PaCO++  0.05
paco_omni.cc
Go to the documentation of this file.
1 #include "paco_omni.h"
2 
4 {
5 }
6 
8 {
9 }
10 
12 {
13  mutex = new omni_mutex();
14 }
15 
17 {
18  delete mutex;
19 }
20 
21 void
23 {
24  mutex->lock();
25 }
26 
27 void
29 {
30  mutex->unlock();
31 }
32 
34 {
35  condition = new omni_condition(m->mutex);
36 }
37 
39 {
40  delete condition;
41 }
42 
43 void
45 {
46  condition->wait();
47 };
48 
49 void
51 {
52  condition->signal();
53 };
54 
56 {
57  return new paco_omni_mutex();
58 }
59 
61 {
62  return new paco_omni_condition((paco_omni_mutex*) mutex);
63 }
64 
65 paco_thread * paco_omni_fabrique::paco_create_thread(void* (*fn)(void*), void* arg)
66 {
67  // paco_omni_thread * th = new paco_omni_thread();
68  // to have a detached thread !
69  void (*fn_detached)(void*) = (void (*)(void *))fn;
70  //th->thread = omni_thread::create(fn_detached,arg);
71  try
72  {
73  omni_thread::create(fn_detached,arg);
74  }
75  catch (omni_thread_fatal &e)
76  {
77  int end = 0;
78  while (end != 1)
79  {
80  cerr << "paco_create_thread error : " << e.error << endl;
81  end = end + 1;
82  omni_thread::sleep(2);
83  try
84  {
85  omni_thread::create(fn_detached,arg);
86  }
87  catch (omni_thread_fatal &e)
88  {
89  end = end - 1;
90  }
91  }
92  }
93  //return th;
94  return NULL;
95 }
96 
97 paco_thread * paco_omni_fabrique::paco_create_thread(void (*fn)(void*), void* arg)
98 {
99  try
100  {
101  omni_thread::create(fn,arg);
102  }
103  catch (omni_thread_fatal &e)
104  {
105  int end = 0;
106  while (end != 1)
107  {
108  cerr << "paco_create_thread error : " << e.error << endl;
109  end = end + 1;
110  omni_thread::sleep(2);
111  try
112  {
113  omni_thread::create(fn,arg);
114  }
115  catch (omni_thread_fatal &e)
116  {
117  end = end - 1;
118  }
119  }
120  }
121  return NULL;
122 }
omni_mutex * mutex
Definition: paco_omni.h:23
paco_thread * paco_create_thread(void *(*fn)(void *), void *arg=NULL)
Definition: paco_omni.cc:65
paco_mutex * paco_create_mutex()
Definition: paco_omni.cc:55
paco_condition * paco_create_condition(paco_mutex *mutex)
Definition: paco_omni.cc:60
virtual ~paco_omni_thread()
Definition: paco_omni.cc:7
paco_omni_condition(paco_omni_mutex *m)
Definition: paco_omni.cc:33