Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/videolan/dav1d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Gramner <gramner@twoorioles.com>2019-05-03 16:01:04 +0300
committerHenrik Gramner <henrik@gramner.com>2019-05-04 22:58:02 +0300
commit2756254fc6ba402c5b6ab345944d0878975ed715 (patch)
treeace10546f1201c056478f58492e9cc867c9964c6 /src/thread.h
parent1d5c1a493742503838b12f108e041644d4838656 (diff)
Control the stack size of spawned threads
On some systems (e.g. Google Fuchsia) the default stack size of new threads is insufficient, resulting in crashes. On other systems the default stack size is unnecessarily large, which can waste a lot of virtual memory. By setting it to a sufficiently large fixed value we can ensure that we don't run out of stack space while keeping down memory usage.
Diffstat (limited to 'src/thread.h')
-rw-r--r--src/thread.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/thread.h b/src/thread.h
index f8da628..b2529fc 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -40,11 +40,15 @@ typedef struct {
void *arg;
} pthread_t;
+typedef struct {
+ unsigned stack_size;
+} pthread_attr_t;
+
typedef SRWLOCK pthread_mutex_t;
typedef CONDITION_VARIABLE pthread_cond_t;
typedef INIT_ONCE pthread_once_t;
-int dav1d_pthread_create(pthread_t *thread, const void *attr,
+int dav1d_pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*func)(void*), void *arg);
int dav1d_pthread_join(pthread_t *thread, void **res);
int dav1d_pthread_once(pthread_once_t *once_control,
@@ -54,6 +58,22 @@ int dav1d_pthread_once(pthread_once_t *once_control,
#define pthread_join(thread, res) dav1d_pthread_join(&(thread), res)
#define pthread_once dav1d_pthread_once
+static inline int pthread_attr_init(pthread_attr_t *const attr) {
+ attr->stack_size = 0;
+ return 0;
+}
+
+static inline int pthread_attr_destroy(pthread_attr_t *const attr) {
+ return 0;
+}
+
+static inline int pthread_attr_setstacksize(pthread_attr_t *const attr,
+ const unsigned stack_size)
+{
+ attr->stack_size = stack_size;
+ return 0;
+}
+
static inline int pthread_mutex_init(pthread_mutex_t *const mutex,
const void *const attr)
{