* Fixed GCC 4 build and warnings.
* Used std::vector in BlockingQueue instead of Ingo's Vector until I can figure out the GCC4 problems. This is untested, but I will test this on another machine in a minute. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30423 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -33,7 +33,9 @@
|
|||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
|
|
||||||
#include "AutoLocker.h"
|
#include "AutoLocker.h"
|
||||||
#include "Vector.h"
|
#include <vector>
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
typedef BLocker Locker;
|
typedef BLocker Locker;
|
||||||
|
|
||||||
@@ -46,7 +48,7 @@ public:
|
|||||||
status_t InitCheck() const;
|
status_t InitCheck() const;
|
||||||
|
|
||||||
status_t Close(bool deleteElements,
|
status_t Close(bool deleteElements,
|
||||||
const Vector<Element*>** elements = NULL);
|
const vector<Element*>** elements = NULL);
|
||||||
|
|
||||||
status_t Push(Element* element);
|
status_t Push(Element* element);
|
||||||
status_t Pop(Element** element,
|
status_t Pop(Element** element,
|
||||||
@@ -57,7 +59,7 @@ public:
|
|||||||
int32 Size();
|
int32 Size();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Element*> fElements;
|
vector<Element*> fElements;
|
||||||
sem_id fElementSemaphore;
|
sem_id fElementSemaphore;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -90,7 +92,7 @@ BlockingQueue<Element>::InitCheck() const
|
|||||||
template<typename Element>
|
template<typename Element>
|
||||||
status_t
|
status_t
|
||||||
BlockingQueue<Element>::Close(bool deleteElements,
|
BlockingQueue<Element>::Close(bool deleteElements,
|
||||||
const Vector<Element*>** elements)
|
const vector<Element*>** elements)
|
||||||
{
|
{
|
||||||
AutoLocker<Locker> _(this);
|
AutoLocker<Locker> _(this);
|
||||||
status_t error = delete_sem(fElementSemaphore);
|
status_t error = delete_sem(fElementSemaphore);
|
||||||
@@ -100,9 +102,9 @@ BlockingQueue<Element>::Close(bool deleteElements,
|
|||||||
if (elements)
|
if (elements)
|
||||||
*elements = &fElements;
|
*elements = &fElements;
|
||||||
if (deleteElements) {
|
if (deleteElements) {
|
||||||
int32 count = fElements.Count();
|
int32 count = fElements.size();
|
||||||
for (int32 i = 0; i < count; i++)
|
for (int32 i = 0; i < count; i++)
|
||||||
delete fElements.ElementAt(i);
|
delete fElements[i];
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -115,12 +117,14 @@ BlockingQueue<Element>::Push(Element* element)
|
|||||||
AutoLocker<Locker> _(this);
|
AutoLocker<Locker> _(this);
|
||||||
if (fElementSemaphore < 0)
|
if (fElementSemaphore < 0)
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
status_t error = fElements.PushBack(element);
|
try {
|
||||||
|
fElements.push_back(element);
|
||||||
|
} catch (std::bad_alloc) {
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
status_t error = release_sem(fElementSemaphore);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
fElements.erase(fElements.begin() + fElements.size() - 1);
|
||||||
error = release_sem(fElementSemaphore);
|
|
||||||
if (error != B_OK)
|
|
||||||
fElements.Erase(fElements.Count() - 1);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,11 +140,11 @@ BlockingQueue<Element>::Pop(Element** element, bigtime_t timeout)
|
|||||||
AutoLocker<Locker> _(this);
|
AutoLocker<Locker> _(this);
|
||||||
if (fElementSemaphore < 0)
|
if (fElementSemaphore < 0)
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
int32 count = fElements.Count();
|
int32 count = fElements.size();
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
*element = fElements.ElementAt(0);
|
*element = fElements[0];
|
||||||
fElements.Erase(0);
|
fElements.erase(fElements.begin());
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,10 +156,10 @@ BlockingQueue<Element>::Peek(Element** element)
|
|||||||
AutoLocker<Locker> _(this);
|
AutoLocker<Locker> _(this);
|
||||||
if (fElementSemaphore < 0)
|
if (fElementSemaphore < 0)
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
int32 count = fElements.Count();
|
int32 count = fElements.size();
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
*element = fElements.ElementAt(0);
|
*element = fElements[0];
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,15 +175,24 @@ BlockingQueue<Element>::Remove(Element* element)
|
|||||||
AutoLocker<Locker> _(this);
|
AutoLocker<Locker> _(this);
|
||||||
if (fElementSemaphore < 0)
|
if (fElementSemaphore < 0)
|
||||||
return B_NO_INIT;
|
return B_NO_INIT;
|
||||||
int32 count = fElements.Remove(element);
|
|
||||||
|
int32 count = 0;
|
||||||
|
for (int32 i = fElements.size() - 1; i >= 0; i--) {
|
||||||
|
if (fElements[i] == element) {
|
||||||
|
fElements.erase(fElements.begin() + i);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
release_sem(fElementSemaphore);
|
release_sem(fElementSemaphore);
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
ERROR(("ERROR: BlockingQueue::Remove(): Removed %ld elements!\n",
|
ERROR(("ERROR: BlockingQueue::Remove(): Removed %ld elements!\n",
|
||||||
count));
|
count));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +202,7 @@ int32
|
|||||||
BlockingQueue<Element>::Size()
|
BlockingQueue<Element>::Size()
|
||||||
{
|
{
|
||||||
AutoLocker<Locker> _(this);
|
AutoLocker<Locker> _(this);
|
||||||
return (fElements.Count());
|
return (fElements.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // BLOCKING_QUEUE_H
|
#endif // BLOCKING_QUEUE_H
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ CopyEngine::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CopyEngine::SetStatusMessage(char *status)
|
CopyEngine::SetStatusMessage(const char *status)
|
||||||
{
|
{
|
||||||
BMessage msg(STATUS_MESSAGE);
|
BMessage msg(STATUS_MESSAGE);
|
||||||
msg.AddString("status", status);
|
msg.AddString("status", status);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class CopyEngine : public BLooper {
|
|||||||
private:
|
private:
|
||||||
void LaunchInitScript(BPath &path);
|
void LaunchInitScript(BPath &path);
|
||||||
void LaunchFinishScript(BPath &path);
|
void LaunchFinishScript(BPath &path);
|
||||||
void SetStatusMessage(char *status);
|
void SetStatusMessage(const char *status);
|
||||||
void Start(BMenu *srcMenu, BMenu *targetMenu);
|
void Start(BMenu *srcMenu, BMenu *targetMenu);
|
||||||
status_t CopyFolder(BDirectory &srcDir, BDirectory &targetDir);
|
status_t CopyFolder(BDirectory &srcDir, BDirectory &targetDir);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#define COPY_ENGINE_2_H
|
#define COPY_ENGINE_2_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user