481 int signum; |
481 int signum; |
482 sigemptyset(&set); |
482 sigemptyset(&set); |
483 sigaddset(&set, SIGALRM); |
483 sigaddset(&set, SIGALRM); |
484 |
484 |
485 int client_node_id = (char *)_index - (char *)NULL; // Use pointer arithmetic (more portable than cast) |
485 int client_node_id = (char *)_index - (char *)NULL; // Use pointer arithmetic (more portable than cast) |
486 printf("%%d\n", client_node_id); |
|
487 /* initialize the timer that will be used to periodically activate the client node */ |
486 /* initialize the timer that will be used to periodically activate the client node */ |
488 { |
487 { |
489 // start off by reseting the flag that will be set whenever the timer expires |
488 // start off by reseting the flag that will be set whenever the timer expires |
490 client_nodes[client_node_id].periodic_act = 0; |
489 client_nodes[client_node_id].periodic_act = 0; |
491 |
490 |
609 goto error_exit; |
608 goto error_exit; |
610 } |
609 } |
611 client_nodes[index].init_state = 1; // we have created the node |
610 client_nodes[index].init_state = 1; // we have created the node |
612 |
611 |
613 /* initialize the mutex variable that will be used by the thread handling the client node */ |
612 /* initialize the mutex variable that will be used by the thread handling the client node */ |
|
613 bzero(&(client_nodes[index].mutex), sizeof(pthread_mutex_t)); |
614 if (pthread_mutex_init(&(client_nodes[index].mutex), NULL) < 0) { |
614 if (pthread_mutex_init(&(client_nodes[index].mutex), NULL) < 0) { |
615 fprintf(stderr, "Modbus plugin: Error creating mutex for modbus client node %%s\n", client_nodes[index].location); |
615 fprintf(stderr, "Modbus plugin: Error creating mutex for modbus client node %%s\n", client_nodes[index].location); |
616 goto error_exit; |
616 goto error_exit; |
617 } |
617 } |
618 client_nodes[index].init_state = 2; // we have created the mutex |
618 client_nodes[index].init_state = 2; // we have created the mutex |
619 |
619 |
620 /* initialize the condition variable that will be used by the thread handling the client node */ |
620 /* initialize the condition variable that will be used by the thread handling the client node */ |
|
621 bzero(&(client_nodes[index].condv), sizeof(pthread_cond_t)); |
621 if (pthread_cond_init(&(client_nodes[index].condv), NULL) < 0) { |
622 if (pthread_cond_init(&(client_nodes[index].condv), NULL) < 0) { |
622 fprintf(stderr, "Modbus plugin: Error creating condition variable for modbus client node %%s\n", client_nodes[index].location); |
623 fprintf(stderr, "Modbus plugin: Error creating condition variable for modbus client node %%s\n", client_nodes[index].location); |
623 goto error_exit; |
624 goto error_exit; |
624 } |
625 } |
625 client_nodes[index].execute_req = 0; //variable associated with condition variable |
626 client_nodes[index].execute_req = 0; //variable associated with condition variable |