Example #1
0
 scoped_context(int cpu_id) : prev_context_(::instant::get_context()) {
     if(get_available_cpu_count() <= cpu_id) {
         throw std::runtime_error("Invalid cpu id: " +
                                  std::to_string(cpu_id));
     }
     ::instant::set_context(context(cpu_id));
 }
Example #2
0
bool
generate_default_ids(std::vector<std::string> & IDs)
{
        // this leave one CPU to attend to everything else but our work
        int cpu_cnt = get_available_cpu_count();
        if (1 > cpu_cnt) {
                M_NOTICE("CPU count does not meet minimum requirements");
                return false;
        }
        M_DEBUG("cpu_cnt = %d\n", cpu_cnt);

        char host_name[MAXHOSTNAMELEN] = { '\0' };
        if (gethostname(host_name, sizeof(host_name))) {
                M_ERROR("could not get host name %s", strerror(errno));
                return false;
        }

        char domain_name[MAXHOSTNAMELEN] = { '\0' };
        if (getdomainname(domain_name, sizeof(domain_name))) {
                M_ERROR("could not get domain name %s", strerror(errno));
                return false;
        }

        IDs.clear();
        std::string id;
        for (int n = 0; n < cpu_cnt; ++n) {
                id = host_name;
		id += ".";
                id += domain_name;
		id += n;
                IDs.push_back(id);
        }

	return true;
}