Logo AND Algorithmique Numérique Distribuée

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