Skip to content

Commit 9a26e69

Browse files
authored
Merge pull request #958 from ChrisNisbet01/tune_command_locking_bug_fix
halcmd: fix "tune" command locking.
2 parents 56428e5 + a5103f6 commit 9a26e69

File tree

7 files changed

+91
-46
lines changed

7 files changed

+91
-46
lines changed

src/hal/hal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ RTAPI_BEGIN_DECLS
147147
#define HAL_LOCK_PARAMS 4 /* locking of parameter set commands */
148148
#define HAL_LOCK_RUN 8 /* locking of start/stop of HAL threads */
149149

150+
/* locks required for the 'tune' command */
151+
#define HAL_LOCK_TUNE (HAL_LOCK_LOAD | HAL_LOCK_CONFIG)
152+
150153
#define HAL_LOCK_ALL 255 /* locks every action */
151154

152155
/***********************************************************************

src/hal/utils/halcmd_commands.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,16 @@ static int match(char **patterns, char *value) {
112112

113113
int do_lock_cmd(char *command)
114114
{
115-
int retval=0;
116-
117-
/* if command is blank or "all", want to lock everything */
118-
if ((command == NULL) || (strcmp(command, "all") == 0)) {
119-
retval = hal_set_lock(HAL_LOCK_ALL);
120-
} else if (strcmp(command, "none") == 0) {
121-
retval = hal_set_lock(HAL_LOCK_NONE);
122-
} else if (strcmp(command, "tune") == 0) {
123-
retval = hal_set_lock(HAL_LOCK_LOAD & HAL_LOCK_CONFIG);
124-
} else if (strcmp(command, "all") == 0) {
125-
retval = hal_set_lock(HAL_LOCK_ALL);
126-
}
115+
int retval = 0;
116+
117+
/* if command is blank or "all", want to lock everything */
118+
if ((command == NULL) || (strcmp(command, "all") == 0)) {
119+
retval = hal_set_lock(HAL_LOCK_ALL);
120+
} else if (strcmp(command, "none") == 0) {
121+
retval = hal_set_lock(HAL_LOCK_NONE);
122+
} else if (strcmp(command, "tune") == 0) {
123+
retval = hal_set_lock(HAL_LOCK_TUNE);
124+
}
127125

