* Changed type of "bytesNeeded" to size_t whereever it's used.

* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17491 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-05-17 14:12:41 +00:00
parent 467a2ae6f8
commit 6632e1f482
2 changed files with 110 additions and 107 deletions
+19 -16
View File
@@ -102,10 +102,9 @@ protected:
class WriterLocker : public AbstractLocker { class WriterLocker : public AbstractLocker {
public: public:
WriterLocker(tty_cookie *sourceCookie); WriterLocker(tty_cookie *sourceCookie);
~WriterLocker(); ~WriterLocker();
status_t AcquireWriter(bool dontBlock, int32 bytesNeeded); status_t AcquireWriter(bool dontBlock, size_t bytesNeeded);
private: private:
size_t _CheckAvailableBytes() const; size_t _CheckAvailableBytes() const;
@@ -152,7 +151,6 @@ public:
if (--cookie->thread_count == 0 && cookie->closed) if (--cookie->thread_count == 0 && cookie->closed)
semaphore = cookie->blocking_semaphore; semaphore = cookie->blocking_semaphore;
locker.Unlock(); locker.Unlock();
if (semaphore >= 0) { if (semaphore >= 0) {
@@ -169,8 +167,10 @@ typedef AutoLocker<tty_cookie, TTYReferenceLocking> TTYReference;
// #pragma mark - // #pragma mark -
Request::Request() Request::Request()
: fOwner(NULL), :
fOwner(NULL),
fCookie(NULL), fCookie(NULL),
fBytesNeeded(0), fBytesNeeded(0),
fNotified(false), fNotified(false),
@@ -180,7 +180,7 @@ Request::Request()
void void
Request::Init(RequestOwner *owner, tty_cookie *cookie, int32 bytesNeeded) Request::Init(RequestOwner *owner, tty_cookie *cookie, size_t bytesNeeded)
{ {
fOwner = owner; fOwner = owner;
fCookie = cookie; fCookie = cookie;
@@ -191,7 +191,7 @@ Request::Init(RequestOwner *owner, tty_cookie *cookie, int32 bytesNeeded)
void void
Request::Notify(int32 bytesAvailable) Request::Notify(size_t bytesAvailable)
{ {
if (!fNotified && bytesAvailable >= fBytesNeeded && fOwner) { if (!fNotified && bytesAvailable >= fBytesNeeded && fOwner) {
fOwner->Notify(this); fOwner->Notify(this);
@@ -213,8 +213,10 @@ Request::NotifyError(status_t error)
// #pragma mark - // #pragma mark -
RequestQueue::RequestQueue() RequestQueue::RequestQueue()
: fRequests() :
fRequests()
{ {
} }
@@ -242,7 +244,7 @@ RequestQueue::Remove(Request *request)
void void
RequestQueue::NotifyFirst(int32 bytesAvailable) RequestQueue::NotifyFirst(size_t bytesAvailable)
{ {
RecursiveLocker _(gTTYRequestLock); RecursiveLocker _(gTTYRequestLock);
@@ -276,8 +278,10 @@ RequestQueue::NotifyError(tty_cookie *cookie, status_t error)
// #pragma mark - // #pragma mark -
RequestOwner::RequestOwner() RequestOwner::RequestOwner()
: fSemaphore(NULL), :
fSemaphore(NULL),
fCookie(NULL), fCookie(NULL),
fError(B_OK), fError(B_OK),
fBytesNeeded(1) fBytesNeeded(1)
@@ -332,7 +336,7 @@ RequestOwner::Dequeue()
void void
RequestOwner::SetBytesNeeded(int32 bytesNeeded) RequestOwner::SetBytesNeeded(size_t bytesNeeded)
{ {
if (fRequestQueues[0]) if (fRequestQueues[0])
fRequests[0].Init(this, fCookie, bytesNeeded); fRequests[0].Init(this, fCookie, bytesNeeded);
@@ -455,9 +459,9 @@ RequestOwner::NotifyError(Request *request, status_t error)
// #pragma mark - // #pragma mark -
WriterLocker::WriterLocker(tty_cookie *sourceCookie) WriterLocker::WriterLocker(tty_cookie *sourceCookie)
: : AbstractLocker(sourceCookie),
AbstractLocker(sourceCookie),
fSource(fCookie->tty), fSource(fCookie->tty),
fTarget(fCookie->other_tty), fTarget(fCookie->other_tty),
fRequestOwner(), fRequestOwner(),
@@ -522,7 +526,7 @@ WriterLocker::_CheckAvailableBytes() const
status_t status_t
WriterLocker::AcquireWriter(bool dontBlock, int32 bytesNeeded) WriterLocker::AcquireWriter(bool dontBlock, size_t bytesNeeded)
{ {
if (!fTarget) if (!fTarget)
return B_FILE_ERROR; return B_FILE_ERROR;
@@ -583,8 +587,7 @@ WriterLocker::AcquireWriter(bool dontBlock, int32 bytesNeeded)
ReaderLocker::ReaderLocker(tty_cookie *cookie) ReaderLocker::ReaderLocker(tty_cookie *cookie)
: : AbstractLocker(cookie),
AbstractLocker(cookie),
fTTY(cookie->tty), fTTY(cookie->tty),
fRequestOwner() fRequestOwner()
{ {
@@ -1219,7 +1222,7 @@ tty_write_to_tty(tty_cookie *sourceCookie, const void *buffer, size_t *_length,
// ToDo: "buffer" is not yet copied or accessed in a safe way! // ToDo: "buffer" is not yet copied or accessed in a safe way!
int32 bytesNeeded = 1; size_t bytesNeeded = 1;
while (bytesWritten < length) { while (bytesWritten < length) {
status_t status = locker.AcquireWriter(dontBlock, bytesNeeded); status_t status = locker.AcquireWriter(dontBlock, bytesNeeded);
+9 -9
View File
@@ -1,6 +1,6 @@
/* /*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License. * Distributed under the terms of the MIT License.
*/ */
#ifndef TTY_PRIVATE_H #ifndef TTY_PRIVATE_H
#define TTY_PRIVATE_H #define TTY_PRIVATE_H
@@ -37,11 +37,11 @@ class Request : public DoublyLinkedListLinkImpl<Request> {
public: public:
Request(); Request();
void Init(RequestOwner *owner, tty_cookie *cookie, int32 bytesNeeded); void Init(RequestOwner *owner, tty_cookie *cookie, size_t bytesNeeded);
tty_cookie *TTYCookie() const { return fCookie; } tty_cookie *TTYCookie() const { return fCookie; }
void Notify(int32 bytesAvailable); void Notify(size_t bytesAvailable);
void NotifyError(status_t error); void NotifyError(status_t error);
bool WasNotified() const { return fNotified; } bool WasNotified() const { return fNotified; }
@@ -50,7 +50,7 @@ public:
private: private:
RequestOwner *fOwner; RequestOwner *fOwner;
tty_cookie *fCookie; tty_cookie *fCookie;
int32 fBytesNeeded; size_t fBytesNeeded;
bool fNotified; bool fNotified;
bool fError; bool fError;
}; };
@@ -66,7 +66,7 @@ public:
Request *First() const { return fRequests.First(); } Request *First() const { return fRequests.First(); }
bool IsEmpty() const { return fRequests.IsEmpty(); } bool IsEmpty() const { return fRequests.IsEmpty(); }
void NotifyFirst(int32 bytesAvailable); void NotifyFirst(size_t bytesAvailable);
void NotifyError(status_t error); void NotifyError(status_t error);
void NotifyError(tty_cookie *cookie, status_t error); void NotifyError(tty_cookie *cookie, status_t error);
@@ -84,8 +84,8 @@ public:
RequestQueue *queue2 = NULL); RequestQueue *queue2 = NULL);
void Dequeue(); void Dequeue();
void SetBytesNeeded(int32 bytesNeeded); void SetBytesNeeded(size_t bytesNeeded);
int32 BytesNeeded() const { return fBytesNeeded; } size_t BytesNeeded() const { return fBytesNeeded; }
status_t Wait(bool interruptable, Semaphore *sem = NULL); status_t Wait(bool interruptable, Semaphore *sem = NULL);
@@ -102,7 +102,7 @@ private:
status_t fError; status_t fError;
RequestQueue *fRequestQueues[2]; RequestQueue *fRequestQueues[2];
Request fRequests[2]; Request fRequests[2];
int32 fBytesNeeded; size_t fBytesNeeded;
}; };