Пример #1
0
void stress_c(){
	void * p;
	void * q;
	head = (node *)malloc(sizeof(node));
	while(1){
		if(queue_size == 0){
			p = g_test_fixture.receive_message(NULL);
			head = enqueue(p);
		} else {
			p = dequeue();
			queue_size--;
		}
		if(message_type(ml_index) == COUNT_REPORT){
			if(*((int*)(p+64))%20 == 0){
				uprintf((CHAR *)"Process C");
			}
			q = g_test_fixture.request_memory_block();
			ml_index = g_test_fixture.delayed_send(STRESS_C_PID, q, 10);
			set_message_type(ml_index, WAKEUP_10);
			while(1){
				p = g_test_fixture.receive_message(NULL);
				if(message_type(ml_index) == WAKEUP_10){
					break;
				} else {
					enqueue(p);
				}
			} 
		}	
		g_test_fixture.release_processor();		
	}	
	return;
}
Пример #2
0
int32_t execute_common_handle(struct data_buffer* dbuf,int socket_fd,MEM_POOL* mem_pool)
{
	struct data_buffer rbuf;
	
	//发数据包
	if(socket_write(socket_fd,dbuf->data,dbuf->data_len) <= 0)
		return -1;

	//接受命名
	memset(&rbuf,0,sizeof(struct data_buffer));
	rbuf.data_len = sizeof(uint32_t);
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,sizeof(uint32_t));
	rbuf.size = rbuf.data_len;
	
	if(socket_read(socket_fd,rbuf.data,sizeof(uint32_t)) <= 0)
		return -1;

	rbuf.data_len = read_int32(&rbuf);
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,rbuf.data_len);
	rbuf.rpos = 0;
	rbuf.size = rbuf.data_len;

	if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0)
		return -1;
	rbuf.rpos += MESSAGE_HEAD_LEN;

	uint16_t type = message_type(&rbuf);
	if (type != MT_DC_EXE_RS)
		return -1;

	return read_int32(&rbuf);
}
Пример #3
0
 void SynchronousEngine<algorithm_t>::
 signalVertex(vertex_id_type vid, const message_type& msg = message_type()){
     active_superstep_[vid] = 1;
     active_minorstep_[vid] = 1;
     has_msg_[vid] = 1;
     internalSignal(vid, msg);
 }
Пример #4
0
    void log( level_type lvl, const string_type& msg )
    {
        auto now = std::chrono::system_clock::now();
        auto in_time_t = std::chrono::system_clock::to_time_t(now);

        m_container.push( message_type(m_channel, lvl, msg, in_time_t ) );

        // distributor_type::instance().log( std::move( message_type(m_channel, lvl, msg, in_time_t ) ) );
    }
Пример #5
0
    std::string dump() const
    {
        std::stringstream s;
        s << "Packet type: " << (uint16_t)message_type() << std::endl;
        s << "Data:" << std::hex << std::fixed << std::setw(2);
        for (auto x : *this) s << " " << (uint16_t)x;

        return s.str();
    }
Пример #6
0
    SynchronousEngine<algorithm_t>::SynchronousEngine(graph_type& graph):
    iteration_counter_(0), max_iterations_(5), graph_(graph) {
        vertex_programs_.resize(graph.num_local_vertices());
		gather_accum_.resize(graph.num_local_vertices());
        has_msg_.resize(graph.num_local_vertices(), 0);
        has_msg_.resize(graph.num_local_vertices(), message_type());
        active_superstep_.resize(graph.num_local_vertices(), 0);
        active_minorstep_.resize(graph.num_local_vertices(), 0);
    }
Пример #7
0
void EOSComm::hi_ho() {
  bool device_discovered = false;
  while (device_discovered == false) {
    write_hi(myDeviceType);
    delay(500);
    if(readIfAvailable()) {
      if(device_address() == myDeviceAddress && message_type() == MSG_HO) {
        device_discovered = true;
      }
    }
  }
}
Пример #8
0
 SynchronousEngine<algorithm_t>::SynchronousEngine(graph_type& graph):
 iteration_counter_(0), max_iterations_(5), graph_(graph) {
     vertex_programs_.resize(graph.num_local_vertices());
     gather_accum_.resize(graph.num_local_vertices());
     has_msg_.resize(graph.num_local_vertices(), 0);
     messages_.resize(graph.num_local_vertices(), message_type());
     active_superstep_.resize(graph.num_local_vertices(), 0);
     active_minorstep_.resize(graph.num_local_vertices(), 0);
     context = new context_type(*this, graph);
     aggregator = new aggregator_type(graph, context);
     cout<<"sync engine init"<<endl;
 }
