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"
15 class XBT_PUBLIC() MutexImpl {
19 MutexImpl(MutexImpl const&) = delete;
20 MutexImpl& operator=(MutexImpl const&) = delete;
22 void lock(smx_actor_t issuer);
23 bool try_lock(smx_actor_t issuer);
24 void unlock(smx_actor_t issuer);
27 smx_actor_t owner = nullptr;
28 // List of sleeping processes:
29 xbt_swag_t sleeping = nullptr;
31 // boost::intrusive_ptr<Mutex> support:
32 friend void intrusive_ptr_add_ref(MutexImpl* mutex)
34 // Atomic operation! Do not split in two instructions!
35 XBT_ATTRIB_UNUSED auto previous = (mutex->refcount_)++;
36 xbt_assert(previous != 0);
38 friend void intrusive_ptr_release(MutexImpl* mutex)
40 // Atomic operation! Do not split in two instructions!
41 auto count = --(mutex->refcount_);
46 simgrid::s4u::Mutex& mutex() { return mutex_; }
49 std::atomic_int_fast32_t refcount_ { 1 };
50 simgrid::s4u::Mutex mutex_;
56 typedef struct s_smx_cond {
57 s_smx_cond() : cond_(this) {}
59 std::atomic_int_fast32_t refcount_ { 1 };
60 smx_mutex_t mutex = nullptr;
61 xbt_swag_t sleeping = nullptr; /* list of sleeping process */
62 simgrid::s4u::ConditionVariable cond_;
65 typedef struct s_smx_sem {
67 xbt_swag_t sleeping; /* list of sleeping process */
70 XBT_PRIVATE void SIMIX_post_synchro(smx_activity_t synchro);
71 XBT_PRIVATE void SIMIX_synchro_stop_waiting(smx_actor_t process, smx_simcall_t simcall);
72 XBT_PRIVATE void SIMIX_synchro_destroy(smx_activity_t synchro);
73 XBT_PRIVATE void SIMIX_synchro_finish(smx_activity_t synchro);
75 XBT_PRIVATE smx_cond_t SIMIX_cond_init();
76 XBT_PRIVATE void SIMIX_cond_broadcast(smx_cond_t cond);
77 XBT_PRIVATE void SIMIX_cond_signal(smx_cond_t cond);
78 XBT_PRIVATE void intrusive_ptr_add_ref(s_smx_cond_t *cond);
79 XBT_PRIVATE void intrusive_ptr_release(s_smx_cond_t *cond);
81 XBT_PRIVATE XBT_PRIVATE smx_sem_t SIMIX_sem_init(unsigned int value);
82 XBT_PRIVATE void SIMIX_sem_release(smx_sem_t sem);
83 XBT_PRIVATE int SIMIX_sem_would_block(smx_sem_t sem);
84 XBT_PRIVATE int SIMIX_sem_get_capacity(smx_sem_t sem);