Skip to content

Commit 8864ac4

Browse files
committed
samples: posix: philosophers: rename 'fork' to avoid POSIX conflict
There is a function, `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 function in question is called `philosopher_fork()`. Signed-off-by: Chris Friedt <[email protected]>
1 parent ec84b80 commit 8864ac4

File tree

1 file changed

+7
-6
lines changed
  • samples/posix/philosophers/src

1 file changed

+7
-6
lines changed

samples/posix/philosophers/src/main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <stdbool.h>
1212
#include <stdio.h>
1313
#include <stdlib.h>
14+
#include <unistd.h>
1415

1516
#include <zephyr/sys/util.h>
1617
#include <zephyr/logging/log.h>
@@ -47,7 +48,7 @@ static inline void fork_init(fork_t frk)
4748
}
4849
}
4950

50-
static inline fork_t fork(size_t idx)
51+
static inline fork_t philosopher_fork(size_t idx)
5152
{
5253
return &forks[idx];
5354
}
@@ -148,11 +149,11 @@ static void *philosopher(void *arg)
148149

149150
/* Djkstra's solution: always pick up the lowest numbered fork first */
150151
if (is_last_philosopher(my_id)) {
151-
my_fork1 = fork(0);
152-
my_fork2 = fork(my_id);
152+
my_fork1 = philosopher_fork(0);
153+
my_fork2 = philosopher_fork(my_id);
153154
} else {
154-
my_fork1 = fork(my_id);
155-
my_fork2 = fork(my_id + 1);
155+
my_fork1 = philosopher_fork(my_id);
156+
my_fork2 = philosopher_fork(my_id + 1);
156157
}
157158

158159
while (1) {
@@ -204,7 +205,7 @@ static void init_objects(void)
204205
{
205206
ARRAY_FOR_EACH(forks, i) {
206207
LOG_DBG("Initializing fork %zu", i);
207-
fork_init(fork(i));
208+
fork_init(philosopher_fork(i));
208209
}
209210
}
210211

0 commit comments

Comments
 (0)