MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / test_thread

Function test_thread

examples/libc/ex7.c:33–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31event_t main_event;
32
33static void *test_thread(void *ms_param) {
34 int status = 0;
35 event_t foo;
36 struct timespec time;
37 struct timeval now;
38 long ms = (long) ms_param;
39
40 /* initialize cond var */
41 pthread_cond_init(&foo.cond, NULL);
42 pthread_mutex_init(&foo.mutex, NULL);
43 foo.flag = 0;
44
45 /* set the time out value */
46 printf("waiting %ld ms ...\n", ms);
47 gettimeofday(&now, NULL);
48 time.tv_sec = now.tv_sec + ms / 1000 + (now.tv_usec + (ms % 1000) * 1000)
49 / 1000000;
50 time.tv_nsec = ((now.tv_usec + (ms % 1000) * 1000) % 1000000) * 1000;
51
52 /* Just use this to test the time out. The cond var is never signaled. */
53 pthread_mutex_lock(&foo.mutex);
54 while (foo.flag == 0 && status != ETIMEDOUT) {
55 status = pthread_cond_timedwait(&foo.cond, &foo.mutex, &time);
56 }
57 pthread_mutex_unlock(&foo.mutex);
58
59 /* post the main event */
60 pthread_mutex_lock(&main_event.mutex);
61 main_event.flag = 1;
62 pthread_cond_signal(&main_event.cond);
63 pthread_mutex_unlock(&main_event.mutex);
64
65 /* that's it, bye */
66 return (void*) status;
67}
68
69int libc_ex7(void) {
70 unsigned long count;

Callers

nothing calls this directly

Calls 8

pthread_cond_initFunction · 0.85
pthread_mutex_initFunction · 0.85
gettimeofdayFunction · 0.85
pthread_mutex_lockFunction · 0.85
pthread_cond_timedwaitFunction · 0.85
pthread_mutex_unlockFunction · 0.85
pthread_cond_signalFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected