Commit ef1fb6de authored by Johann Koenig's avatar Johann Koenig Committed by Gerrit Code Review

Merge changes I999ef597,Ic6dc9f53

* changes:
  configure: Add -mstackrealign flags to CFLAGS on OS/2
  vpx: Add OS/2-specific threading codes
parents 3de42ac2 72e332f7
......@@ -119,29 +119,25 @@ utiltest:
test-no-data-check::
exampletest-no-data-check utiltest-no-data-check:
# Add compiler flags for intrinsic files
# Force to realign stack always on OS/2
ifeq ($(TOOLCHAIN), x86-os2-gcc)
STACKREALIGN=-mstackrealign
else
STACKREALIGN=
CFLAGS += -mstackrealign
endif
$(BUILD_PFX)%_mmx.c.d: CFLAGS += -mmmx
$(BUILD_PFX)%_mmx.c.o: CFLAGS += -mmmx
$(BUILD_PFX)%_sse2.c.d: CFLAGS += -msse2 $(STACKREALIGN)
$(BUILD_PFX)%_sse2.c.o: CFLAGS += -msse2 $(STACKREALIGN)
$(BUILD_PFX)%_sse3.c.d: CFLAGS += -msse3 $(STACKREALIGN)
$(BUILD_PFX)%_sse3.c.o: CFLAGS += -msse3 $(STACKREALIGN)
$(BUILD_PFX)%_ssse3.c.d: CFLAGS += -mssse3 $(STACKREALIGN)
$(BUILD_PFX)%_ssse3.c.o: CFLAGS += -mssse3 $(STACKREALIGN)
$(BUILD_PFX)%_sse4.c.d: CFLAGS += -msse4.1 $(STACKREALIGN)
$(BUILD_PFX)%_sse4.c.o: CFLAGS += -msse4.1 $(STACKREALIGN)
$(BUILD_PFX)%_avx.c.d: CFLAGS += -mavx $(STACKREALIGN)
$(BUILD_PFX)%_avx.c.o: CFLAGS += -mavx $(STACKREALIGN)
$(BUILD_PFX)%_avx2.c.d: CFLAGS += -mavx2 $(STACKREALIGN)
$(BUILD_PFX)%_avx2.c.o: CFLAGS += -mavx2 $(STACKREALIGN)
$(BUILD_PFX)%vp9_reconintra.c.d: CFLAGS += $(STACKREALIGN)
$(BUILD_PFX)%vp9_reconintra.c.o: CFLAGS += $(STACKREALIGN)
$(BUILD_PFX)%_sse2.c.d: CFLAGS += -msse2
$(BUILD_PFX)%_sse2.c.o: CFLAGS += -msse2
$(BUILD_PFX)%_sse3.c.d: CFLAGS += -msse3
$(BUILD_PFX)%_sse3.c.o: CFLAGS += -msse3
$(BUILD_PFX)%_ssse3.c.d: CFLAGS += -mssse3
$(BUILD_PFX)%_ssse3.c.o: CFLAGS += -mssse3
$(BUILD_PFX)%_sse4.c.d: CFLAGS += -msse4.1
$(BUILD_PFX)%_sse4.c.o: CFLAGS += -msse4.1
$(BUILD_PFX)%_avx.c.d: CFLAGS += -mavx
$(BUILD_PFX)%_avx.c.o: CFLAGS += -mavx
$(BUILD_PFX)%_avx2.c.d: CFLAGS += -mavx2
$(BUILD_PFX)%_avx2.c.o: CFLAGS += -mavx2
$(BUILD_PFX)%.c.d: %.c
$(if $(quiet),@echo " [DEP] $@")
......
......@@ -44,8 +44,8 @@ extern "C" {
#include <os2.h>
#include <stdlib.h>
#define THREAD_FUNCTION void
#define THREAD_FUNCTION_RETURN void
#define THREAD_FUNCTION void *
#define THREAD_FUNCTION_RETURN void *
#define THREAD_SPECIFIC_INDEX PULONG
#define pthread_t TID
#define pthread_attr_t ULONG
......
......@@ -147,6 +147,152 @@ static INLINE int pthread_cond_wait(pthread_cond_t *const condition,
pthread_mutex_lock(mutex);
return !ok;
}
#elif defined(__OS2__)
#define INCL_DOS
#include <os2.h> // NOLINT
#include <errno.h> // NOLINT
#include <stdlib.h> // NOLINT
#include <sys/builtin.h> // NOLINT
#define pthread_t TID
#define pthread_mutex_t HMTX
typedef struct {
HEV event_sem_;
HEV ack_sem_;
volatile unsigned wait_count_;
} pthread_cond_t;
//------------------------------------------------------------------------------
// simplistic pthread emulation layer
#define THREADFN void *
#define THREAD_RETURN(val) (val)
typedef struct {
void* (*start_)(void*);
void* arg_;
} thread_arg;
static void thread_start(void* arg) {
thread_arg targ = *(thread_arg *)arg;
free(arg);
targ.start_(targ.arg_);
}
static INLINE int pthread_create(pthread_t* const thread, const void* attr,
void* (*start)(void*),
void* arg) {
int tid;
thread_arg *targ = (thread_arg *)malloc(sizeof(*targ));
if (targ == NULL) return 1;
(void)attr;
targ->start_ = start;
targ->arg_ = arg;
tid = (pthread_t)_beginthread(thread_start, NULL, 1024 * 1024, targ);
if (tid == -1) {
free(targ);
return 1;
}
*thread = tid;
return 0;
}
static INLINE int pthread_join(pthread_t thread, void** value_ptr) {
(void)value_ptr;
return DosWaitThread(&thread, DCWW_WAIT) != 0;
}
// Mutex
static INLINE int pthread_mutex_init(pthread_mutex_t *const mutex,
void* mutexattr) {
(void)mutexattr;
return DosCreateMutexSem(NULL, mutex, 0, FALSE) != 0;
}
static INLINE int pthread_mutex_trylock(pthread_mutex_t *const mutex) {
return DosRequestMutexSem(*mutex, SEM_IMMEDIATE_RETURN) == 0 ? 0 : EBUSY;
}
static INLINE int pthread_mutex_lock(pthread_mutex_t *const mutex) {
return DosRequestMutexSem(*mutex, SEM_INDEFINITE_WAIT) != 0;
}
static INLINE int pthread_mutex_unlock(pthread_mutex_t *const mutex) {
return DosReleaseMutexSem(*mutex) != 0;
}
static INLINE int pthread_mutex_destroy(pthread_mutex_t *const mutex) {
return DosCloseMutexSem(*mutex) != 0;
}
// Condition
static INLINE int pthread_cond_destroy(pthread_cond_t *const condition) {
int ok = 1;
ok &= DosCloseEventSem(condition->event_sem_) == 0;
ok &= DosCloseEventSem(condition->ack_sem_) == 0;
return !ok;
}
static INLINE int pthread_cond_init(pthread_cond_t *const condition,
void* cond_attr) {
int ok = 1;
(void)cond_attr;
ok &= DosCreateEventSem(NULL, &condition->event_sem_, DCE_POSTONE, FALSE)
== 0;
ok &= DosCreateEventSem(NULL, &condition->ack_sem_, DCE_POSTONE, FALSE) == 0;
if (!ok) {
pthread_cond_destroy(condition);
return 1;
}
condition->wait_count_ = 0;
return 0;
}
static INLINE int pthread_cond_signal(pthread_cond_t *const condition) {
int ok = 1;
if (!__atomic_cmpxchg32(&condition->wait_count_, 0, 0)) {
ok &= DosPostEventSem(condition->event_sem_) == 0;
ok &= DosWaitEventSem(condition->ack_sem_, SEM_INDEFINITE_WAIT) == 0;
}
return !ok;
}
static INLINE int pthread_cond_broadcast(pthread_cond_t *const condition) {
int ok = 1;
while (!__atomic_cmpxchg32(&condition->wait_count_, 0, 0))
ok &= pthread_cond_signal(condition) == 0;
return !ok;
}
static INLINE int pthread_cond_wait(pthread_cond_t *const condition,
pthread_mutex_t *const mutex) {
int ok = 1;
__atomic_increment(&condition->wait_count_);
ok &= pthread_mutex_unlock(mutex) == 0;
ok &= DosWaitEventSem(condition->event_sem_, SEM_INDEFINITE_WAIT) == 0;
__atomic_decrement(&condition->wait_count_);
ok &= DosPostEventSem(condition->ack_sem_) == 0;
pthread_mutex_lock(mutex);
return !ok;
}
#else // _WIN32
#include <pthread.h> // NOLINT
# define THREADFN void*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment