2 * Copyright 2002, Marcus Overhagen. All rights reserved.
3 * Distributed under the terms of the MIT License.
7 /*! This is a simple multi thread save queue.
9 One thread calls AddItem() to add items, and when it is finished doing
10 so, it calls Terminate(). Another thread calls RemoveItem() to remove
11 items from the queue. RemoveItem() blocks when no items are available.
12 As soon as Terminate() is called and the queue is empty, RemoveItem()
25 BLocker("queue locker"),
26 fSem(create_sem(0, "queue sem"))
53 Queue::AddItem(void* item
)
60 if (!fList
.AddItem(item
))
71 // if the semaphore is deleted by Terminate(),
72 // this will no longer block
73 while (acquire_sem(fSem
) == B_INTERRUPTED
)
78 // if the list is empty, which can only happen after
79 // Terminate() was called, item will be NULL
80 return fList
.RemoveItem((int32
)0);