ActiveObject.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
24 
25 namespace icl_core {
26 namespace thread {
27 
29  : Thread(description, priority),
30  m_sem(0)
31 {
32 }
33 
35 {
36  onThreadStart();
37 
38  // Continually process the operation queue.
39  while (execute())
40  {
41  m_sem.wait();
42  if (execute())
43  {
44  // Process all queued operations.
45  while (!m_operation_queue.empty())
46  {
47  // Try to lock the queue mutex
49  {
50  // Extract the next pending operation from the queue.
51  ActiveOperation *op = m_operation_queue.front();
52  m_operation_queue.pop_front();
53 
54  // Release the mutex before executing the operation!
56 
57  // Finally, execute the operation.
58  op->invoke();
59  delete op;
60  }
61  }
62  }
63  }
64 
65  // Delete any pending operations.
66  while (!m_operation_queue.empty())
67  {
68  delete m_operation_queue.front();
69  m_operation_queue.pop_front();
70  }
71 
72  onThreadStop();
73 }
74 
76 {
77  Thread::stop();
78  m_sem.post();
79 }
80 
81 void ActiveObject::queue(ActiveOperation *active_operation)
82 {
84  {
85  m_operation_queue.push_back(active_operation);
87  m_sem.post();
88  }
89  else
90  {
91  delete active_operation;
92  }
93 }
94 
95 }
96 }
ActiveObject(const icl_core::String &description, icl_core::ThreadPriority priority=0)
void queue(ActiveOperation *active_operation)
std::string String
Definition: BaseTypes.h:43
icl_core::List< ActiveOperation * > m_operation_queue
Definition: ActiveObject.h:88
int32_t ThreadPriority
Definition: os_thread.h:50


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58