Пример #9
0
int32_t execute_index_stat_handle(struct data_buffer* dbuf,int socket_fd,MEM_POOL* mem_pool)
{	
	struct data_buffer rbuf;
	
	//发一个数据包长度
	if(socket_write(socket_fd,dbuf->data,dbuf->data_len) <= 0)
		return -1;

	//接受命名
	memset(&rbuf,0,sizeof(struct data_buffer));
	rbuf.data_len = sizeof(uint32_t);
	rbuf.size = rbuf.data_len;
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,sizeof(uint32_t));
	
	if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0)
		return -1;
	
	rbuf.data_len = read_int32(&rbuf);
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,rbuf.data_len);
	rbuf.rpos = 0;
	rbuf.size = rbuf.data_len;
	
	if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0) 
		return -1;

	rbuf.rpos += MESSAGE_HEAD_LEN;
	uint16_t type = message_type(&rbuf);
	if (type != MT_DC_STAT_RS)
		return -1;

	uint16_t field_count = read_int16(&rbuf);

	uint16_t i;
	char* field_name = NULL;
	fprintf(stderr,"%-20s%-20s%-20s%-20s\n","FIELD_NAME","INDEX_TYPE","DATA_TYPE","FLAG");
	uint8_t j;
	uint8_t index_num;
	for(i=0; i<field_count; i++)
	{
		field_name = read_cstring(&rbuf,mem_pool);
		index_num = read_int8(&rbuf);
		for(j=0;j < index_num; j++)
		{
			fprintf(stderr,"%-20s",field_name);
			fprintf(stderr,"%-20u",read_int8(&rbuf));
			fprintf(stderr,"%-20u",read_int8(&rbuf));
			fprintf(stderr,"%-20u\n",read_int8(&rbuf));
		}
	}

	return 0;
}
Пример #10
0
void wr_messages(void)
{
	s16b i;
	u16b num;

	num = messages_num();
	if (num > 80) num = 80;
	wr_u16b(num);

	/* Dump the messages (oldest first!) */
	for (i = num - 1; i >= 0; i--)
	{
		wr_string(message_str(i));
		wr_u16b(message_type(i));
	}
}
Пример #11
0
int32_t execute_segment_stat_handle(struct data_buffer* dbuf,int socket_fd,MEM_POOL* mem_pool)
{
	struct data_buffer rbuf;
	
	//发数据包
	if(socket_write(socket_fd,dbuf->data,dbuf->data_len) <= 0)
		return -1;

	//接受命名
	memset(&rbuf,0,sizeof(struct data_buffer));
	rbuf.data_len = sizeof(uint32_t);
	rbuf.size = rbuf.data_len;
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,sizeof(uint32_t));
	if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0)
		return -1;

	rbuf.data_len = read_int32(&rbuf);
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,rbuf.data_len);
	rbuf.rpos = 0;
	rbuf.size = rbuf.data_len;

	if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0)
		return -1;
	
	rbuf.rpos += MESSAGE_HEAD_LEN;
	uint16_t type = message_type(&rbuf);
	if (type != MT_DC_STAT_RS)
		return -1;

	uint16_t segment_count = read_int16(&rbuf);

	uint16_t i;
	fprintf(stderr,"%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n","SEGMENT_ID","CREATE_TIME","MODIFY_TIME","CHECKPOINT_TIME","FLAG","ROW_COUNT","DEL_COUNT");
	for(i=0; i<segment_count; i++)
	{
		fprintf(stderr,"%-20u",read_int16(&rbuf));
		fprintf(stderr,"%-20llu",read_int64(&rbuf));
		fprintf(stderr,"%-20llu",read_int64(&rbuf));
		fprintf(stderr,"%-20llu",read_int64(&rbuf));
		fprintf(stderr,"%-20u",read_int8(&rbuf));
		fprintf(stderr,"%-20u",read_int32(&rbuf));
		fprintf(stderr,"%-20u\n",read_int32(&rbuf));
	}
	
	return 0;
}
Пример #12
0
int execute_ldb_control_handle(struct data_buffer *dbuf, int socket_fd, MEM_POOL_PTR mem_pool)
{
	struct data_buffer rbuf;

	if (socket_write(socket_fd, dbuf->data, dbuf->data_len) <= 0)
		return -1;

	memset(&rbuf,0,sizeof(struct data_buffer));
	rbuf.data_len = sizeof(uint32_t);
	rbuf.size = rbuf.data_len;
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,sizeof(uint32_t));
	
	if(socket_read(socket_fd,rbuf.data,sizeof(uint32_t)) <= 0)
		return -1;

	rbuf.data_len = read_int32(&rbuf);
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,rbuf.data_len);
	rbuf.rpos = 0;
	rbuf.size = rbuf.data_len;

	if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0)
		return -1;
	rbuf.rpos += MESSAGE_HEAD_LEN;

	uint16_t type = message_type(&rbuf);
	if (type != MT_DC_LDB_CONTROL)
		return -1;

	// content
	char *content = read_cstring(&rbuf, mem_pool);
	if (content) {
		fprintf(stderr, "%s\n", content);
		return 0;
	}
	else 
		return -1;
}
Пример #13
0
/** Close channel **/
void do_chat_close(int id)
{
	int i, j;

	for (i = 0; i < MAX_CHANNELS; i++)
	{
		if (channels[i].id == id)
		{
			if (view_channel == i)
				cmd_chat_cycle(-1);

			for (j = 0; j < message_num(); j++)
			{
				u16b type = message_type(j);
				if (type == MSG_CHAT + id)
				{
					c_message_del(j);
				}
			}

			channels[i].name[0] = '\0';
			channels[i].id = 0;

			if (p_ptr->main_channel == i)
				p_ptr->main_channel = 0;

			if (STRZERO(channels[view_channel].name))
				cmd_chat_cycle(+1);

			/* Window update */
			p_ptr->window |= PW_MESSAGE_CHAT;

			break;
		}
	}
}
Пример #14
0
int execute_set_load_threshold_handle(struct data_buffer *dbuf, int socket_fd, MEM_POOL_PTR mem_pool)
{
	struct data_buffer rbuf;
	
	//发数据包
	if(socket_write(socket_fd,dbuf->data,dbuf->data_len) <= 0)
		return -1;

	//接受命名
	memset(&rbuf,0,sizeof(struct data_buffer));
	rbuf.data_len = sizeof(uint32_t);
	rbuf.size = rbuf.data_len;
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,sizeof(uint32_t));
	
	if(socket_read(socket_fd,rbuf.data,sizeof(uint32_t)) <= 0)
		return -1;

	rbuf.data_len = read_int32(&rbuf);
	rbuf.data = (uint8_t *)mem_pool_malloc(mem_pool,rbuf.data_len);
	rbuf.rpos = 0;
	rbuf.size = rbuf.data_len;

	if(socket_read(socket_fd,rbuf.data,rbuf.data_len) <= 0)
		return -1;
	rbuf.rpos += MESSAGE_HEAD_LEN;

	uint16_t type = message_type(&rbuf);
	if (type != MT_DC_EXE_RS)
		return -1;

	double load = 0;
	read_bytes(&rbuf, (uint8_t *)&load, sizeof(load));

	fprintf(stderr, "OLD VALUE: %g\n", load);
	return 0;
}
Пример #15
0
 void EngineDelegate<algorithm_t>::
 signalVertex(vertex_id_type vid, const message_type& msg = message_type()){
     engine->signalVertex(vid, msg);
 }
