Skip to content

Commit 8cf26c1

Browse files
committed
Backport thread-related changes from libaom.
This ports changes that touched aom_thread.[c,h] from the time after libaom copied libvpx' sources, where they hadn't already been present. The goal here is to unify the two repos' thread implementations in hopes of ultimately sharing one. The list of commits is approximately as follows; however, I made a few other changes as necessary where noted. https://aomedia-review.googlesource.com/c/aom/+/64044 Edited other hook func return values similarly. https://aomedia-review.googlesource.com/c/aom/+/71321 https://aomedia-review.googlesource.com/c/aom/+/71327 https://aomedia-review.googlesource.com/c/aom/+/71436 https://aomedia-review.googlesource.com/c/aom/+/72481 Also removed conflicting MAX_NUM_THREADS definition of 80. I think this was incorrect as the relevant array was indexed by variables that were in turn controlled by the global config values that were clamped to <=64. https://aomedia-review.googlesource.com/c/aom/+/102621 Also removed a pre-XP handling block in vp8/common/generic/systemdependent.c. https://aomedia-review.googlesource.com/c/aom/+/102601 MAX_DECODE_THREADS was the only relevant piece. https://aomedia-review.googlesource.com/c/aom/+/102741 https://aomedia-review.googlesource.com/c/aom/+/109025 https://aomedia-review.googlesource.com/c/aom/+/160961 https://aomedia-review.googlesource.com/c/aom/+/169684 Also removed OS/2 support from elsewhere. https://aomedia-review.googlesource.com/c/aom/+/169823 https://aomedia-review.googlesource.com/c/aom/+/170022 https://aomedia-review.googlesource.com/c/aom/+/169685 https://aomedia-review.googlesource.com/c/aom/+/173761 https://aomedia-review.googlesource.com/c/aom/+/174842 Bug: none Change-Id: I91462873a57e9efa120288d1bd8af3a6c09d423d
1 parent 491c16a commit 8cf26c1

13 files changed

+87
-400
lines changed

