fix gcc4 build

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22590 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2007-10-16 19:02:28 +00:00
parent e7e325508b
commit 287cc7652b
+314 -310
View File
@@ -1,310 +1,314 @@
/****************************************************************************** /******************************************************************************
File: BufferStream.h File: BufferStream.h
Copyright 1995-97, Be Incorporated Copyright 1995-97, Be Incorporated
******************************************************************************/ ******************************************************************************/
#ifndef _BUFFER_STREAM_H #ifndef _BUFFER_STREAM_H
#define _BUFFER_STREAM_H #define _BUFFER_STREAM_H
#include <stdlib.h> #include <stdlib.h>
#include <OS.h> #include <OS.h>
#include <SupportDefs.h> #include <SupportDefs.h>
#include <ClassInfo.h> #include <ClassInfo.h>
#include <Locker.h> #include <Locker.h>
#include <Messenger.h> #include <Messenger.h>
/* ================
Per-subscriber information. class BSubscriber;
================ */
struct _sbuf_info; /* ================
Per-subscriber information.
typedef struct _sub_info { ================ */
_sub_info *fNext; /* next subscriber in the stream*/
_sub_info *fPrev; /* previous subscriber in the stream */ struct _sbuf_info;
_sbuf_info *fRel; /* next buf to be released */
_sbuf_info *fAcq; /* next buf to be acquired */ typedef struct _sub_info {
sem_id fSem; /* semaphore used for blocking */ _sub_info *fNext; /* next subscriber in the stream*/
bigtime_t fTotalTime; /* accumulated time between acq/rel */ _sub_info *fPrev; /* previous subscriber in the stream */
int32 fHeld; /* # of buffers acq'd but not yet rel'd */ _sbuf_info *fRel; /* next buf to be released */
sem_id fBlockedOn; /* the semaphore being waited on */ _sbuf_info *fAcq; /* next buf to be acquired */
/* or B_BAD_SEM_ID if not blocked */ sem_id fSem; /* semaphore used for blocking */
} *subscriber_id; bigtime_t fTotalTime; /* accumulated time between acq/rel */
int32 fHeld; /* # of buffers acq'd but not yet rel'd */
sem_id fBlockedOn; /* the semaphore being waited on */
/* ================ /* or B_BAD_SEM_ID if not blocked */
Per-buffer information } *subscriber_id;
================ */
typedef struct _sbuf_info { /* ================
_sbuf_info *fNext; /* next "newer" buffer in the chain */ Per-buffer information
subscriber_id fAvailTo; /* next subscriber to acquire this buffer */ ================ */
subscriber_id fHeldBy; /* subscriber that's acquired this buffer */
bigtime_t fAcqTime; /* time at which this buffer was acquired */ typedef struct _sbuf_info {
area_id fAreaID; /* for system memory allocation calls */ _sbuf_info *fNext; /* next "newer" buffer in the chain */
char *fAddress; subscriber_id fAvailTo; /* next subscriber to acquire this buffer */
int32 fSize; /* usable portion can be smaller than ... */ subscriber_id fHeldBy; /* subscriber that's acquired this buffer */
int32 fAreaSize; /* ... the size of the area. */ bigtime_t fAcqTime; /* time at which this buffer was acquired */
bool fIsFinal; /* TRUE => stream is stopping */ area_id fAreaID; /* for system memory allocation calls */
} *buffer_id; char *fAddress;
int32 fSize; /* usable portion can be smaller than ... */
int32 fAreaSize; /* ... the size of the area. */
/* ================ bool fIsFinal; /* TRUE => stream is stopping */
Interface definition for BBufferStream class } *buffer_id;
================ */
/* We've chosen B_MAX_SUBSCRIBER_COUNT and B_MAX_BUFFER_COUNT to be small /* ================
* enough so that a BBufferStream structure fits in one 4096 byte page. Interface definition for BBufferStream class
*/ ================ */
#define B_MAX_SUBSCRIBER_COUNT 52
#define B_MAX_BUFFER_COUNT 32 /* We've chosen B_MAX_SUBSCRIBER_COUNT and B_MAX_BUFFER_COUNT to be small
* enough so that a BBufferStream structure fits in one 4096 byte page.
class BBufferStream; */
class BBufferStreamManager; #define B_MAX_SUBSCRIBER_COUNT 52
#define B_MAX_BUFFER_COUNT 32
typedef BBufferStream* stream_id; // for now
class BBufferStream;
class BBufferStreamManager;
class BAbstractBufferStream
{ typedef BBufferStream* stream_id; // for now
public:
virtual status_t GetStreamParameters(size_t *bufferSize, class BAbstractBufferStream
int32 *bufferCount, {
bool *isRunning, public:
int32 *subscriberCount) const;
virtual status_t GetStreamParameters(size_t *bufferSize,
virtual status_t SetStreamBuffers(size_t bufferSize, int32 *bufferCount,
int32 bufferCount); bool *isRunning,
int32 *subscriberCount) const;
virtual status_t StartStreaming();
virtual status_t StopStreaming(); virtual status_t SetStreamBuffers(size_t bufferSize,
int32 bufferCount);
protected:
virtual status_t StartStreaming();
virtual void _ReservedAbstractBufferStream1(); virtual status_t StopStreaming();
virtual void _ReservedAbstractBufferStream2();
virtual void _ReservedAbstractBufferStream3(); protected:
virtual void _ReservedAbstractBufferStream4();
virtual void _ReservedAbstractBufferStream1();
friend class BSubscriber; virtual void _ReservedAbstractBufferStream2();
friend class BBufferStreamManager; virtual void _ReservedAbstractBufferStream3();
virtual void _ReservedAbstractBufferStream4();
virtual stream_id StreamID() const;
/* stream identifier for direct access */ friend class BSubscriber;
friend class BBufferStreamManager;
/* Create or delete a subscriber id for subsequent operations */
virtual status_t Subscribe(char *name, virtual stream_id StreamID() const;
subscriber_id *subID, /* stream identifier for direct access */
sem_id semID);
virtual status_t Unsubscribe(subscriber_id subID); /* Create or delete a subscriber id for subsequent operations */
virtual status_t Subscribe(char *name,
/* Enter into or quit the stream */ subscriber_id *subID,
virtual status_t EnterStream(subscriber_id subID, sem_id semID);
subscriber_id neighbor, virtual status_t Unsubscribe(subscriber_id subID);
bool before);
/* Enter into or quit the stream */
virtual status_t ExitStream(subscriber_id subID); virtual status_t EnterStream(subscriber_id subID,
subscriber_id neighbor,
virtual BMessenger* Server() const; /* message pipe to server */ bool before);
status_t SendRPC(BMessage* msg, BMessage* reply = NULL) const;
}; virtual status_t ExitStream(subscriber_id subID);
virtual BMessenger* Server() const; /* message pipe to server */
class BBufferStream : public BAbstractBufferStream status_t SendRPC(BMessage* msg, BMessage* reply = NULL) const;
{ };
public:
BBufferStream(size_t headerSize, class BBufferStream : public BAbstractBufferStream
BBufferStreamManager* controller, {
BSubscriber* headFeeder, public:
BSubscriber* tailFeeder);
virtual ~BBufferStream(); BBufferStream(size_t headerSize,
BBufferStreamManager* controller,
/* BBufferStreams are allocated on shared memory pages */ BSubscriber* headFeeder,
void *operator new(size_t size); BSubscriber* tailFeeder);
void operator delete(void *stream, size_t size); virtual ~BBufferStream();
/* Return header size */ /* BBufferStreams are allocated on shared memory pages */
size_t HeaderSize() const; void *operator new(size_t size);
void operator delete(void *stream, size_t size);
/* These four functions are delegated to the stream controller */
status_t GetStreamParameters(size_t *bufferSize, /* Return header size */
int32 *bufferCount, size_t HeaderSize() const;
bool *isRunning,
int32 *subscriberCount) const; /* These four functions are delegated to the stream controller */
status_t GetStreamParameters(size_t *bufferSize,
status_t SetStreamBuffers(size_t bufferSize, int32 *bufferCount,
int32 bufferCount); bool *isRunning,
int32 *subscriberCount) const;
status_t StartStreaming();
status_t StopStreaming(); status_t SetStreamBuffers(size_t bufferSize,
int32 bufferCount);
/* Get the controller for delegation */
BBufferStreamManager *StreamManager() const; status_t StartStreaming();
status_t StopStreaming();
/* number of buffers in stream */
int32 CountBuffers() const; /* Get the controller for delegation */
BBufferStreamManager *StreamManager() const;
/* Create or delete a subscriber id for subsequent operations */
status_t Subscribe(char *name, /* number of buffers in stream */
subscriber_id *subID, int32 CountBuffers() const;
sem_id semID);
/* Create or delete a subscriber id for subsequent operations */
status_t Unsubscribe(subscriber_id subID); status_t Subscribe(char *name,
subscriber_id *subID,
/* Enter into or quit the stream */ sem_id semID);
status_t EnterStream(subscriber_id subID,
subscriber_id neighbor, status_t Unsubscribe(subscriber_id subID);
bool before);
/* Enter into or quit the stream */
status_t ExitStream(subscriber_id subID); status_t EnterStream(subscriber_id subID,
subscriber_id neighbor,
/* queries about a subscriber */ bool before);
bool IsSubscribed(subscriber_id subID);
bool IsEntered(subscriber_id subID); status_t ExitStream(subscriber_id subID);
status_t SubscriberInfo(subscriber_id subID, /* queries about a subscriber */
char** name, bool IsSubscribed(subscriber_id subID);
stream_id* streamID, bool IsEntered(subscriber_id subID);
int32* position);
status_t SubscriberInfo(subscriber_id subID,
/* Force an error return of a subscriber if it's blocked */ char** name,
status_t UnblockSubscriber(subscriber_id subID); stream_id* streamID,
int32* position);
/* Acquire and release a buffer */
status_t AcquireBuffer(subscriber_id subID, /* Force an error return of a subscriber if it's blocked */
buffer_id *bufID, status_t UnblockSubscriber(subscriber_id subID);
bigtime_t timeout);
status_t ReleaseBuffer(subscriber_id subID); /* Acquire and release a buffer */
status_t AcquireBuffer(subscriber_id subID,
/* Get the attributes of a particular buffer */ buffer_id *bufID,
size_t BufferSize(buffer_id bufID) const; bigtime_t timeout);
char *BufferData(buffer_id bufID) const; status_t ReleaseBuffer(subscriber_id subID);
bool IsFinalBuffer(buffer_id bufID) const;
/* Get the attributes of a particular buffer */
/* Get attributes of a particular subscriber */ size_t BufferSize(buffer_id bufID) const;
int32 CountBuffersHeld(subscriber_id subID); char *BufferData(buffer_id bufID) const;
bool IsFinalBuffer(buffer_id bufID) const;
/* Queries for the BBufferStream */
int32 CountSubscribers() const; /* Get attributes of a particular subscriber */
int32 CountEnteredSubscribers() const; int32 CountBuffersHeld(subscriber_id subID);
subscriber_id FirstSubscriber() const; /* Queries for the BBufferStream */
subscriber_id LastSubscriber() const; int32 CountSubscribers() const;
subscriber_id NextSubscriber(subscriber_id subID); int32 CountEnteredSubscribers() const;
subscriber_id PrevSubscriber(subscriber_id subID);
subscriber_id FirstSubscriber() const;
/* debugging aids */ subscriber_id LastSubscriber() const;
void PrintStream(); subscriber_id NextSubscriber(subscriber_id subID);
void PrintBuffers(); subscriber_id PrevSubscriber(subscriber_id subID);
void PrintSubscribers();
/* debugging aids */
/* gaining exclusive access to the BBufferStream */ void PrintStream();
bool Lock(); void PrintBuffers();
void Unlock(); void PrintSubscribers();
/* introduce a new buffer into the "newest" end of the chain */ /* gaining exclusive access to the BBufferStream */
status_t AddBuffer(buffer_id bufID); bool Lock();
void Unlock();
/* remove a buffer from the "oldest" end of the chain */
buffer_id RemoveBuffer(bool force); /* introduce a new buffer into the "newest" end of the chain */
status_t AddBuffer(buffer_id bufID);
/* allocate a buffer from shared memory and create a bufID for it. */
buffer_id CreateBuffer(size_t size, bool isFinal); /* remove a buffer from the "oldest" end of the chain */
buffer_id RemoveBuffer(bool force);
/* deallocate a buffer and returns its bufID to the freelist */
void DestroyBuffer(buffer_id bufID); /* allocate a buffer from shared memory and create a bufID for it. */
buffer_id CreateBuffer(size_t size, bool isFinal);
/* remove and destroy any "newest" buffers from the head of the chain
* that have not yet been claimed by any subscribers. If there are /* deallocate a buffer and returns its bufID to the freelist */
* no subscribers, this clears the entire chain. void DestroyBuffer(buffer_id bufID);
*/
void RescindBuffers(); /* remove and destroy any "newest" buffers from the head of the chain
* that have not yet been claimed by any subscribers. If there are
/* ================ * no subscribers, this clears the entire chain.
Private member functions that assume locking already has been done. */
================ */ void RescindBuffers();
private: /* ================
Private member functions that assume locking already has been done.
virtual void _ReservedBufferStream1(); ================ */
virtual void _ReservedBufferStream2();
virtual void _ReservedBufferStream3(); private:
virtual void _ReservedBufferStream4();
virtual void _ReservedBufferStream1();
/* initialize the free list of subscribers */ virtual void _ReservedBufferStream2();
void InitSubscribers(); virtual void _ReservedBufferStream3();
virtual void _ReservedBufferStream4();
/* return TRUE if subID appears valid */
bool IsSubscribedSafe(subscriber_id subID) const; /* initialize the free list of subscribers */
void InitSubscribers();
/* return TRUE if subID is entered into the stream */
bool IsEnteredSafe(subscriber_id subID) const; /* return TRUE if subID appears valid */
bool IsSubscribedSafe(subscriber_id subID) const;
/* initialize the free list of buffer IDs */
void InitBuffers(); /* return TRUE if subID is entered into the stream */
bool IsEnteredSafe(subscriber_id subID) const;
/* Wake a blocked subscriber */
status_t WakeSubscriber(subscriber_id subID); /* initialize the free list of buffer IDs */
void InitBuffers();
/* Give subID all the buffers it can get */
void InheritBuffers(subscriber_id subID); /* Wake a blocked subscriber */
status_t WakeSubscriber(subscriber_id subID);
/* Relinquish any buffers held by subID */
void BequeathBuffers(subscriber_id subID); /* Give subID all the buffers it can get */
void InheritBuffers(subscriber_id subID);
/* Fast version of ReleaseBuffer() */
status_t ReleaseBufferSafe(subscriber_id subID); /* Relinquish any buffers held by subID */
void BequeathBuffers(subscriber_id subID);
/* Release a buffer to a subscriber */
status_t ReleaseBufferTo(buffer_id bufID, subscriber_id subID); /* Fast version of ReleaseBuffer() */
status_t ReleaseBufferSafe(subscriber_id subID);
/* deallocate all buffers */
void FreeAllBuffers(); /* Release a buffer to a subscriber */
status_t ReleaseBufferTo(buffer_id bufID, subscriber_id subID);
/* deallocate all subscribers */
void FreeAllSubscribers(); /* deallocate all buffers */
void FreeAllBuffers();
/* ================
Private data members /* deallocate all subscribers */
================ */ void FreeAllSubscribers();
BLocker fLock; /* ================
area_id fAreaID; /* area id for this BBufferStream */ Private data members
BBufferStreamManager *fStreamManager; ================ */
BSubscriber *fHeadFeeder;
BSubscriber *fTailFeeder; BLocker fLock;
size_t fHeaderSize; area_id fAreaID; /* area id for this BBufferStream */
BBufferStreamManager *fStreamManager;
/* ================ BSubscriber *fHeadFeeder;
subscribers BSubscriber *fTailFeeder;
================ */ size_t fHeaderSize;
_sub_info *fFreeSubs; /* free list of subscribers */ /* ================
_sub_info *fFirstSub; /* first entered in itinierary */ subscribers
_sub_info *fLastSub; /* last entered in itinerary */ ================ */
sem_id fFirstSem; /* semaphore used by fFirstSub */ _sub_info *fFreeSubs; /* free list of subscribers */
int32 fSubCount; _sub_info *fFirstSub; /* first entered in itinierary */
int32 fEnteredSubCount; _sub_info *fLastSub; /* last entered in itinerary */
_sub_info fSubscribers[B_MAX_SUBSCRIBER_COUNT]; sem_id fFirstSem; /* semaphore used by fFirstSub */
int32 fSubCount;
/* ================ int32 fEnteredSubCount;
buffers
================ */ _sub_info fSubscribers[B_MAX_SUBSCRIBER_COUNT];
_sbuf_info *fFreeBuffers; /* ================
_sbuf_info *fOldestBuffer; /* first in line */ buffers
_sbuf_info *fNewestBuffer; /* fNewest->fNext = NULL */ ================ */
int32 fCountBuffers;
_sbuf_info *fFreeBuffers;
_sbuf_info fBuffers[B_MAX_BUFFER_COUNT]; _sbuf_info *fOldestBuffer; /* first in line */
_sbuf_info *fNewestBuffer; /* fNewest->fNext = NULL */
uint32 _reserved[4]; int32 fCountBuffers;
};
_sbuf_info fBuffers[B_MAX_BUFFER_COUNT];
#endif // #ifdef _BUFFER_STREAM_H
uint32 _reserved[4];
};
#endif // #ifdef _BUFFER_STREAM_H