summaryrefslogtreecommitdiff
path: root/src/preview/PreviewModel.cpp
diff options
context:
space:
mode:
authorcracker64 <cracker642@gmail.com>2013-03-10 06:47:09 (GMT)
committer cracker64 <cracker642@gmail.com>2013-03-10 06:47:09 (GMT)
commit5aa233d4e7ec0f87b59572d44b4e90cda2bb6272 (patch)
tree59a4c51dcd49e2b03a6b84b203a2859b33975a4a /src/preview/PreviewModel.cpp
parent3abc33fd3b8bfaa720202ad2e4d5c46b9d51e9d7 (diff)
downloadpowder-5aa233d4e7ec0f87b59572d44b4e90cda2bb6272.zip
powder-5aa233d4e7ec0f87b59572d44b4e90cda2bb6272.tar.gz
Use cancels instead of pthread_getattr_np for compatibility.
Stopping the download would be nice, it still goes in the background.
Diffstat (limited to 'src/preview/PreviewModel.cpp')
-rw-r--r--src/preview/PreviewModel.cpp103
1 files changed, 49 insertions, 54 deletions
diff --git a/src/preview/PreviewModel.cpp b/src/preview/PreviewModel.cpp
index b25d084..8d608cf 100644
--- a/src/preview/PreviewModel.cpp
+++ b/src/preview/PreviewModel.cpp
@@ -36,65 +36,63 @@ 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()
{
- int check;
- pthread_attr_t attr;
- SaveInfo * tempSave = Client::Ref().GetSave(tSaveID, tSaveDate);
- pthread_getattr_np(pthread_self(), &attr);
- pthread_attr_getdetachstate(&attr,&check);
- pthread_attr_destroy(&attr);
- if (check==PTHREAD_CREATE_JOINABLE)
- {
- updateSaveInfoFinished = true;
- return tempSave;
- } else
- {
- if (tempSave) delete tempSave;
- }
- return NULL;
+ 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, check;
- pthread_attr_t attr;
- unsigned char * tempData = Client::Ref().GetSaveData(tSaveID, tSaveDate, tempDataSize);
- pthread_getattr_np(pthread_self(), &attr);
- pthread_attr_getdetachstate(&attr,&check);
- pthread_attr_destroy(&attr);
- if (check==PTHREAD_CREATE_JOINABLE)
- {
- saveDataBuffer.clear();
- if (tempData)
- saveDataBuffer.insert(saveDataBuffer.begin(), tempData, tempData+tempDataSize);
- updateSaveDataFinished = true;
- }
- if (tempData) free(tempData);
-
+ int 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()
{
- int check;
- pthread_attr_t attr;
- std::vector<SaveComment*> * tempComments = Client::Ref().GetComments(tSaveID, (commentsPageNumber-1)*20, 20);
- pthread_getattr_np(pthread_self(), &attr);
- pthread_attr_getdetachstate(&attr,&check);
- pthread_attr_destroy(&attr);
- if (check==PTHREAD_CREATE_JOINABLE)
- {
- updateSaveCommentsFinished = true;
- return tempComments;
- } else
- {
- for(int i = 0; i < tempComments->size(); i++)
- delete tempComments->at(i);
- tempComments->clear();
- delete tempComments;
- }
- return NULL;
+ 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;
}
void PreviewModel::SetFavourite(bool favourite)
@@ -345,12 +343,9 @@ void PreviewModel::Update()
}
PreviewModel::~PreviewModel() {
- //pthread_join(updateSaveDataThread, NULL);
- //pthread_join(updateSaveInfoThread, NULL);
- //pthread_join(updateSaveCommentsThread, NULL);
- if (updateSaveDataWorking) pthread_detach(updateSaveDataThread);
- if (updateSaveInfoWorking) pthread_detach(updateSaveInfoThread);
- if (updateSaveCommentsWorking) pthread_detach(updateSaveCommentsThread);
+ pthread_cancel(updateSaveDataThread);
+ pthread_cancel(updateSaveInfoThread);
+ pthread_cancel(updateSaveCommentsThread);
if(save)
delete save;
if(saveComments)