1/*
2 * Copyright 2009, Axel D��rfler, axeld@pinc-software.de.
3 * Copyright 2002, Marcus Overhagen. All Rights Reserved.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef _SHARED_BUFFER_LIST_H_
7#define _SHARED_BUFFER_LIST_H_
8
9
10#include <Buffer.h>
11
12
13namespace BPrivate {
14
15
16class SharedBufferList {
17public:
18	static	area_id				Create(SharedBufferList** _list);
19	static	SharedBufferList*	Get();
20	static	void				Invalidate();
21
22			void				Put();
23			void 				DeleteGroupAndPut(sem_id groupReclaimSem);
24
25			status_t			Lock();
26			status_t			Unlock();
27
28			status_t			AddBuffer(sem_id groupReclaimSem,
29									BBuffer* buffer);
30			status_t			RequestBuffer(sem_id groupReclaimSem,
31									int32 buffersInGroup, size_t size,
32									media_buffer_id wantID, BBuffer** _buffer,
33									bigtime_t timeout);
34			status_t			RecycleBuffer(BBuffer* buffer);
35			status_t			GetBufferList(sem_id groupReclaimSem,
36									int32 bufferCount, BBuffer** buffers);
37
38private:
39	struct _shared_buffer_info {
40		media_buffer_id			id;
41		BBuffer*				buffer;
42		bool 					reclaimed;
43		// The reclaim_sem belonging to the BBufferGroup of this BBuffer
44		// is also used as a unique identifier of the group
45		sem_id					reclaim_sem;
46	};
47
48	enum { kMaxBuffers = 2047 };
49		// 16 bytes per buffer, 8 pages in total (one entry less for the list)
50
51			status_t			_Init();
52			void 				_RequestBufferInOtherGroups(
53									sem_id groupReclaimSem, media_buffer_id id);
54
55private:
56			sem_id				fSemaphore;
57			vint32				fAtom;
58
59			_shared_buffer_info	fInfos[kMaxBuffers];
60			int32				fCount;
61};
62
63
64}	// namespace BPrivate
65
66
67#endif	// _SHARED_BUFFER_LIST_H_
68