Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0cd3b01a9da6b88e7508bd9b7cf8b2680289b1ab
[simgrid.git] / src / simix / smx_synchro.cpp
1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "src/kernel/activity/ConditionVariableImpl.hpp"
7 #include "src/kernel/activity/MutexImpl.hpp"
8 #include "src/kernel/activity/SemaphoreImpl.hpp"
9 #include "src/kernel/activity/SynchroRaw.hpp"
10 #include "src/kernel/context/Context.hpp"
11 #include "src/simix/smx_synchro_private.hpp"
12 #include "src/surf/cpu_interface.hpp"
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_synchro, simix, "SIMIX Synchronization (mutex, semaphores and conditions)");
15
16 /***************************** Raw synchronization *********************************/
17
18 smx_activity_t SIMIX_synchro_wait(sg_host_t smx_host, double timeout)
19 {
20   XBT_IN("(%p, %f)",smx_host,timeout);
21
22   simgrid::kernel::activity::RawImplPtr sync =
23       simgrid::kernel::activity::RawImplPtr(new simgrid::kernel::activity::RawImpl());
24   sync->surf_action_ = smx_host->pimpl_cpu->sleep(timeout);
25   sync->surf_action_->set_data(sync.get());
26   XBT_OUT();
27   return sync;
28 }
29
30 void SIMIX_synchro_stop_waiting(smx_actor_t process, smx_simcall_t simcall)
31 {
32   XBT_IN("(%p, %p)",process,simcall);
33   switch (simcall->call) {
34
35     case SIMCALL_MUTEX_LOCK:
36       simgrid::xbt::intrusive_erase(simcall_mutex_lock__get__mutex(simcall)->sleeping, *process);
37       break;
38
39     case SIMCALL_COND_WAIT:
40       simgrid::xbt::intrusive_erase(simcall_cond_wait__get__cond(simcall)->sleeping, *process);
41       break;
42
43     case SIMCALL_COND_WAIT_TIMEOUT:
44       simgrid::xbt::intrusive_erase(simcall_cond_wait_timeout__get__cond(simcall)->sleeping, *process);
45       simcall_cond_wait_timeout__set__result(simcall, 1); // signal a timeout
46       break;
47
48     case SIMCALL_SEM_ACQUIRE:
49       simgrid::xbt::intrusive_erase(simcall_sem_acquire__get__sem(simcall)->sleeping_, *process);
50       break;
51
52     case SIMCALL_SEM_ACQUIRE_TIMEOUT:
53       simgrid::xbt::intrusive_erase(simcall_sem_acquire_timeout__get__sem(simcall)->sleeping_, *process);
54       simcall_sem_acquire_timeout__set__result(simcall, 1); // signal a timeout
55       break;
56
57     default:
58       THROW_IMPOSSIBLE;
59   }
60   XBT_OUT();
61 }