diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-12 21:21:01 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-12 21:21:01 (GMT) |
| commit | de680a1e5cd65c771a9ed659510fb48b2916a5f0 (patch) | |
| tree | 660919b656177aa469d4dc17571e9b7dfcc7d4a2 /src/preview/PreviewModel.cpp | |
| parent | 86b7a118004c9f9797d4d898dd587000e5178cea (diff) | |
| parent | 134d1fab10a713ce0e99bfc3325b099abcbbe591 (diff) | |
| download | powder-de680a1e5cd65c771a9ed659510fb48b2916a5f0.zip powder-de680a1e5cd65c771a9ed659510fb48b2916a5f0.tar.gz | |
Merge
Diffstat (limited to 'src/preview/PreviewModel.cpp')
| -rw-r--r-- | src/preview/PreviewModel.cpp | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/src/preview/PreviewModel.cpp b/src/preview/PreviewModel.cpp index 8a0ff59..8d608cf 100644 --- a/src/preview/PreviewModel.cpp +++ b/src/preview/PreviewModel.cpp @@ -36,28 +36,62 @@ void * PreviewModel::updateSaveCommentsTHelper(void * obj) return ((PreviewModel*)obj)->updateSaveCommentsT(); } +void PreviewModel::updateSaveInfoTDelete(void * arg) +{ + delete arg; +} +void PreviewModel::updateSaveDataTDelete(void * arg) +{ + free(arg); +} +void PreviewModel::updateSaveCommentsTDelete(void * arg) +{ + for(int i = 0; i < ((std::vector<SaveComment*> *)arg)->size(); i++) + delete ((std::vector<SaveComment*> *)arg)->at(i); + ((std::vector<SaveComment*> *)arg)->clear(); + delete arg; +} + void * PreviewModel::updateSaveInfoT() { - SaveInfo * tempSave = Client::Ref().GetSave(tSaveID, tSaveDate); + SaveInfo * tempSave; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL); + tempSave = Client::Ref().GetSave(tSaveID, tSaveDate); + pthread_cleanup_push(&updateSaveInfoTDelete,tempSave); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL); + pthread_testcancel(); updateSaveInfoFinished = true; + pthread_cleanup_pop(0); return tempSave; } void * PreviewModel::updateSaveDataT() { int tempDataSize; - unsigned char * tempData = Client::Ref().GetSaveData(tSaveID, tSaveDate, tempDataSize); + unsigned char * tempData; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL); + tempData = Client::Ref().GetSaveData(tSaveID, tSaveDate, tempDataSize); + pthread_cleanup_push(&updateSaveDataTDelete,tempData); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL); + pthread_testcancel(); saveDataBuffer.clear(); if (tempData) saveDataBuffer.insert(saveDataBuffer.begin(), tempData, tempData+tempDataSize); updateSaveDataFinished = true; + pthread_cleanup_pop(1); return NULL; } void * PreviewModel::updateSaveCommentsT() { - std::vector<SaveComment*> * tempComments = Client::Ref().GetComments(tSaveID, (commentsPageNumber-1)*20, 20); + std::vector<SaveComment*> * tempComments; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL); + tempComments = Client::Ref().GetComments(tSaveID, (commentsPageNumber-1)*20, 20); + pthread_cleanup_push(&updateSaveCommentsTDelete,tempComments); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL); + pthread_testcancel(); updateSaveCommentsFinished = true; + pthread_cleanup_pop(0); return tempComments; } @@ -101,6 +135,7 @@ void PreviewModel::UpdateSave(int saveID, int saveDate) for(int i = 0; i < saveComments->size(); i++) delete saveComments->at(i); saveComments->clear(); + delete saveComments; saveComments = NULL; } notifySaveChanged(); @@ -166,6 +201,7 @@ void PreviewModel::UpdateComments(int pageNumber) { for(int i = 0; i < saveComments->size(); i++) delete saveComments->at(i); + saveComments->clear(); delete saveComments; saveComments = NULL; } @@ -307,6 +343,9 @@ void PreviewModel::Update() } PreviewModel::~PreviewModel() { + pthread_cancel(updateSaveDataThread); + pthread_cancel(updateSaveInfoThread); + pthread_cancel(updateSaveCommentsThread); if(save) delete save; if(saveComments) @@ -314,6 +353,7 @@ PreviewModel::~PreviewModel() { for(int i = 0; i < saveComments->size(); i++) delete saveComments->at(i); saveComments->clear(); + delete saveComments; } saveDataBuffer.clear(); } |