Пример #16
0
 void SynchronousEngine<algorithm_t>::
 clearMessages(){
     messages_.assign(graph_.num_local_vertices(), message_type());
     has_msg_.assign(graph_.num_local_vertices(), 0);
 }
Пример #17
0
bool Generator::AnalyseProtoFile(std::string const& proto_path) {
    try {
        std::ifstream ifs(proto_path);
        if (!ifs.is_open()) {
            err_string = "Open file " + proto_path + " failed!";
            return false;
        }

        char line[256] = {0};
        ContentType type = NONE;
        std::string message_name;
        while (!ifs.eof()) {
            memset(line, 0, sizeof(line));
            ifs.getline(line, 256);
            std::string useful = getUseful(line);
            if (useful.empty()) continue;

            if (NONE == type) {
                if (useful.substr(0, 4) == "enum" && isblank(useful[4])) {
                    type = ENUM;
                    enum_vec.push_back(getName(useful, 5));
                } else if (useful.substr(0, 7) == "message" && isblank(useful[7])) {
                    type = MESSAGE;
                    message_name = getName(useful, 8);
                    message_map[message_name] = message_type();
                }
                continue;
            }

            if (ENUM == type) {
                if (useful.substr(0, 1) == "}") type = NONE;
                continue;
            }

            if (MESSAGE == type) {
                if (useful.substr(0, 1) == "}") {
                    type = NONE;
                    message_name.clear();
                } else {
                    std::istringstream iss(useful);
                    std::cout << iss.str() << std::endl;
                    Element ele;
                    iss >> ele.label >> ele.type >> ele.name;
                    if (!isProtoOriginalType(ele.type)) {
                        if (std::find(enum_vec.begin(), enum_vec.end(), ele.type) == enum_vec.end() &&
                            message_map.find(ele.type) == message_map.end()) {
                            err_string += "There is not a definition of message " + ele.type +
                                          " which is the type of element " + ele.name + " in message " + message_name +
                                          "\n";
                            continue;
                        }
                    }

                    auto pos = ele.name.find("=");
                    if (std::string::npos != pos) ele.name = ele.name.substr(0, pos);

                    ele.method_name = ele.name;
                    for (auto i = 0; i < ele.method_name.length(); ++i) {
                        ele.method_name[i] = (char)tolower(ele.method_name[i]);
                    }

                    message_map[message_name].push_back(ele);
                }
            }
        }

        ifs.close();
    }
    catch (std::exception e) {
        err_string = e.what();
        return false;
    }

    return true;
}
Пример #18
0
Файл: save.c Проект: fph/mortsil
/*
 * Actually write a save-file
 */
