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() Mutex {
19 Mutex(Mutex const&) = delete;
20 Mutex& operator=(Mutex 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(Mutex* mutex)
34 // Atomic operation! Do not split in two instructions!
35 auto previous = (mutex->refcount_)++;
36 xbt_assert(previous != 0);
39 friend void intrusive_ptr_release(Mutex* mutex)
41 // Atomic operation! Do not split in two instructions!
42 auto count = --(mutex->refcount_);
47 simgrid::s4u::Mutex& mutex() { return mutex_; }
50 std::atomic_int_fast32_t refcount_ { 1 };
51 simgrid::s4u::Mutex mutex_;
57 typedef struct s_smx_cond {
58 s_smx_cond() : cond_(this) {}
60 std::atomic_int_fast32_t refcount_ { 1 };
61 smx_mutex_t mutex = nullptr;
62 xbt_swag_t sleeping = nullptr; /* list of sleeping process */
63 simgrid::s4u::ConditionVariable cond_;
66 typedef struct s_smx_sem {
68 xbt_swag_t sleeping; /* list of sleeping process */
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);