* Don't return the export thread id as error code in Export().

* Added WaitForExportThread() method.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41176 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2011-04-04 09:18:27 +00:00
parent 04a59db1ff
commit 1f3678c179
2 changed files with 33 additions and 26 deletions
@@ -1,11 +1,9 @@
/* /*
* Copyright 2006, Haiku. All rights reserved. * Copyright 2006, 2011, Stephan Aßmus <[email protected]>.
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/ */
#include "Exporter.h" #include "Exporter.h"
#include <fs_attr.h> #include <fs_attr.h>
@@ -33,7 +31,7 @@
using std::nothrow; using std::nothrow;
// constructor
Exporter::Exporter() Exporter::Exporter()
: fDocument(NULL), : fDocument(NULL),
fClonedIcon(NULL), fClonedIcon(NULL),
@@ -43,18 +41,15 @@ Exporter::Exporter()
{ {
} }
// destructor
Exporter::~Exporter() Exporter::~Exporter()
{ {
if (fExportThread >= 0 && find_thread(NULL) != fExportThread) { WaitForExportThread();
status_t ret;
wait_for_thread(fExportThread, &ret);
}
delete fClonedIcon; delete fClonedIcon;
} }
// Export
status_t status_t
Exporter::Export(Document* document, const entry_ref& ref) Exporter::Export(Document* document, const entry_ref& ref)
{ {
@@ -70,22 +65,36 @@ Exporter::Export(Document* document, const entry_ref& ref)
fExportThread = spawn_thread(_ExportThreadEntry, "export", fExportThread = spawn_thread(_ExportThreadEntry, "export",
B_NORMAL_PRIORITY, this); B_NORMAL_PRIORITY, this);
if (fExportThread >= B_OK) if (fExportThread < 0)
resume_thread(fExportThread); return (status_t)fExportThread;
return fExportThread; resume_thread(fExportThread);
return B_OK;
} }
// SetSelfDestroy
void void
Exporter::SetSelfDestroy(bool selfDestroy) Exporter::SetSelfDestroy(bool selfDestroy)
{ {
fSelfDestroy = selfDestroy; fSelfDestroy = selfDestroy;
} }
void
Exporter::WaitForExportThread()
{
if (fExportThread >= 0 && find_thread(NULL) != fExportThread) {
status_t ret;
wait_for_thread(fExportThread, &ret);
fExportThread = -1;
}
}
// #pragma mark - // #pragma mark -
// _ExportThreadEntry
int32 int32
Exporter::_ExportThreadEntry(void* cookie) Exporter::_ExportThreadEntry(void* cookie)
{ {
@@ -93,7 +102,7 @@ Exporter::_ExportThreadEntry(void* cookie)
return exporter->_ExportThread(); return exporter->_ExportThread();
} }
// _ExportThread
int32 int32
Exporter::_ExportThread() Exporter::_ExportThread()
{ {
@@ -132,10 +141,9 @@ Exporter::_ExportThread()
return ret; return ret;
} }
// _Export
status_t status_t
Exporter::_Export(const Icon* icon, Exporter::_Export(const Icon* icon, const entry_ref* docRef)
const entry_ref* docRef)
{ {
// TODO: reenable the commented out code, but make it work // TODO: reenable the commented out code, but make it work
// the opposite direction, ie *copy* the file contents // the opposite direction, ie *copy* the file contents
@@ -1,9 +1,6 @@
/* /*
* Copyright 2006-2007, Haiku. All rights reserved. * Copyright 2006, 2007, 2011, Stephan Aßmus <[email protected]>.
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/ */
#ifndef EXPORTER_H #ifndef EXPORTER_H
#define EXPORTER_H #define EXPORTER_H
@@ -41,6 +38,8 @@ class Exporter {
void SetSelfDestroy(bool selfDestroy); void SetSelfDestroy(bool selfDestroy);
void WaitForExportThread();
private: private:
static int32 _ExportThreadEntry(void* cookie); static int32 _ExportThreadEntry(void* cookie);
int32 _ExportThread(); int32 _ExportThread();