Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tiny doc formating improvement
[simgrid.git] / src / simix / smx_synchro_private.h
1 /* Copyright (c) 2012, 2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef _SIMIX_SYNCHRO_PRIVATE_H
8 #define _SIMIX_SYNCHRO_PRIVATE_H
9
10 #include <atomic>
11
12 #include "xbt/base.h"
13 #include "xbt/swag.h"
14 #include "xbt/xbt_os_thread.h"
15 #include "src/simix/popping_private.h"
16
17 namespace simgrid {
18 namespace simix {
19
20 class XBT_PUBLIC() Mutex {
21 public:
22   Mutex();
23   ~Mutex();
24   Mutex(Mutex const&) = delete;
25   Mutex& operator=(Mutex const&) = delete;
26
27   void lock(smx_process_t issuer);
28   bool try_lock(smx_process_t issuer);
29   void unlock(smx_process_t issuer);
30
31   bool locked = false;
32   smx_process_t owner = nullptr;
33   // List of sleeping processes:
34   xbt_swag_t sleeping = nullptr;
35
36   // boost::intrusive_ptr<Mutex> support:
37   friend void intrusive_ptr_add_ref(Mutex* mutex)
38   {
39     auto previous = ++mutex->refcount_;
40     xbt_assert(previous != 0);
41     (void) previous;
42   }
43   friend void intrusive_ptr_release(Mutex* mutex)
44   {
45     auto count = mutex->refcount_--;
46     if (count == 0)
47       delete mutex;
48   }
49 private:
50   std::atomic_int_fast32_t refcount_ { 1 };
51 };
52
53 }
54 }
55
56 typedef struct s_smx_cond {
57   smx_mutex_t mutex;
58   xbt_swag_t sleeping;          /* list of sleeping process */
59 } s_smx_cond_t;
60
61 typedef struct s_smx_sem {
62   unsigned int value;
63   xbt_swag_t sleeping;          /* list of sleeping process */
64 } s_smx_sem_t;
65
66 XBT_PRIVATE void SIMIX_post_synchro(smx_synchro_t synchro);
67 XBT_PRIVATE void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t simcall);
68 XBT_PRIVATE void SIMIX_synchro_destroy(smx_synchro_t synchro);
69 XBT_PRIVATE void SIMIX_synchro_finish(smx_synchro_t synchro);
70
71 XBT_PRIVATE smx_cond_t SIMIX_cond_init(void);
72 XBT_PRIVATE void SIMIX_cond_broadcast(smx_cond_t cond);
73 XBT_PRIVATE void SIMIX_cond_signal(smx_cond_t cond);
74
75 XBT_PRIVATE XBT_PRIVATE smx_sem_t SIMIX_sem_init(unsigned int value);
76 XBT_PRIVATE void SIMIX_sem_release(smx_sem_t sem);
77 XBT_PRIVATE int SIMIX_sem_would_block(smx_sem_t sem);
78 XBT_PRIVATE int SIMIX_sem_get_capacity(smx_sem_t sem);
79
80 #endif