| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #ifndef WIN32 | 18 #ifndef WIN32 |
| 19 #include <unistd.h> | 19 #include <unistd.h> |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 #include "Thread.h" | 22 #include "Thread.h" |
| 23 | 23 |
| 24 using namespace AdblockPlus; | 24 using namespace AdblockPlus; |
| 25 | 25 |
| 26 namespace | |
| 27 { | |
| 28 void CallRun(Thread* thread) | |
| 29 { | |
| 30 thread->Run(); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 void AdblockPlus::Sleep(const int millis) | 26 void AdblockPlus::Sleep(const int millis) |
| 35 { | 27 { |
| 36 #ifdef WIN32 | 28 #ifdef WIN32 |
| 37 ::Sleep(millis); | 29 ::Sleep(millis); |
| 38 #else | 30 #else |
| 39 usleep(millis * 1000); | 31 usleep(millis * 1000); |
| 40 #endif | 32 #endif |
| 41 } | 33 } |
| 42 | 34 |
| 43 Mutex::Mutex() | 35 Mutex::Mutex() |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 Lock::Lock(Mutex& mutex) : mutex(mutex) | 71 Lock::Lock(Mutex& mutex) : mutex(mutex) |
| 80 { | 72 { |
| 81 mutex.Lock(); | 73 mutex.Lock(); |
| 82 } | 74 } |
| 83 | 75 |
| 84 Lock::~Lock() | 76 Lock::~Lock() |
| 85 { | 77 { |
| 86 mutex.Unlock(); | 78 mutex.Unlock(); |
| 87 } | 79 } |
| 88 | 80 |
| 81 Thread::Thread(bool deleteSelfOnFinish) | |
| 82 : m_deleteSelfOnFinish(deleteSelfOnFinish) | |
|
Oleksandr
2016/11/07 10:31:31
Do we have a case where we would not want to delet
sergei
2016/11/07 13:04:12
Yes, we have it already in tests, in those cases T
| |
| 83 { | |
| 84 } | |
| 85 | |
| 89 Thread::~Thread() | 86 Thread::~Thread() |
| 90 { | 87 { |
| 91 } | 88 } |
| 92 | 89 |
| 93 void Thread::Start() | 90 void Thread::Start() |
|
Oleksandr
2016/11/07 10:31:31
How about renaming this to something like 'LaunchA
sergei
2016/11/07 13:04:12
No, because it won't be always destroyed.
| |
| 94 { | 91 { |
| 95 #ifdef WIN32 | 92 #ifdef WIN32 |
| 96 nativeThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&CallRun, this, 0, 0 ); | 93 nativeThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&CallRun, this, 0, 0 ); |
| 97 #else | 94 #else |
| 98 pthread_create(&nativeThread, 0, (void* (*)(void*)) &CallRun, this); | 95 pthread_create(&nativeThread, 0, (void* (*)(void*)) &CallRun, this); |
| 99 #endif | 96 #endif |
| 100 } | 97 } |
| 101 | 98 |
| 102 void Thread::Join() | 99 void Thread::Join() |
| 103 { | 100 { |
| 104 #ifdef WIN32 | 101 #ifdef WIN32 |
| 105 WaitForSingleObject(nativeThread, INFINITE); | 102 WaitForSingleObject(nativeThread, INFINITE); |
| 106 #else | 103 #else |
| 107 pthread_join(nativeThread, 0); | 104 pthread_join(nativeThread, 0); |
| 108 #endif | 105 #endif |
| 109 } | 106 } |
| 107 | |
| 108 void Thread::CallRun(Thread* thread) | |
| 109 { | |
| 110 thread->Run(); | |
| 111 if (thread->m_deleteSelfOnFinish) | |
|
sergei
2016/11/07 13:04:12
BTW, this code is pretty dangerous because it's ve
| |
| 112 delete thread; | |
| 113 } | |
| OLD | NEW |