Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Close file after use.
[simgrid.git] / src / msg / msg_legacy.cpp
1 /* Copyright (c) 2004-2020. 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 "simgrid/Exception.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "src/msg/msg_private.hpp"
9 #include "xbt/functional.hpp"
10
11 #define MSG_CALL(type, oldname, args)
12
13 /* ************************** Engine *************************** */
14 void MSG_create_environment(const char* filename)
15 {
16   simgrid_load_platform(filename);
17 }
18
19 void MSG_launch_application(const char* filename)
20 {
21   simgrid_load_deployment(filename);
22 }
23 msg_error_t MSG_main()
24 {
25   simgrid_run();
26   return MSG_OK;
27 }
28 void MSG_function_register(const char* name, int (*code)(int, char**))
29 {
30   simgrid::s4u::Engine::get_instance()->register_function(
31       name, [code](std::vector<std::string> args) { return simgrid::xbt::wrap_main(code, std::move(args)); });
32 }
33 void MSG_function_register_default(int (*code)(int, char**))
34 {
35   simgrid::s4u::Engine::get_instance()->register_default(
36       [code](std::vector<std::string> args) { return simgrid::xbt::wrap_main(code, std::move(args)); });
37 }
38 double MSG_get_clock()
39 {
40   return simgrid_get_clock();
41 }
42
43 /* ************************** Mailboxes ************************ */
44 void MSG_mailbox_set_async(const char* alias)
45 {
46   sg_mailbox_set_receiver(alias);
47 }
48 int MSG_task_listen(const char* alias)
49 {
50   return sg_mailbox_listen(alias);
51 }
52
53 /* ************************** Actors *************************** */
54 void MSG_process_on_exit(int_f_int_pvoid_t fun, void* data)
55 {
56   sg_actor_on_exit(fun, data);
57 }
58
59 int MSG_process_get_PID(const_sg_actor_t actor)
60 {
61   return sg_actor_get_PID(actor);
62 }
63 int MSG_process_get_PPID(const_sg_actor_t actor)
64 {
65   return sg_actor_get_PPID(actor);
66 }
67 msg_process_t MSG_process_from_PID(int PID)
68 {
69   return sg_actor_by_PID(PID);
70 }
71 const char* MSG_process_get_name(const_sg_actor_t actor)
72 {
73   return sg_actor_get_name(actor);
74 }
75 sg_host_t MSG_process_get_host(const_sg_actor_t actor)
76 {
77   return sg_actor_get_host(actor);
78 }
79 xbt_dict_t MSG_process_get_properties(const_sg_actor_t actor)
80 {
81   return sg_actor_get_properties(actor);
82 }
83 const char* MSG_process_get_property_value(const_sg_actor_t actor, const char* name)
84 {
85   return sg_actor_get_property_value(actor, name);
86 }
87 void MSG_process_suspend(sg_actor_t actor)
88 {
89   sg_actor_suspend(actor);
90 }
91 void MSG_process_resume(sg_actor_t actor)
92 {
93   sg_actor_resume(actor);
94 }
95 int MSG_process_is_suspended(sg_actor_t actor)
96 {
97   return sg_actor_is_suspended(actor);
98 }
99 void MSG_process_restart(sg_actor_t actor)
100 {
101   sg_actor_restart(actor);
102 }
103 void MSG_process_auto_restart_set(sg_actor_t actor, int auto_restart)
104 {
105   sg_actor_set_auto_restart(actor, auto_restart);
106 }
107
108 void MSG_process_daemonize(sg_actor_t actor)
109 {
110   sg_actor_daemonize(actor);
111 }
112 void MSG_process_migrate(sg_actor_t actor, sg_host_t host)
113 {
114   sg_actor_set_host(actor, host);
115 }
116 void MSG_process_join(sg_actor_t actor, double timeout)
117 {
118   sg_actor_join(actor, timeout);
119 }
120 void MSG_process_kill(sg_actor_t actor)
121 {
122   sg_actor_kill(actor);
123 }
124 void MSG_process_killall()
125 {
126   sg_actor_kill_all();
127 }
128 void MSG_process_set_kill_time(sg_actor_t actor, double kill_time)
129 {
130   sg_actor_set_kill_time(actor, kill_time);
131 }
132 void MSG_process_yield()
133 {
134   sg_actor_yield();
135 }
136
137 msg_error_t MSG_process_sleep(double duration)
138 {
139   try {
140     sg_actor_sleep_for(duration);
141     return MSG_OK;
142   } catch (const simgrid::HostFailureException&) {
143     return MSG_HOST_FAILURE;
144   }
145 }
146
147 /** @brief Returns the user data of a process.
148  *
149  * This function checks whether @a process is a valid pointer and returns the user data associated to this process.
150  */
151 void* MSG_process_get_data(const_sg_actor_t process)
152 {
153   xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!");
154
155   /* get from SIMIX the MSG process data, and then the user data */
156   return sg_actor_data(process);
157 }
158
159 /** @brief Sets the user data of a process.
160  *
161  * This function checks whether @a process is a valid pointer and sets the user data associated to this process.
162  */
163 msg_error_t MSG_process_set_data(msg_process_t process, void* data)
164 {
165   xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!");
166   sg_actor_data_set(process, data);
167
168   return MSG_OK;
169 }
170
171 msg_process_t MSG_process_attach(const char* name, void* data, msg_host_t host, xbt_dict_t properties)
172 {
173   return sg_actor_attach(name, data, host, properties);
174 }
175
176 void MSG_process_detach()
177 {
178   sg_actor_detach();
179 }
180 aid_t MSG_process_self_PID()
181 {
182   return sg_actor_self_get_pid();
183 }
184
185 /** @brief Return the PPID of the current process.
186  *
187  * This function returns the PID of the parent of the currently running #msg_process_t.
188  */
189 aid_t MSG_process_self_PPID()
190 {
191   return sg_actor_self_get_ppid();
192 }
193
194 /** @brief Return the name of the current process. */
195 const char* MSG_process_self_name()
196 {
197   return sg_actor_self_get_name();
198 }
199 /** @brief Return the current process.
200  *
201  * This function returns the currently running #msg_process_t.
202  */
203 msg_process_t MSG_process_self()
204 {
205   return sg_actor_self();
206 }
207
208 /** @brief Take an extra reference on that process to prevent it to be garbage-collected */
209 void MSG_process_ref(const_sg_actor_t process)
210 {
211   sg_actor_ref(process);
212 }
213 /** @brief Release a reference on that process so that it can get be garbage-collected */
214 void MSG_process_unref(const_sg_actor_t process)
215 {
216   sg_actor_unref(process);
217 }
218 /** @brief Return the current number MSG processes. */
219 int MSG_process_get_number()
220 {
221   return simgrid_get_actor_count();
222 }
223 /* ************************** NetZones *************************** */
224 sg_netzone_t MSG_zone_get_root()
225 {
226   return sg_zone_get_root();
227 }
228 const char* MSG_zone_get_name(const_sg_netzone_t zone)
229 {
230   return sg_zone_get_name(zone);
231 }
232 sg_netzone_t MSG_zone_get_by_name(const char* name)
233 {
234   return sg_zone_get_by_name(name);
235 }
236 void MSG_zone_get_sons(const_sg_netzone_t zone, xbt_dict_t whereto)
237 {
238   return sg_zone_get_sons(zone, whereto);
239 }
240 const char* MSG_zone_get_property_value(const_sg_netzone_t zone, const char* name)
241 {
242   return sg_zone_get_property_value(zone, name);
243 }
244 void MSG_zone_set_property_value(sg_netzone_t zone, const char* name, const char* value)
245 {
246   sg_zone_set_property_value(zone, name, value);
247 }
248 void MSG_zone_get_hosts(const_sg_netzone_t zone, xbt_dynar_t whereto)
249 {
250   sg_zone_get_hosts(zone, whereto);
251 }
252
253 /* ************************** Storages *************************** */
254 const char* MSG_storage_get_name(const_sg_storage_t storage)
255 {
256   return sg_storage_get_name(storage);
257 }
258 sg_storage_t MSG_storage_get_by_name(const char* name)
259 {
260   return sg_storage_get_by_name(name);
261 }
262 xbt_dict_t MSG_storage_get_properties(const_sg_storage_t storage)
263 {
264   return sg_storage_get_properties(storage);
265 }
266 void MSG_storage_set_property_value(sg_storage_t storage, const char* name, const char* value)
267 {
268   sg_storage_set_property_value(storage, name, value);
269 }
270 const char* MSG_storage_get_property_value(const_sg_storage_t storage, const char* name)
271 {
272   return sg_storage_get_property_value(storage, name);
273 }
274 xbt_dynar_t MSG_storages_as_dynar()
275 {
276   return sg_storages_as_dynar();
277 }
278 void MSG_storage_set_data(sg_storage_t storage, void* data)
279 {
280   sg_storage_set_data(storage, data);
281 }
282 void* MSG_storage_get_data(const_sg_storage_t storage)
283 {
284   return sg_storage_get_data(storage);
285 }
286 const char* MSG_storage_get_host(const_sg_storage_t storage)
287 {
288   return sg_storage_get_host(storage);
289 }
290 sg_size_t MSG_storage_read(sg_storage_t storage, sg_size_t size)
291 {
292   return sg_storage_read(storage, size);
293 }
294 sg_size_t MSG_storage_write(sg_storage_t storage, sg_size_t size)
295 {
296   return sg_storage_write(storage, size);
297 }
298
299 /* ************************** hosts *************************** */
300 xbt_dynar_t MSG_hosts_as_dynar()
301 {
302   return sg_hosts_as_dynar();
303 }
304 size_t MSG_get_host_number()
305 {
306   return sg_host_count();
307 }
308 sg_host_t MSG_get_host_by_name(const char* name)
309 {
310   return sg_host_by_name(name);
311 }
312 sg_host_t MSG_host_by_name(const char* name)
313 {
314   return sg_host_by_name(name);
315 }
316 const char* MSG_host_get_name(const_sg_host_t host)
317 {
318   return sg_host_get_name(host);
319 }
320 void* MSG_host_get_data(const_sg_host_t host)
321 {
322   return sg_host_data(host);
323 }
324 void MSG_host_set_data(sg_host_t host, void* data)
325 {
326   return sg_host_data_set(host, data);
327 }
328 xbt_dict_t MSG_host_get_mounted_storage_list(sg_host_t host) // XBT_ATTRIB_DEPRECATED_v330
329 {
330   return sg_host_get_mounted_storage_list(host);
331 }
332 xbt_dynar_t MSG_host_get_attached_storage_lists(const_sg_host_t host)
333 {
334   return sg_host_get_attached_storage_list(host);
335 }
336 double MSG_host_get_speed(const_sg_host_t host)
337 {
338   return sg_host_speed(host);
339 }
340 double MSG_host_get_power_peak_at(const_sg_host_t host, int pstate_index)
341 {
342   return sg_host_get_pstate_speed(host, pstate_index);
343 }
344 int MSG_host_get_core_number(const_sg_host_t host)
345 {
346   return sg_host_core_count(host);
347 }
348 int MSG_host_get_nb_pstates(const_sg_host_t host)
349 {
350   return sg_host_get_nb_pstates(host);
351 }
352 int MSG_host_get_pstate(const_sg_host_t host)
353 {
354   return sg_host_get_pstate(host);
355 }
356 void MSG_host_set_pstate(sg_host_t host, int pstate)
357 {
358   sg_host_set_pstate(host, pstate);
359 }
360 void MSG_host_on(sg_host_t h)
361 {
362   sg_host_turn_on(h);
363 }
364 void MSG_host_off(sg_host_t h)
365 {
366   sg_host_turn_off(h);
367 }
368 int MSG_host_is_on(const_sg_host_t h)
369 {
370   return sg_host_is_on(h);
371 }
372 xbt_dict_t MSG_host_get_properties(const_sg_host_t host)
373 {
374   return sg_host_get_properties(host);
375 }
376 const char* MSG_host_get_property_value(const_sg_host_t host, const char* name)
377 {
378   return sg_host_get_property_value(host, name);
379 }
380 void MSG_host_set_property_value(sg_host_t host, const char* name, const char* value)
381 {
382   sg_host_set_property_value(host, name, value);
383 }
384 void MSG_host_get_process_list(const_sg_host_t host, xbt_dynar_t whereto)
385 {
386   sg_host_get_actor_list(host, whereto);
387 }
388 sg_host_t MSG_host_self()
389 {
390   return sg_host_self();
391 }
392
393 double MSG_host_get_load(const_sg_host_t host)
394 {
395   return sg_host_load(host);
396 }
397 /* ************************** Virtual Machines *************************** */
398 sg_vm_t MSG_vm_create_core(sg_host_t pm, const char* name)
399 {
400   return sg_vm_create_core(pm, name);
401 }
402 sg_vm_t MSG_vm_create_multicore(sg_host_t pm, const char* name, int coreAmount)
403 {
404   return sg_vm_create_multicore(pm, name, coreAmount);
405 }
406 int MSG_vm_is_created(sg_vm_t vm)
407 {
408   return sg_vm_is_created(vm);
409 }
410 int MSG_vm_is_running(sg_vm_t vm)
411 {
412   return sg_vm_is_running(vm);
413 }
414 int MSG_vm_is_suspended(sg_vm_t vm)
415 {
416   return sg_vm_is_suspended(vm);
417 }
418 const char* MSG_vm_get_name(const_sg_vm_t vm)
419 {
420   return sg_vm_get_name(vm);
421 }
422 void MSG_vm_set_ramsize(sg_vm_t vm, size_t size)
423 {
424   sg_vm_set_ramsize(vm, size);
425 }
426 size_t MSG_vm_get_ramsize(const_sg_vm_t vm)
427 {
428   return sg_vm_get_ramsize(vm);
429 }
430 sg_host_t MSG_vm_get_pm(const_sg_vm_t vm)
431 {
432   return sg_vm_get_pm(vm);
433 }
434 void MSG_vm_set_bound(sg_vm_t vm, double bound)
435 {
436   sg_vm_set_bound(vm, bound);
437 }
438 void MSG_vm_start(sg_vm_t vm)
439 {
440   sg_vm_start(vm);
441 }
442 void MSG_vm_suspend(sg_vm_t vm)
443 {
444   sg_vm_suspend(vm);
445 }
446 void MSG_vm_resume(sg_vm_t vm)
447 {
448   sg_vm_resume(vm);
449 }
450 void MSG_vm_shutdown(sg_vm_t vm)
451 {
452   sg_vm_shutdown(vm);
453 }
454 void MSG_vm_destroy(sg_vm_t vm)
455 {
456   sg_vm_destroy(vm);
457 }
458 /********* barriers ************/
459 sg_bar_t MSG_barrier_init(unsigned int count)
460 {
461   return sg_barrier_init(count);
462 }
463
464 void MSG_barrier_destroy(const_sg_bar_t bar)
465 {
466   sg_barrier_destroy(bar);
467 }
468
469 int MSG_barrier_wait(sg_bar_t bar)
470 {
471   return sg_barrier_wait(bar);
472 }
473
474 sg_sem_t MSG_sem_init(int initial_value)
475 {
476   return sg_sem_init(initial_value);
477 }
478 void MSG_sem_acquire(sg_sem_t sem)
479 {
480   sg_sem_acquire(sem);
481 }
482 int MSG_sem_acquire_timeout(sg_sem_t sem, double timeout)
483 {
484   return sg_sem_acquire_timeout(sem, timeout);
485 }
486 void MSG_sem_release(sg_sem_t sem)
487 {
488   sg_sem_release(sem);
489 }
490 int MSG_sem_get_capacity(sg_sem_t sem)
491 {
492   return sg_sem_get_capacity(sem);
493 }
494 void MSG_sem_destroy(const_sg_sem_t sem)
495 {
496   sg_sem_destroy(sem);
497 }
498 int MSG_sem_would_block(sg_sem_t sem)
499 {
500   return sg_sem_would_block(sem);
501 }