1 /* Copyright (c) 2012, 2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef _SIMIX_SYNCHRO_PRIVATE_H
8 #define _SIMIX_SYNCHRO_PRIVATE_H
14 #include "xbt/xbt_os_thread.h"
15 #include "src/simix/popping_private.h"
20 class XBT_PUBLIC() Mutex {
24 Mutex(Mutex const&) = delete;
25 Mutex& operator=(Mutex const&) = delete;
27 void lock(smx_process_t issuer);
28 bool try_lock(smx_process_t issuer);
29 void unlock(smx_process_t issuer);
32 smx_process_t owner = nullptr;
33 // List of sleeping processes:
34 xbt_swag_t sleeping = nullptr;
36 // boost::intrusive_ptr<Mutex> support:
37 friend void intrusive_ptr_add_ref(Mutex* mutex)
39 // Atomic operation! Do not split in two instructions!
40 auto previous = (mutex->refcount_)++;
41 xbt_assert(previous != 0);
44 friend void intrusive_ptr_release(Mutex* mutex)
46 // Atomic operation! Do not split in two instructions!
47 auto count = --(mutex->refcount_);
52 std::atomic_int_fast32_t refcount_ { 1 };
58 typedef struct s_smx_cond {
60 xbt_swag_t sleeping; /* list of sleeping process */
61 std::atomic_int_fast32_t refcount_;
64 typedef struct s_smx_sem {
66 xbt_swag_t sleeping; /* list of sleeping process */
71 XBT_PRIVATE void SIMIX_post_synchro(smx_synchro_t synchro);
72 XBT_PRIVATE void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t simcall);
73 XBT_PRIVATE void SIMIX_synchro_destroy(smx_synchro_t synchro);
74 XBT_PRIVATE void SIMIX_synchro_finish(smx_synchro_t synchro);
76 XBT_PRIVATE smx_cond_t SIMIX_cond_init(void);
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);