Commit graph

46 commits

Author SHA1 Message Date
Arttu Makinen 377aa989ab Updated to VTM6.1.
Done according to all #ifs enabled
2020-12-30 14:27:15 +02:00
Arttu Ylä-Outinen dc6b2024ea Modify reference count asserts to fix data races
Changes asserts on the reference count of objects to assert the value
after KVZ_ATOMIC_INC instead of directly checking the value. Fixes some
data races detected by TSan.
2018-06-12 09:35:07 +03:00
Ari Lemmetti 713e694d82 Define HAVE_STRUCT_TIMESPEC on Visual Studio 2015 and later
Fixes redefinition of timespec that Pthreads-Win32 does even if it has been already defined.
2017-12-05 18:26:12 +02:00
Arttu Ylä-Outinen 7144a00beb Rewrite thread queue
Changes thread queue so that only the jobs that are ready to run are
stored in the queue. Other jobs are kept track of by pointers in the
reverse dependency lists of other jobs. When a job is ready to run it is
appended to the queue. The job queue is stored as a linked list.

The definitions of threadqueue_queue_t and threadqueue_job_t are moved
to the .c file, turning them into opaque structs.

Makes thread queue code simpler. Fixes some TSan errors.
2017-08-11 14:18:12 +03:00
Arttu Ylä-Outinen bc47fe94af Drop thread queue debug code 2017-08-11 14:18:12 +03:00
Arttu Ylä-Outinen 4fc9b743c1 Drop an unnecessary pthread_cond_broadcast
Drop pthread_cond_broadcast on threadqueue->cond in function
kvz_threadqueue_waitfor. The broadcast caused threads to be woken up
more often than necessary.
2017-07-19 11:09:30 +03:00
Arttu Ylä-Outinen 2b169d5d63 Fix crash in kvazaar_close
Changes kvazaar_close to stop all threads before freeing encoder states.
Fixes a crash when the encoder is closed before all pictures have been
encoded.
2017-06-02 10:05:33 +03:00
Arttu Ylä-Outinen 5f8e17d4ba Eliminate a race condition in threadqueue
Fixes the order of acquiring locks for the job and its dependency in
kvz_threadqueue_job_dep_add. The dependency is locked before the job
that depends on it. This is the same order as in threadqueue_worker.

Acquiring the locks in different order in kvz_threadqueue_job_dep_add
and threadqueue_worker would sometimes result in a deadlock.
2017-05-18 12:25:53 +03:00
Arttu Ylä-Outinen 2991962033 Add reference counting to threadequeue_job_t
Both the thread queue and the encoder states hold pointers to the thread
queue jobs. It is possible that a job is removed from the thread queue
and freed while the encoder state is still using it. This commit adds
reference counting to threadqueue_job_t in order to fix the problem.

Fixes #161.
2017-04-12 16:13:52 +03:00
Arttu Ylä-Outinen a5a925fc28 Replace timed waits by normal waits in threadqueue
Replaces calls to pthread_cond_timedwait with pthread_cond_wait in
threadqueue.c. Simplifies code, as there should be no need for the
timeout.
2017-02-11 15:42:03 +09:00
Ari Koivula 61fc3e87ba Run include-what-you-use fix_includes.py fix_includes.py
The includes should make more sense now and not just happen to compile
due to headers included from other headers.

Used a modified version of IWYU. Modifications were to attribute int8_t
and so on to stdint.h instead of sys/types.h and immintrin.h instead of
more specific headers.

include-what-you-use 0.7 (git:b70df35)
based on clang version 3.9.0 (trunk 264728)
2016-04-01 17:46:55 +03:00
Ari Koivula 9139e169fe Fix unnecessary waiting in main thread
The main thread has to wait for the worker threads to finish. The
pthread_cond_timedwait call used to accomplish this was given
a relative instead of absolute time, which resulted in the call
returning immediately, because the time had already passed.

