1 /* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMIX_SYNCHRO_PRIVATE_H
7 #define SIMIX_SYNCHRO_PRIVATE_H
9 #include "simgrid/s4u/ConditionVariable.hpp"
10 #include "src/simix/ActorImpl.hpp"
11 #include <boost/intrusive/list.hpp>
16 typedef boost::intrusive::list<ActorImpl, boost::intrusive::member_hook<ActorImpl, boost::intrusive::list_member_hook<>,
17 &ActorImpl::smx_synchro_hook>>
20 class XBT_PUBLIC() MutexImpl {
24 MutexImpl(MutexImpl const&) = delete;
25 MutexImpl& operator=(MutexImpl const&) = delete;
27 void lock(smx_actor_t issuer);
28 bool try_lock(smx_actor_t issuer);
29 void unlock(smx_actor_t issuer);
32 smx_actor_t owner = nullptr;
33 // List of sleeping processes:
34 simgrid::simix::SynchroList sleeping;
36 // boost::intrusive_ptr<Mutex> support:
37 friend void intrusive_ptr_add_ref(MutexImpl* mutex)
39 XBT_ATTRIB_UNUSED auto previous = mutex->refcount_.fetch_add(1);
40 xbt_assert(previous != 0);
42 friend void intrusive_ptr_release(MutexImpl* mutex)
44 if (mutex->refcount_.fetch_sub(1) == 1)
48 simgrid::s4u::Mutex& mutex() { return mutex_; }
51 std::atomic_int_fast32_t refcount_{1};
52 simgrid::s4u::Mutex mutex_;
58 s_smx_cond_t() : cond_(this) {}
60 std::atomic_int_fast32_t refcount_{1};
61 smx_mutex_t mutex = nullptr;
62 simgrid::simix::SynchroList sleeping; /* list of sleeping processes */
63 simgrid::s4u::ConditionVariable cond_;
68 simgrid::simix::SynchroList sleeping; /* list of sleeping processes */
71 XBT_PRIVATE void SIMIX_post_synchro(smx_activity_t synchro);
72 XBT_PRIVATE void SIMIX_synchro_stop_waiting(smx_actor_t process, smx_simcall_t simcall);
73 XBT_PRIVATE void SIMIX_synchro_destroy(smx_activity_t synchro);
74 XBT_PRIVATE void SIMIX_synchro_finish(smx_activity_t synchro);
76 XBT_PRIVATE smx_cond_t SIMIX_cond_init();
77 XBT_PRIVATE void SIMIX_cond_broadcast(smx_cond_t cond);
78 XBT_PRIVATE void SIMIX_cond_signal(smx_cond_t cond);
79 XBT_PRIVATE void intrusive_ptr_add_ref(s_smx_cond_t* cond);
80 XBT_PRIVATE void intrusive_ptr_release(s_smx_cond_t* cond);
82 XBT_PRIVATE XBT_PRIVATE smx_sem_t SIMIX_sem_init(unsigned int value);
83 XBT_PRIVATE void SIMIX_sem_release(smx_sem_t sem);
84 XBT_PRIVATE int SIMIX_sem_would_block(smx_sem_t sem);
85 XBT_PRIVATE int SIMIX_sem_get_capacity(smx_sem_t sem);