128126
if (retval == 0) {
129127
/* print success message */
@@ -136,16 +134,16 @@ int do_lock_cmd(char *command)
136134

137135
int do_unlock_cmd(char *command)
138136
{
139-
int retval=0;
140-
141-
/* if command is blank or "all", want to unlock everything */
142-
if ((command == NULL) || (strcmp(command, "all") == 0)) {
143-
retval = hal_set_lock(HAL_LOCK_NONE);
144-
} else if (strcmp(command, "all") == 0) {
145-
retval = hal_set_lock(HAL_LOCK_NONE);
146-
} else if (strcmp(command, "tune") == 0) {
147-
retval = hal_set_lock(HAL_LOCK_LOAD & HAL_LOCK_CONFIG);
148-
}
137+
int retval = 0;
138+
139+
/* if command is blank or "all", want to unlock everything */
140+
if ((command == NULL) || (strcmp(command, "all") == 0)) {
141+
retval = hal_set_lock(HAL_LOCK_NONE);
142+
} else if (strcmp(command, "none") == 0) {
143+
retval = hal_set_lock(HAL_LOCK_NONE);
144+
} else if (strcmp(command, "tune") == 0) {
145+
retval = hal_set_lock(hal_get_lock() & ~HAL_LOCK_TUNE);
146+
}
149147

150148
if (retval == 0) {
151149
/* print success message */

src/hal/utils/halrmt.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -622,21 +622,18 @@ static int release_HAL_mutex(void)
622622

623623
static int doLock(char *command, connectionRecType *context)
624624
{
625-
int retval=0;
626-
const char *nakStr = "SET LOCK NAK";
627-
628-
/* if command is blank, want to lock everything */
629-
if (*command == '\0')
630-
retval = hal_set_lock(HAL_LOCK_ALL);
631-
else
632-
if (strcmp(command, "none") == 0)
633-
retval = hal_set_lock(HAL_LOCK_NONE);
634-
else
635-
if (strcmp(command, "tune") == 0)
636-
retval = hal_set_lock(HAL_LOCK_LOAD & HAL_LOCK_CONFIG);
637-
else
638-
if (strcmp(command, "all") == 0)
639-
retval = hal_set_lock(HAL_LOCK_ALL);
625+
int retval = 0;
626+
const char *nakStr = "SET LOCK NAK";
627+
628+
/* if command is blank, want to lock everything */
629+
if (*command == '\0')
630+
retval = hal_set_lock(HAL_LOCK_ALL);
631+
else if (strcmp(command, "none") == 0)
632+
retval = hal_set_lock(HAL_LOCK_NONE);
633+
else if (strcmp(command, "tune") == 0)
634+
retval = hal_set_lock(HAL_LOCK_TUNE);
635+
else if (strcmp(command, "all") == 0)
636+
retval = hal_set_lock(HAL_LOCK_ALL);
640637

641638
if (retval != 0) {
642639
snprintf(errorStr, sizeof(errorStr), "HAL:%d: Locking failed", linenumber);
@@ -650,15 +647,15 @@ static int doUnlock(char *command, connectionRecType *context)
650647
int retval=0;
651648
const char *nakStr = "SET UNLOCK NAK";
652649

653-
/* if command is blank, want to lock everything */
654-
if (*command == '\0')
655-
retval = hal_set_lock(HAL_LOCK_NONE);
656-
else
657-
if (strcmp(command, "all") == 0)
658-
retval = hal_set_lock(HAL_LOCK_NONE);
659-
else
660-
if (strcmp(command, "tune") == 0)
661-
retval = hal_set_lock(HAL_LOCK_LOAD & HAL_LOCK_CONFIG);
650+
/* if command is blank, want to unlock everything */
651+
if (*command == '\0')
652+
retval = hal_set_lock(HAL_LOCK_NONE);
653+
else if (strcmp(command, "none") == 0)
654+
retval = hal_set_lock(HAL_LOCK_NONE);
655+
else if (strcmp(command, "tune") == 0)
656+
retval = hal_set_lock(hal_get_lock() & ~HAL_LOCK_TUNE);
657+
else if (strcmp(command, "all") == 0)
658+
retval = hal_set_lock(HAL_LOCK_NONE);
662659

663660
if (retval != 0) {
664661
snprintf(errorStr, sizeof(errorStr), "HAL:%d: Unlocking failed", linenumber);

tests/halrun-lock/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tests that the various lock commands result in the expected locking status.

tests/halrun-lock/expected

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
HAL locking status:
2+
current lock value 0 (00)
3+
HAL_LOCK_NONE - nothing is locked
4+
HAL locking status:
5+
current lock value 255 (ff)
6+
HAL_LOCK_LOAD - loading of new components is locked
7+
HAL_LOCK_CONFIG - link and addf is locked
8+
HAL_LOCK_PARAMS - setting params is locked
9+
HAL_LOCK_RUN - running/stopping HAL is locked
10+
HAL locking status:
11+
current lock value 0 (00)
12+
HAL_LOCK_NONE - nothing is locked
13+
HAL locking status:
14+
current lock value 3 (03)
15+
HAL_LOCK_LOAD - loading of new components is locked
16+
HAL_LOCK_CONFIG - link and addf is locked
17+
HAL locking status:
18+
current lock value 0 (00)
19+
HAL_LOCK_NONE - nothing is locked
20+
HAL locking status:
21+
current lock value 255 (ff)
22+
HAL_LOCK_LOAD - loading of new components is locked
23+
HAL_LOCK_CONFIG - link and addf is locked
24+
HAL_LOCK_PARAMS - setting params is locked
25+
HAL_LOCK_RUN - running/stopping HAL is locked
26+
HAL locking status:
27+
current lock value 0 (00)
28+
HAL_LOCK_NONE - nothing is locked

tests/halrun-lock/halrun.hal

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
status
2+
lock
3+
status
4+
unlock
5+
status
6+
lock tune
7+
status
8+
unlock tune
9+
status
10+
lock all
11+
status
12+
unlock all
13+
status
14+

tests/halrun-lock/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
halrun -f halrun.hal | grep -i lock
4+

0 commit comments

Comments
 (0)