Skip to content

Commit f6eb86f

Browse files
committed
samples: 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 63868e4 commit f6eb86f

File tree

1 file changed

+8
-8
lines changed
  • samples/philosophers/src

1 file changed

+8
-8
lines changed

samples/philosophers/src/main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888
#include "phil_obj_abstract.h"
8989

90-
#define fork(x) (forks[x])
90+
#define philosopher_fork(x) (forks[x])
9191

9292
static void set_phil_state_pos(int id)
9393
{
@@ -149,11 +149,11 @@ void philosopher(void *id, void *unused1, void *unused2)
149149

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

159159
while (1) {
@@ -202,7 +202,7 @@ static void init_objects(void)
202202
{
203203
#if !STATIC_OBJS
204204
for (int i = 0; i < NUM_PHIL; i++) {
205-
fork_init(fork(i));
205+
fork_init(philosopher_fork(i));
206206
}
207207
#endif
208208
}
@@ -225,8 +225,8 @@ static void start_threads(void)
225225
snprintk(tname, CONFIG_THREAD_MAX_NAME_LEN, "Philosopher %d", i);
226226
k_thread_name_set(&threads[i], tname);
227227
#endif /* CONFIG_THREAD_NAME */
228-
k_object_access_grant(fork(i), &threads[i]);
229-
k_object_access_grant(fork((i + 1) % NUM_PHIL), &threads[i]);
228+
k_object_access_grant(philosopher_fork(i), &threads[i]);
229+
k_object_access_grant(philosopher_fork((i + 1) % NUM_PHIL), &threads[i]);
230230

231231
k_thread_start(&threads[i]);
232232
}

0 commit comments

Comments
 (0)