Import LinuxCNC source tree

This commit is contained in:
Wang Dequan
2026-08-20 06:17:39 +08:00
commit 2c814634c3
9429 changed files with 10556013 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
count=200000
test passed

View File

@@ -0,0 +1,38 @@
#include <rtapi_mutex.h>
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
// to make this test fail, you can...
#if 0
#define rtapi_mutex_give(x) (void)0
#define rtapi_mutex_get(x) (void)0
#endif
const unsigned int N = 100000;
unsigned long mut;
unsigned long count;
void *thread_fun(void *unused) {
for(unsigned long i=0; i<N; i++) {
rtapi_mutex_get(&mut);
unsigned long tmp = count;
tmp++;
sched_yield();
count = tmp;
rtapi_mutex_give(&mut);
}
return unused;
}
int main() {
pthread_t t1, t2;
pthread_create(&t1, NULL, thread_fun, NULL);
pthread_create(&t2, NULL, thread_fun, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
printf("count=%lu\n", count);
assert(count == 2*N);
printf("test passed\n");
return 0;
}

5
tests/lowlevel/mutex/test.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
gcc -O -I"${HEADERS}" test.c -o test -DULAPI -std=gnu99 -pthread || exit 1
./test; exitval=$?
rm -f test
exit $exitval