+ if (mask == 0) {
+ /* 0 means clear */
+ {
+ /* We need remove_ext() not throwing exception. */
+ void *ret = xbt_dict_get_or_null_ext(task->simdata->affinity_mask_db, (char *) host, sizeof(msg_host_t));
+ if (ret != NULL)
+ xbt_dict_remove_ext(task->simdata->affinity_mask_db, (char *) host, sizeof(host));
+ }
+ } else
+ xbt_dict_set_ext(task->simdata->affinity_mask_db, (char *) host, sizeof(host), (void *) mask, NULL);
+
+ /* We set affinity data of this task. If the task is being executed, we
+ * actually change the affinity setting of the task. Otherwise, this change
+ * will be applied when the task is executed. */
+
+ if (!task->simdata->compute) {
+ /* task is not yet executed */
+ XBT_INFO("set affinity(0x%04lx@%s) for %s (not active now)", mask, MSG_host_get_name(host), MSG_task_get_name(task));
+ return;
+ }
+
+ {
+ smx_action_t compute = task->simdata->compute;
+ msg_host_t host_now = compute->execution.host; // simix_private.h is necessary
+ if (host_now != host) {
+ /* task is not yet executed on this host */
+ XBT_INFO("set affinity(0x%04lx@%s) for %s (not active now)", mask, MSG_host_get_name(host), MSG_task_get_name(task));
+ return;
+ }
+
+ /* task is being executed on this host. so change the affinity now */
+ {
+ /* check it works. remove me if it works. */
+ unsigned long affinity_mask = (unsigned long) xbt_dict_get_or_null_ext(task->simdata->affinity_mask_db, (char *) host, sizeof(msg_host_t));
+ xbt_assert(affinity_mask == mask);
+ }
+
+ XBT_INFO("set affinity(0x%04lx@%s) for %s", mask, MSG_host_get_name(host), MSG_task_get_name(task));