Lines Matching refs:b
31 static void init(struct prodcons * b) in init() argument
33 pthread_mutex_init(&b->lock, NULL); in init()
34 pthread_cond_init(&b->notempty, NULL); in init()
35 pthread_cond_init(&b->notfull, NULL); in init()
36 b->readpos = 0; in init()
37 b->writepos = 0; in init()
41 static void put(struct prodcons * b, int data) in put() argument
43 pthread_mutex_lock(&b->lock); in put()
45 while ((b->writepos + 1) % BUFFER_SIZE == b->readpos) { in put()
46 pthread_cond_wait(&b->notfull, &b->lock); in put()
50 b->buffer[b->writepos] = data; in put()
51 b->writepos++; in put()
52 if (b->writepos >= BUFFER_SIZE) b->writepos = 0; in put()
54 pthread_cond_signal(&b->notempty); in put()
55 pthread_mutex_unlock(&b->lock); in put()
60 static int get(struct prodcons * b) in get() argument
63 pthread_mutex_lock(&b->lock); in get()
65 while (b->writepos == b->readpos) { in get()
66 pthread_cond_wait(&b->notempty, &b->lock); in get()
69 data = b->buffer[b->readpos]; in get()
70 b->readpos++; in get()
71 if (b->readpos >= BUFFER_SIZE) b->readpos = 0; in get()
73 pthread_cond_signal(&b->notfull); in get()
74 pthread_mutex_unlock(&b->lock); in get()