Skip to content

Commit ec84b80

Browse files
committed
samples: cmsis: philosophers: rename 'fork' to avoid POSIX conflict
There is a macro, `fork()`, inside of the philosophers example that conflicts with the POSIX `fork()` function. Since it is customary to avoid using reserved names, adjust the sample so that the macro in question is called `philosopher_fork()`. Signed-off-by: Chris Friedt <[email protected]>
1 parent f6eb86f commit ec84b80

File tree

2 files changed

+10
-10
lines changed
  • samples/subsys/portability
    • cmsis_rtos_v1/philosophers/src
    • cmsis_rtos_v2/philosophers/src

2 files changed

+10
-10
lines changed

samples/subsys/portability/cmsis_rtos_v1/philosophers/src/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
/***************************************/
7070
osSemaphoreId forks[NUM_PHIL];
7171

72-
#define fork(x) (forks[x])
72+
#define philosopher_fork(x) (forks[x])
7373

7474
/*
7575
* CMSIS limits the stack size, but qemu_x86_64, qemu_xtensa (all),
@@ -149,11 +149,11 @@ void philosopher(void const *id)
149149

150150
/* Djkstra's solution: always pick up the lowest numbered fork first */
151151
if (is_last_philosopher(my_id)) {
152-
fork1 = fork(0);
153-
fork2 = fork(my_id);
152+
fork1 = philosopher_fork(0);
153+
fork2 = philosopher_fork(my_id);
154154
} else {
155-
fork1 = fork(my_id);
156-
fork2 = fork(my_id + 1);
155+
fork1 = philosopher_fork(my_id);
156+
fork2 = philosopher_fork(my_id + 1);
157157
}
158158

159159
while (1) {

samples/subsys/portability/cmsis_rtos_v2/philosophers/src/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
/***************************************/
6666
osSemaphoreId_t forks[NUM_PHIL];
6767

68-
#define fork(x) (forks[x])
68+
#define philosopher_fork(x) (forks[x])
6969

7070
#define STACK_SIZE CONFIG_CMSIS_V2_THREAD_MAX_STACK_SIZE
7171
static K_THREAD_STACK_ARRAY_DEFINE(stacks, NUM_PHIL, STACK_SIZE);
@@ -174,11 +174,11 @@ void philosopher(void *id)
174174

175175
/* Djkstra's solution: always pick up the lowest numbered fork first */
176176
if (is_last_philosopher(my_id)) {
177-
fork1 = fork(0);
178-
fork2 = fork(my_id);
177+
fork1 = philosopher_fork(0);
178+
fork2 = philosopher_fork(my_id);
179179
} else {
180-
fork1 = fork(my_id);
181-
fork2 = fork(my_id + 1);
180+
fork1 = philosopher_fork(my_id);
181+
fork2 = philosopher_fork(my_id + 1);
182182
}
183183

184184
while (1) {

0 commit comments

Comments
 (0)