Commit Graph

10 Commits

Author SHA1 Message Date
OGAWA Hirofumi
b8dcb5f706 Don't polling to wait the exit of threads in CThreadPool destructor
All values are protected by m_mutex. So we don't need the polling to
wait m_num_threads==0 with wakeups, instead simply use CConditionVariable.
2015-01-25 21:55:42 +09:00
Falk Seidel
2e29d49a53 Welcome to 2015 2014-12-31 11:28:38 +01:00
Uli Schlachter
e0e86e8b02 CThreadPool::cancelJobs(): Add a comment explaining the logic a bit
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-08-11 09:09:38 +02:00
Uli Schlachter
74fdd97a52 CJob: Even cancel finished jobs
When a job was cancelled after its runThread() method finished, but before the
main thread noticed this and reacted, we would just run runMain() before and
pretend the job finished normally.

However, with CModuleJob this means that runMain() might get called for a module
which is currently being destructed. This has bad effects with virtual functions
and thus causes problems. It's better to just really cancel the job instead.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-08-11 09:09:38 +02:00
Uli Schlachter
0fddbba230 CThreadPool: Fix a race when starting threads
There was a race where threads were themselves responsible for increasing the
counter for the number of running threads. This left an open window where the
thread was already started, but our counter was not yet increased. The effect of
this race would be that we start more threads than we should.

Fix this by increasing the counter before actually starting new worker threads.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-08-06 15:20:12 +02:00
Uli Schlachter
1d67e87d90 CThreadPool: Add cancellation support
This adds CThreadPool::cancelJob() and cancelJobs() which can cancel a set of
jobs synchronously. These functions only return when the job was successfully
cancelled.

It tries to cancel the jobs as quickly as possible, skipping any callbacks on
CJob that were not yet called. A job that is already running can use
CJob::wasCancelled() to check if it should quit.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-08-06 15:15:57 +02:00
Falk Seidel
f19b4caa43 Welcome to 2014 - year 10 with ZNC 2013-12-31 10:10:55 +01:00
Alexey Sokolov
b2dcad5fd4 Change ZNC license to Apache 2.0
The following people agreed with the change, in alphabetical order:
(people who approved in several ways are listed only once)
By email:
- Adam (from Anope)
- Austin Morton
- Brian Campbell
- Christian Walde
- Daniel Holbert
- Daniel Wallace
- Falk Seidel
- Heiko Hund
- Ingmar Runge
- Jim Hull
- Kyle Fuller
- Lee Aylward
- Martin Martimeo
- Matt Harper
- Michael J Edgar
- Michael Ziegler
- Nick Bebout
- Paul Driver
- Perry Nguyen
- Philippe (cycomate)
- Reuben Morais
- Roland Hieber
- Sebastian Ramacher
- Stefan Rado
- Stéphan Kochen
- Thomas Ward
- Toon Schoenmakers
- Veit Wahlich
- Wulf C. Krueger

By IRC:
- CNU
- Jonas Gorski
- Joshua M. Clulow
- Prozac/SHiZNO
- SilverLeo
- Uli Schlachter

At https://github.com/znc/znc/issues/311 :
- Alexey Sokolov
- Elizabeth Myers
- flakes
- Jens-Andre Koch
- Jyzee
- KindOne/ineedalifetoday
- Lee Williams
- Mantas Mikulėnas
- md-5
- Reed Loden

At the last few pull requests' comments:
- Allan Odgaard
- Jacob Baines
- Lluís Batlle i Rossell
- ravomavain
- protomouse

The following commits' authors didn't respond:
Trivial changes:
- f70f1086fd
- 4ca8b50e45

The changes which are not presented in master anymore:
- 5512ed2ea0
- 960a4498f7
- 0f739de2c0
- 7f53cc810b

Fix #311
Fix #218
2013-06-14 00:43:34 +04:00
Uli Schlachter
53c579b296 CJob: Add a way to do stuff on the main thread
This just moves the pipe from the socket code to the thread pool. However, now
all CJobs can use this and there is a single place for them to get deleted.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2013-03-15 11:58:27 +01:00
Uli Schlachter
75f2e3fa41 Add a generic threads abstraction
This should make it easier to work with threads. It provides classes for mutexes
and condition variables. Additionally, there is a special CMutexGuard that
automatically unlocks the mutex on destruction and a CThreadPool class.

This thread pool is used to replace the thread pool in the sockets code.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2013-03-15 11:58:22 +01:00