test/frame_size_tests.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ TEST_F(VP9FrameSizeTestsLarge, ValidSizes) {
193193
// size or almost 1 gig of memory.
194194
// In total the allocations will exceed 2GiB which may cause a failure with
195195
// mingw + wine, use a smaller size in that case.
196-
#if defined(_WIN32) && !defined(_WIN64) || defined(__OS2__)
196+
#if defined(_WIN32) && !defined(_WIN64)
197197
video.SetSize(4096, 3072);
198198
#else
199199
video.SetSize(4096, 4096);

tools_common.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,9 @@
2626

2727
#include "vpx/vpx_codec.h"
2828

29-
#if defined(_WIN32) || defined(__OS2__)
29+
#if defined(_WIN32)
3030
#include <io.h>
3131
#include <fcntl.h>
32-
33-
#ifdef __OS2__
34-
#define _setmode setmode
35-
#define _fileno fileno
36-
#define _O_BINARY O_BINARY
37-
#endif
3832
#endif
3933

4034
#define LOG_ERROR(label) \
@@ -58,7 +52,7 @@ static size_t wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) {
5852

5953
FILE *set_binary_mode(FILE *stream) {
6054
(void)stream;
61-
#if defined(_WIN32) || defined(__OS2__)
55+
#if defined(_WIN32)
6256
_setmode(_fileno(stream), _O_BINARY);
6357
#endif
6458
return stream;

vp8/common/generic/systemdependent.c

+5-34
Original file line numberDiff line numberDiff line change
@@ -25,62 +25,33 @@
2525
#include "vp8/common/systemdependent.h"
2626

2727
#if CONFIG_MULTITHREAD
28-
#if HAVE_UNISTD_H && !defined(__OS2__)
28+
#if HAVE_UNISTD_H
2929
#include <unistd.h>
3030
#elif defined(_WIN32)
3131
#include <windows.h>
3232
typedef void(WINAPI *PGNSI)(LPSYSTEM_INFO);
33-
#elif defined(__OS2__)
34-
#define INCL_DOS
35-
#define INCL_DOSSPINLOCK
36-
#include <os2.h>
3733
#endif
3834
#endif
3935

4036
#if CONFIG_MULTITHREAD
4137
static int get_cpu_count() {
4238
int core_count = 16;
4339

44-
#if HAVE_UNISTD_H && !defined(__OS2__)
40+
#if HAVE_UNISTD_H
4541
#if defined(_SC_NPROCESSORS_ONLN)
4642
core_count = (int)sysconf(_SC_NPROCESSORS_ONLN);
4743
#elif defined(_SC_NPROC_ONLN)
4844
core_count = (int)sysconf(_SC_NPROC_ONLN);
4945
#endif
5046
#elif defined(_WIN32)
5147
{
52-
#if _WIN32_WINNT >= 0x0501
48+
#if _WIN32_WINNT < 0x0501
49+
#error _WIN32_WINNT must target Windows XP or newer.
50+
#endif
5351
SYSTEM_INFO sysinfo;
5452
GetNativeSystemInfo(&sysinfo);
55-
#else
56-
PGNSI pGNSI;
57-
SYSTEM_INFO sysinfo;
58-
59-
/* Call GetNativeSystemInfo if supported or
60-
* GetSystemInfo otherwise. */
61-
62-
pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")),
63-
"GetNativeSystemInfo");
64-
if (pGNSI != NULL)
65-
pGNSI(&sysinfo);
66-
else
67-
GetSystemInfo(&sysinfo);
68-
#endif
69-
7053
core_count = (int)sysinfo.dwNumberOfProcessors;
7154
}
72-
#elif defined(__OS2__)
73-
{
74-
ULONG proc_id;
75-
ULONG status;
76-
77-
core_count = 0;
78-
for (proc_id = 1;; ++proc_id) {
79-
if (DosGetProcessorStatus(proc_id, &status)) break;
80-
81-
if (status == PROC_ONLINE) core_count++;
82-
}
83-
}
8455
#else
8556
/* other platforms */
8657
#endif

vp8/common/threading.h

-83
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ extern "C" {
3434
#define THREAD_FUNCTION_RETURN DWORD
3535
#define THREAD_SPECIFIC_INDEX DWORD
3636
#define pthread_t HANDLE
37-
#define pthread_attr_t DWORD
3837
#define pthread_detach(thread) \
3938
if (thread != NULL) CloseHandle(thread)
4039
#define thread_sleep(nms) Sleep(nms)
@@ -45,25 +44,6 @@ extern "C" {
4544
#define pthread_setspecific(ts_key, value) TlsSetValue(ts_key, (void *)value)
4645
#define pthread_self() GetCurrentThreadId()
4746

48-
#elif defined(__OS2__)
49-
/* OS/2 */
50-
#define INCL_DOS
51-
#include <os2.h>
52-
53-
#include <stdlib.h>
54-
#define THREAD_FUNCTION void *
55-
#define THREAD_FUNCTION_RETURN void *
56-
#define THREAD_SPECIFIC_INDEX PULONG
57-
#define pthread_t TID
58-
#define pthread_attr_t ULONG
59-
#define pthread_detach(thread) 0
60-
#define thread_sleep(nms) DosSleep(nms)
61-
#define pthread_cancel(thread) DosKillThread(thread)
62-
#define ts_key_create(ts_key, destructor) \
63-
DosAllocThreadLocalMemory(1, &(ts_key));
64-
#define pthread_getspecific(ts_key) ((void *)(*(ts_key)))
65-
#define pthread_setspecific(ts_key, value) (*(ts_key) = (ULONG)(value))
66-
#define pthread_self() _gettid()
6747
#else
6848
#ifdef __APPLE__
6949
#include <mach/mach_init.h>
@@ -99,69 +79,6 @@ extern "C" {
9979
if (*sem) ((int)(CloseHandle(*sem)) == TRUE)
10080
#define thread_sleep(nms) Sleep(nms)
10181

102-
#elif defined(__OS2__)
103-
typedef struct {
104-
HEV event;
105-
HMTX wait_mutex;
106-
HMTX count_mutex;
107-
int count;
108-
} sem_t;
109-
110-
static inline int sem_init(sem_t *sem, int pshared, unsigned int value) {
111-
DosCreateEventSem(NULL, &sem->event, pshared ? DC_SEM_SHARED : 0,
112-
value > 0 ? TRUE : FALSE);
113-
DosCreateMutexSem(NULL, &sem->wait_mutex, 0, FALSE);
114-
DosCreateMutexSem(NULL, &sem->count_mutex, 0, FALSE);
115-
116-
sem->count = value;
117-
118-
return 0;
119-
}
120-
121-
static inline int sem_wait(sem_t *sem) {
122-
DosRequestMutexSem(sem->wait_mutex, -1);
123-
124-
DosWaitEventSem(sem->event, -1);
125-
126-
DosRequestMutexSem(sem->count_mutex, -1);
127-
128-
sem->count--;
129-
if (sem->count == 0) {
130-
ULONG post_count;
131-
132-
DosResetEventSem(sem->event, &post_count);
133-
}
134-
135-
DosReleaseMutexSem(sem->count_mutex);
136-
137-
DosReleaseMutexSem(sem->wait_mutex);
138-
139-
return 0;
140-
}
141-
142-
static inline int sem_post(sem_t *sem) {
143-
DosRequestMutexSem(sem->count_mutex, -1);
144-
145-
if (sem->count < 32768) {
146-
sem->count++;
147-
DosPostEventSem(sem->event);
148-
}
149-
150-
DosReleaseMutexSem(sem->count_mutex);
151-
152-
return 0;
153-
}
154-
155-
static inline int sem_destroy(sem_t *sem) {
156-
DosCloseEventSem(sem->event);
157-
DosCloseMutexSem(sem->wait_mutex);
158-
DosCloseMutexSem(sem->count_mutex);
159-
160-
return 0;
161-
}
162-
163-
#define thread_sleep(nms) DosSleep(nms)
164-
16582
#else
16683

16784
#ifdef __APPLE__

vp8/vp8_cx_iface.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "vpx_mem/vpx_mem.h"
1919
#include "vpx_ports/static_assert.h"
2020
#include "vpx_ports/system_state.h"
21+
#include "vpx_util/vpx_thread.h"
2122
#include "vpx_util/vpx_timestamp.h"
2223
#if CONFIG_MULTITHREAD
2324
#include "vp8/encoder/ethreading.h"
@@ -148,7 +149,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
148149
RANGE_CHECK_HI(cfg, g_profile, 3);
149150
RANGE_CHECK_HI(cfg, rc_max_quantizer, 63);
150151
RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer);
151-
RANGE_CHECK_HI(cfg, g_threads, 64);
152+
RANGE_CHECK_HI(cfg, g_threads, MAX_NUM_THREADS);
152153
#if CONFIG_REALTIME_ONLY
153154
RANGE_CHECK_HI(cfg, g_lag_in_frames, 0);
154155
#elif CONFIG_MULTI_RES_ENCODING

vp9/decoder/vp9_decodeframe.c

+1
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,7 @@ static INLINE void init_mt(VP9Decoder *pbi) {
22922292
++pbi->num_tile_workers;
22932293

22942294
winterface->init(worker);
2295+
worker->thread_name = "vpx tile worker";
22952296
if (n < num_threads - 1 && !winterface->reset(worker)) {
22962297
do {
22972298
winterface->end(&pbi->tile_workers[pbi->num_tile_workers - 1]);

vp9/decoder/vp9_decoder.c

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ VP9Decoder *vp9_decoder_create(BufferPool *const pool) {
210210
cm->error.setjmp = 0;
211211

212212
vpx_get_worker_interface()->init(&pbi->lf_worker);
213+
pbi->lf_worker.thread_name = "vpx lf worker";
213214

214215
return pbi;
215216
}

vp9/encoder/vp9_ethread.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int enc_worker_hook(void *arg1, void *unused) {
5555
vp9_encode_tile(cpi, thread_data->td, tile_row, tile_col);
5656
}
5757

58-
return 0;
58+
return 1;
5959
}
6060

6161
static int get_max_tile_cols(VP9_COMP *cpi) {
@@ -106,6 +106,7 @@ static void create_enc_workers(VP9_COMP *cpi, int num_workers) {
106106

107107
++cpi->num_workers;
108108
winterface->init(worker);
109+
worker->thread_name = "vpx enc worker";
109110

110111
if (i < num_workers - 1) {
111112
thread_data->cpi = cpi;
@@ -204,8 +205,7 @@ void vp9_encode_tiles_mt(VP9_COMP *cpi) {
204205
create_enc_workers(cpi, num_workers);
205206

206207
for (i = 0; i < num_workers; i++) {
207-
EncWorkerData *thread_data;
208-
thread_data = &cpi->tile_thr_data[i];
208+
EncWorkerData *const thread_data = &cpi->tile_thr_data[i];
209209

210210
// Before encoding a frame, copy the thread data from cpi.
211211
if (thread_data->td != &cpi->td) {
@@ -456,7 +456,7 @@ static int first_pass_worker_hook(void *arg1, void *arg2) {
456456
this_tile, &best_ref_mv, mb_row);
457457
}
458458
}
459-
return 0;
459+
return 1;
460460
}
461461

462462
void vp9_encode_fp_row_mt(VP9_COMP *cpi) {
@@ -543,7 +543,7 @@ static int temporal_filter_worker_hook(void *arg1, void *arg2) {
543543
mb_col_start, mb_col_end);
544544
}
545545
}
546-
return 0;
546+
return 1;
547547
}
548548

549549
void vp9_temporal_filter_row_mt(VP9_COMP *cpi) {
@@ -616,7 +616,7 @@ static int enc_row_mt_worker_hook(void *arg1, void *arg2) {
616616
vp9_encode_sb_row(cpi, thread_data->td, tile_row, tile_col, mi_row);
617617
}
618618
}
619-
return 0;
619+
return 1;
620620
}
621621

622622
void vp9_encode_tiles_row_mt(VP9_COMP *cpi) {

vp9/encoder/vp9_ethread.h

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ extern "C" {
1717

1818
#define MAX_NUM_TILE_COLS (1 << 6)
1919
#define MAX_NUM_TILE_ROWS 4
20-
#define MAX_NUM_THREADS 80
2120

2221
struct VP9_COMP;
2322
struct ThreadData;

vp9/vp9_cx_iface.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "vpx_dsp/psnr.h"
1818
#include "vpx_ports/static_assert.h"
1919
#include "vpx_ports/system_state.h"
20+
#include "vpx_util/vpx_thread.h"
2021
#include "vpx_util/vpx_timestamp.h"
2122
#include "vpx/internal/vpx_codec_internal.h"
2223
#include "./vpx_version.h"
@@ -190,7 +191,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
190191
RANGE_CHECK(extra_cfg, aq_mode, 0, AQ_MODE_COUNT - 2);
191192
RANGE_CHECK(extra_cfg, alt_ref_aq, 0, 1);
192193
RANGE_CHECK(extra_cfg, frame_periodic_boost, 0, 1);
193-
RANGE_CHECK_HI(cfg, g_threads, 64);
194+
RANGE_CHECK_HI(cfg, g_threads, MAX_NUM_THREADS);
194195
RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS);
195196
RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_Q);
196197
RANGE_CHECK_HI(cfg, rc_undershoot_pct, 100);

vpx_ports/vpx_once.h

-23
Original file line numberDiff line numberDiff line change
@@ -91,29 +91,6 @@ static void once(void (*func)(void)) {
9191
return;
9292
}
9393

94-
#elif CONFIG_MULTITHREAD && defined(__OS2__)
95-
#define INCL_DOS
96-
#include <os2.h>
97-
static void once(void (*func)(void)) {
98-
static volatile int done;
99-
100-
/* If the initialization is complete, return early. */
101-
if (done) return;
102-
103-
/* Causes all other threads in the process to block themselves
104-
* and give up their time slice.
105-
*/
106-
DosEnterCritSec();
107-
108-
if (!done) {
109-
func();
110-
done = 1;
111-
}
112-
113-
/* Restores normal thread dispatching for the current process. */
114-
DosExitCritSec();
115-
}
116-
11794
#elif CONFIG_MULTITHREAD && HAVE_PTHREAD_H
11895
#include <pthread.h>
11996
static void once(void (*func)(void)) {

0 commit comments

Comments
 (0)