static bool wr_savefile(void)
{
	int i;

	u32b now;

	u16b tmp16u;


	/* Guess at the current time */
	now = time((time_t *)0);


	/* Note the operating system */
	sf_xtra = 0L;

	/* Note when the file was saved */
	sf_when = now;

	/* Note the number of saves */
	sf_saves++;


	/*** Actually write the file ***/

	/* Dump the file header */
	xor_byte = 0;
	wr_byte(VERSION_MAJOR);
	xor_byte = 0;
	wr_byte(VERSION_MINOR);
	xor_byte = 0;
	wr_byte(VERSION_PATCH);
	xor_byte = 0;
	wr_byte(VERSION_EXTRA);


	/* Reset the checksum */
	v_stamp = 0L;
	x_stamp = 0L;


	/* Operating system */
	wr_u32b(sf_xtra);

	/* Time file last saved */
	wr_u32b(sf_when);

	/* Number of past lives */
	wr_u16b(sf_lives);

	/* Number of times saved */
	wr_u16b(sf_saves);

	// 8 spare bytes
	wr_u32b(0L);
	wr_u32b(0L);

	/* Write the RNG state */
	wr_randomizer();

	/* Write the boolean "options" */
	wr_options();

	/* Dump the number of "messages" */
	tmp16u = message_num();
	wr_u16b(tmp16u);

	/* Dump the messages (oldest first!) */
	for (i = tmp16u - 1; i >= 0; i--)
	{
		wr_string(message_str((s16b)i));
		wr_u16b(message_type((s16b)i));
	}


	/* Dump the monster lore */
	tmp16u = z_info->r_max;
	wr_u16b(tmp16u);
	for (i = 0; i < tmp16u; i++) wr_lore(i);

	/* Dump the object memory */
	tmp16u = z_info->k_max;
	wr_u16b(tmp16u);
	for (i = 0; i < tmp16u; i++) wr_xtra(i);

	/* Hack -- Dump the artefacts */
	tmp16u = z_info->art_max;
	wr_u16b(tmp16u);
	for (i = 0; i < tmp16u; i++)
	{
		artefact_type *a_ptr = &a_info[i];
		wr_byte(a_ptr->cur_num);
		wr_byte(a_ptr->found_num);
	}

	/* Write the "extra" information */
	wr_extra();

	/*Write the randarts*/
	wr_randarts();

	/*Copy the notes file into the savefile*/
	wr_notes();

	// Write the smithing item
	wr_item(smith_o_ptr);
	
	/* Write the inventory */
	for (i = 0; i < INVEN_TOTAL; i++)
	{
		object_type *o_ptr = &inventory[i];

		/* Skip non-objects */
		if (!o_ptr->k_idx) continue;

		/* Dump index */
		wr_u16b((u16b)i);

		/* Dump object */
		wr_item(o_ptr);
	}

	/* Add a sentinel */
	wr_u16b(0xFFFF);

	/* Player is not dead, write the dungeon */
	if (!p_ptr->is_dead)
	{
		/* Dump the dungeon */
		wr_dungeon();
	}


	/* Write the "value check-sum" */
	wr_u32b(v_stamp);

	/* Write the "encoded checksum" */
	wr_u32b(x_stamp);


	/* Error in save */
	if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;

	/* Successful save */
	return TRUE;
}