@@ -23,11 +23,11 @@ serial_port::serial_port()
23
23
/* -----------------------------------------------------*\
24
24
| Set default port configuration but do not open |
25
25
\*-----------------------------------------------------*/
26
- baud_rate = 9600 ;
27
- parity = SERIAL_PORT_PARITY_NONE;
28
- size = SERIAL_PORT_SIZE_8;
29
- stop_bits = SERIAL_PORT_STOP_BITS_1;
30
- flow_control = true ;
26
+ this -> baud_rate = 9600 ;
27
+ this -> parity = SERIAL_PORT_PARITY_NONE;
28
+ this -> size = SERIAL_PORT_SIZE_8;
29
+ this -> stop_bits = SERIAL_PORT_STOP_BITS_1;
30
+ this -> flow_control = false ;
31
31
}
32
32
33
33
/* ---------------------------------------------------------*\
@@ -40,11 +40,11 @@ serial_port::serial_port(const char * name, unsigned int baud)
40
40
/* -----------------------------------------------------*\
41
41
| Set default port configuration and open |
42
42
\*-----------------------------------------------------*/
43
- baud_rate = baud;
44
- parity = SERIAL_PORT_PARITY_NONE;
45
- size = SERIAL_PORT_SIZE_8;
46
- stop_bits = SERIAL_PORT_STOP_BITS_1;
47
- flow_control = true ;
43
+ this -> baud_rate = baud;
44
+ this -> parity = SERIAL_PORT_PARITY_NONE;
45
+ this -> size = SERIAL_PORT_SIZE_8;
46
+ this -> stop_bits = SERIAL_PORT_STOP_BITS_1;
47
+ this -> flow_control = false ;
48
48
49
49
serial_open (name);
50
50
}
@@ -230,6 +230,16 @@ bool serial_port::serial_open()
230
230
return false ;
231
231
}
232
232
233
+ /* -----------------------------------------*\
234
+ | Set an advisory lock on the port and |
235
+ | abort port setup if already locked |
236
+ \*-----------------------------------------*/
237
+ if (flock (file_descriptor, LOCK_EX | LOCK_NB) < 0 )
238
+ {
239
+ close (file_descriptor);
240
+ return false ;
241
+ }
242
+
233
243
/* -----------------------------------------*\
234
244
| Get the port configuration options |
235
245
\*-----------------------------------------*/
@@ -496,6 +506,7 @@ void serial_port::serial_close()
496
506
| Linux-specific code path for serial close |
497
507
\*-----------------------------------------------------*/
498
508
#ifdef __linux__
509
+ flock (file_descriptor, LOCK_UN | LOCK_NB);
499
510
close (file_descriptor);
500
511
#endif
501
512
0 commit comments