Peano
Loading...
Searching...
No Matches
ServiceRepository.cpp
Go to the documentation of this file.
1#include "ServiceRepository.h"
2
3#include "tarch/tarch.h"
4#include "tarch/Assertions.h"
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 #if !defined(SharedTBB)
51 tarch::multicore::RecursiveLock lock(_receiveDanglingMessagesSemaphore);
52 #endif
53
54 _services.push_back( entry );
55}
56
57
59 tarch::multicore::RecursiveLock lock(_receiveDanglingMessagesSemaphore);
60 for (std::vector<ServiceEntry>::iterator p=_services.begin(); p!=_services.end(); ) {
61 if ( p->_service==service) {
62 p = _services.erase(p);
63 }
64 else p++;
65 }
66}
67
68
70 for (
71 ServiceContainer::const_iterator p = _services.begin();
72 p != _services.end();
73 p++
74 ) {
75 if (p->_service==service) {
76 return true;
77 }
78 }
79 return false;
80}
81
82
84 #ifdef UseSmartMPI
85 smartmpi::chime();
86 #endif
87
88 // Don't do such a thing. See docu
89 // tarch::multicore::processPendingTasks(1);
90
91 tarch::multicore::RecursiveLock lock(_receiveDanglingMessagesSemaphore,false);
92 if ( lock.tryLock() ) {
93 for (
94 ServiceContainer::iterator p = _services.begin();
95 p != _services.end();
96 p++
97 ) {
98 p->_service->receiveDanglingMessages();
99 }
100 }
101}
102
103
105 std::ostringstream result;
106 for (
107 ServiceContainer::const_iterator p = _services.begin();
108 p != _services.end();
109 p++
110 ) {
111 result << " " << p->_name;
112 }
113 return result.str();
114}
115
#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