This removes the now unnecessary sleeps and fixes the time given to
the pthread_cond_timedwait such that it now waits until a job finishes
or 100ms have passed.
2016-03-23 22:23:04 +02:00
Ari Koivula 6f431e510c Comment and tidy threadqueue_worker
Carefully avoided making any changes to the logic.
2016-03-14 20:08:04 +02:00
Ari Koivula 93637f4683 Move macros in threads.h to KVZ_ namespace 2015-11-13 22:46:32 +02:00
Ari Koivula f1ac0e6bc2 Rename _DEBUG to KVZ_DEBUG 2015-09-15 13:04:03 +03:00
Ari Koivula ec2d8d6ad7 Rename _DEBUG_PERF macros to KVZ_PERF
And move them to threadqueue.h, where the things that use them are.
2015-09-15 13:03:32 +03:00
Ari Koivula 3958e8b6f7 Handle VS warnings with _DEBUG.
- Conditional expression is constant was being triggered by debug code.
2015-09-10 14:16:42 +03:00
Arttu Ylä-Outinen 3a10e9e3e0 Prefix all non-static symbols with "kvz_". 2015-08-26 13:02:28 +03:00
Ari Koivula cdb66baf16 Fix mutex being unlocked twice. 2015-06-01 16:28:50 +03:00
Ari Koivula 1c6c4963e7 Fix coverity warning.
- Mutex was left locked when malloc failed. Fixed.
2015-05-04 17:38:16 +03:00
Ari Koivula 3d135324da Rename struct threadqueue_queue to threadqueue_queue_t. 2015-03-04 16:30:20 +02:00
Ari Koivula b7fcb800b2 Rename struct threadqueue_job to threadqueue_job_t. 2015-03-04 16:28:56 +02:00
Ari Koivula d7383ccb25 Change license to LGPL.
- Everyone who has contributed code to the project has been asked to license
  their contributions under LPGL and they have agreed.

- COPYING file changed to say LGPLv2.1 instead of GPLv2.

- GPL changed to LGPL in the header of every single file that a header and
  header added to the few that were missing one.

- Also.. Happy new year!
2015-02-25 15:19:05 +02:00
Ari Koivula 5fa6438b25 Clean up calls to memset.
- Replaces all calls to memset with new FILL and FILL_ARRAY macros. The use
  of memset was inconsistent and we never use it for anything complicated.
2015-02-19 16:25:28 +02:00
Laurent Fasnacht 8502f3d850 Improve logging 2014-08-11 11:57:07 +02:00
Ari Koivula 5662621b3c Free threadqueue jobs when they are not needed.
- Also add destroying the mutex when the job is freed.

- This makes Kvazaar no longer acquire thousands of OS handles on Windows.
2014-07-16 16:51:20 +03:00
Laurent Fasnacht 28c3f22ba1 Fix possible freeze 2014-06-16 11:03:48 +02:00
Laurent Fasnacht 3be3fa8d6e Use different processing order depending if we have OWF or not 2014-06-16 10:54:56 +02:00
Laurent Fasnacht 4acadccf89 Only signal the required number of threads 2014-06-13 08:34:59 +02:00
Laurent Fasnacht 70ce7cec20 Remove unneccessary locks by adding threadqueue->queue_running counter 2014-06-13 08:34:58 +02:00
Laurent Fasnacht 7ef34ff5a1 Ability to dump mutex_lock, mutex_unlock and cond_wait timing, if compiled with -D_PTHREAD_DUMP 2014-06-13 08:32:14 +02:00
Laurent Fasnacht 68ad323e84 Tentative fix for race condition 2014-06-12 14:01:33 +02:00
Laurent Fasnacht b194e19708 Tentative fix for deadlock 2014-06-12 12:57:14 +02:00
Laurent Fasnacht 7372f9244d Basic infrastructure for OWF 2014-06-05 09:09:25 +02:00
Laurent Fasnacht 9bdecbe071 Better thread scheduling 2014-06-03 11:39:16 +02:00
Laurent Fasnacht 0811dbcfbe Remove unneeded cond_broadcast. Limit contention 2014-06-03 09:45:17 +02:00
Laurent Fasnacht 3a30a886fc FREE_POINTER of job->rdepends was at the wrong place (memory leak) 2014-05-22 07:15:18 +02:00
Laurent Fasnacht 90f46dc56f Threadqueue has now a start index to the first queue job. It improves the speed a little 2014-05-21 12:02:55 +02:00
Laurent Fasnacht 6fdb821b14 Fix memory leaks 2014-05-16 12:20:40 +02:00
Laurent Fasnacht 36945e89ce Stubs to be able to make a portable version of the profiling 2014-05-16 10:15:05 +02:00
Laurent Fasnacht 53b0835316 Improve handling of jobs when not using threads 2014-05-16 08:50:43 +02:00
Laurent Fasnacht 7473ac1bfc Able to log time in a simple way 2014-05-16 08:50:42 +02:00
Laurent Fasnacht 4f73a7fc91 Instrument threads in order to be able to do some visualization 2014-05-16 08:44:32 +02:00
Laurent Fasnacht 38444a81a6 Threads should be put in queue in wait state if we want to add dependencies later 2014-05-14 14:01:25 +02:00
Laurent Fasnacht d4a303e7e6 Free jobs as soon as possible 2014-05-14 13:27:09 +02:00
Laurent Fasnacht baede7f6c4 threadqueue 2014-05-14 13:27:08 +02:00