summaryrefslogtreecommitdiff
path: root/docs/random/queue
blob: 6641e229ff75499d785c6b76982d2204082b15b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
            thread 1                                         thread2

                             				   // the queue is empty
                                                           while (!queue->level_buffers) {
                                                             STATUS("queue: %s U released lock\n");
                                                             GST_OBJECT_UNLOCK (queue);

  // thread1 is scheduled and puts a lot of buffers
  // in the queue

  // thread1 has put the last buffer on the queue
  // here. A signal is going to be emited

  tosignal = (queue->level_buffers >= 0);
  queue->level_buffers++;

  /* we can unlock now */
  GST_OBJECT_UNLOCK (queue);

  if (tosignal) {
    g_mutex_lock (queue->emptylock);
    g_cond_signal (queue->emptycond);
    g_mutex_unlock (queue->emptylock);
  }

                                                             g_mutex_lock (queue->emptylock);
							     // wait forever
                                                             g_cond_wait (queue->emptycond, queue->emptylock);
                                                             g_mutex_unlock (queue->emptylock);
                                                             GST_OBJECT_LOCK (queue);
                                                           }
							   

  // thread 1 will also wait forever because the
  // queue is filled....