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

Function get

examples/libc/ex2.c:60–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58/* Read and remove an integer from the buffer */
59
60static int get(struct prodcons * b)
61{
62 int data;
63 pthread_mutex_lock(&b->lock);
64 /* Wait until buffer is not empty */
65 while (b->writepos == b->readpos) {
66 pthread_cond_wait(&b->notempty, &b->lock);
67 }
68 /* Read the data and advance read pointer */
69 data = b->buffer[b->readpos];
70 b->readpos++;
71 if (b->readpos >= BUFFER_SIZE) b->readpos = 0;
72 /* Signal that the buffer is now not full */
73 pthread_cond_signal(&b->notfull);
74 pthread_mutex_unlock(&b->lock);
75 return data;
76}
77
78/* A test program: one thread inserts integers from 1 to 10000,
79 the other reads them and prints them. */

Callers 1

consumerFunction · 0.70

Calls 4

pthread_mutex_lockFunction · 0.85
pthread_cond_waitFunction · 0.85
pthread_cond_signalFunction · 0.85
pthread_mutex_unlockFunction · 0.85

Tested by

no test coverage detected