A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Implement simcall_HANDLER_execution_waitany_for into ExecImpl::wait_any_for.
[simgrid.git]
/
src
/
kernel
/
activity
/
SemaphoreImpl.hpp
diff --git
a/src/kernel/activity/SemaphoreImpl.hpp
b/src/kernel/activity/SemaphoreImpl.hpp
index
f2d05b7
..
33793ce
100644
(file)
--- a/
src/kernel/activity/SemaphoreImpl.hpp
+++ b/
src/kernel/activity/SemaphoreImpl.hpp
@@
-18,12
+18,12
@@
namespace activity {
class XBT_PUBLIC SemaphoreImpl {
std::atomic_int_fast32_t refcount_{1};
class XBT_PUBLIC SemaphoreImpl {
std::atomic_int_fast32_t refcount_{1};
+ s4u::Semaphore piface_;
unsigned int value_;
actor::SynchroList sleeping_; /* list of sleeping actors*/
public:
unsigned int value_;
actor::SynchroList sleeping_; /* list of sleeping actors*/
public:
- explicit SemaphoreImpl(unsigned int value) : value_(value){};
- ~SemaphoreImpl() = default;
+ explicit SemaphoreImpl(unsigned int value) : piface_(this), value_(value){};
SemaphoreImpl(SemaphoreImpl const&) = delete;
SemaphoreImpl& operator=(SemaphoreImpl const&) = delete;
SemaphoreImpl(SemaphoreImpl const&) = delete;
SemaphoreImpl& operator=(SemaphoreImpl const&) = delete;
@@
-36,6
+36,9
@@
public:
unsigned int get_capacity() const { return value_; }
bool is_used() const { return not sleeping_.empty(); }
unsigned int get_capacity() const { return value_; }
bool is_used() const { return not sleeping_.empty(); }
+ SemaphoreImpl* ref();
+ void unref();
+
friend void intrusive_ptr_add_ref(SemaphoreImpl* sem)
{
XBT_ATTRIB_UNUSED auto previous = sem->refcount_.fetch_add(1);
friend void intrusive_ptr_add_ref(SemaphoreImpl* sem)
{
XBT_ATTRIB_UNUSED auto previous = sem->refcount_.fetch_add(1);
@@
-43,9
+46,13
@@
public:
}
friend void intrusive_ptr_release(SemaphoreImpl* sem)
{
}
friend void intrusive_ptr_release(SemaphoreImpl* sem)
{
- if (sem->refcount_.fetch_sub(1) == 1)
+ if (sem->refcount_.fetch_sub(1) == 1) {
+ xbt_assert(not sem->is_used(), "Cannot destroy semaphore since someone is still using it");
delete sem;
delete sem;
+ }
}
}
+
+ s4u::Semaphore& sem() { return piface_; }
};
} // namespace activity
} // namespace kernel
};
} // namespace activity
} // namespace kernel