Peano 4
Loading...
Searching...
No Matches
ServiceRepository.cpp
Go to the documentation of this file.
2#include "tarch/Assertions.h"
3#include "tarch/tarch.h"
6
7
8#ifdef UseSmartMPI
9#include "smartmpi.h"
10#endif
11
12#include <sstream>
13
14
16
17
21
22
26
27
30
31
34
35
39
40
41void tarch::services::ServiceRepository::addService( Service* const service, const std::string& name ) {
42 assertion2( service!=0, name, getListOfRegisteredServices() );
43 assertion2( !name.empty(), name, getListOfRegisteredServices() );
44 assertion2( !hasService(service), name, getListOfRegisteredServices() );
45
46 ServiceEntry entry;
47 entry._name = name;
48 entry._service = service;
49
50 tarch::multicore::RecursiveLock lock(_receiveDanglingMessagesSemaphore);
51 _services.push_back( entry );
52}
53
54
56 tarch::multicore::RecursiveLock lock(_receiveDanglingMessagesSemaphore);
57 for (std::vector<ServiceEntry>::iterator p=_services.begin(); p!=_services.end(); ) {
58 if ( p->_service==service) {
59 p = _services.erase(p);
60 }
61 else p++;
62 }
63}
64
65
67 for (
68 ServiceContainer::const_iterator p = _services.begin();
69 p != _services.end();
70 p++
71 ) {
72 if (p->_service==service) {
73 return true;
74 }
75 }
76 return false;
77}
78
79
81 #ifdef UseSmartMPI
82 smartmpi::chime();
83 #endif
84
85 // Don't do such a thing. See docu
86 // tarch::multicore::processPendingTasks(1);
87
88 tarch::multicore::RecursiveLock lock(_receiveDanglingMessagesSemaphore,false);
89 if ( lock.tryLock() ) {
90 for (
91 ServiceContainer::iterator p = _services.begin();
92 p != _services.end();
93 p++
94 ) {
95 p->_service->receiveDanglingMessages();
96 }
97 }
98}
99
100
102 std::ostringstream result;
103 for (
104 ServiceContainer::const_iterator p = _services.begin();
105 p != _services.end();
106 p++
107 ) {
108 result << " " << p->_name;
109 }
110 return result.str();
111}
112
#define assertion2(expr, param0, param1)
Create a lock around a boolean semaphore region.
virtual void receiveDanglingMessages() override
Answer to MPI Messages.
static tarch::services::ServiceRepository _singleton
static ServiceRepository & getInstance()
void init()
Maybe the only service that you don't have to init and shutdown.
void removeService(Service *const service)
This routine is thread-safe, i.e.
bool hasService(Service *service) const
This routine is thread-safe.
void addService(Service *const service, const std::string &name)
Add a new service.
Service Interface.
Definition Service.h:87