Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/Thread.cpp

Issue 29498570: Issue #4711 - remove lagacy Thread and Mutex classes (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created July 26, 2017, 2:39 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/Thread.h ('k') | test/Thread.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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
(...skipping 12 matching lines...) Expand all
23 23
24 using namespace AdblockPlus; 24 using namespace AdblockPlus;
25 25
26 void AdblockPlus::Sleep(int millis) 26 void AdblockPlus::Sleep(int millis)
27 { 27 {
28 #ifdef WIN32 28 #ifdef WIN32
29 ::Sleep(millis); 29 ::Sleep(millis);
30 #else 30 #else
31 usleep(millis * 1000); 31 usleep(millis * 1000);
32 #endif 32 #endif
33 } 33 }
34
35 Mutex::Mutex()
36 {
37 #ifdef WIN32
38 InitializeCriticalSection(&nativeMutex);
39 #else
40 pthread_mutex_init(&nativeMutex, 0);
41 #endif
42 }
43
44 Mutex::~Mutex()
45 {
46 #ifdef WIN32
47 DeleteCriticalSection(&nativeMutex);
48 #else
49 pthread_mutex_destroy(&nativeMutex);
50 #endif
51 }
52
53 void Mutex::Lock()
54 {
55 #ifdef WIN32
56 EnterCriticalSection(&nativeMutex);
57 #else
58 pthread_mutex_lock(&nativeMutex);
59 #endif
60 }
61
62 void Mutex::Unlock()
63 {
64 #ifdef WIN32
65 LeaveCriticalSection(&nativeMutex);
66 #else
67 pthread_mutex_unlock(&nativeMutex);
68 #endif
69 }
70
71 Lock::Lock(Mutex& mutex) : mutex(mutex)
72 {
73 mutex.Lock();
74 }
75
76 Lock::~Lock()
77 {
78 mutex.Unlock();
79 }
80
81 Thread::Thread(bool deleteSelfOnFinish)
82 : m_deleteSelfOnFinish(deleteSelfOnFinish)
83 {
84 }
85
86 Thread::~Thread()
87 {
88 }
89
90 void Thread::Start()
91 {
92 #ifdef WIN32
93 nativeThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&CallRun, this, 0, 0 );
94 #else
95 pthread_create(&nativeThread, 0, (void* (*)(void*)) &CallRun, this);
96 #endif
97 }
98
99 void Thread::Join()
100 {
101 #ifdef WIN32
102 WaitForSingleObject(nativeThread, INFINITE);
103 #else
104 pthread_join(nativeThread, 0);
105 #endif
106 }
107
108 void Thread::CallRun(Thread* thread)
109 {
110 thread->Run();
111 if (thread->m_deleteSelfOnFinish)
112 delete thread;
113 }
OLDNEW
« no previous file with comments | « src/Thread.h ('k') | test/Thread.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld