History

plan 9: dirty multithreading (need to link with dav1d until this is moved somewhere else)

Sigrid Haflínudóttir committed 6 years agoplan9_0

Commit c097de81 parent ba694339 files · +152 −6Browse files

Unified · Split

9 files
  1. mkfile +1 −1
  2. plan9/pthread.h +75 −0
  3. plan9/sched.h +0 −0
  4. plan9/semaphore.h +50 −0
  5. plan9/vpx_config.h +13 −4
  6. vp8/common/generic/systemdependent.c +7 −1
  7. vp8/vp8_dx_iface.c +1 −0
  8. vpx_util/endian_inl.h +2 −0
  9. vpx_util/vpx_thread.h +3 −0
mkfile+1−1
@@ -60,7 +60,7 @@ OFILES=\ · 59 unmodified lines
6060 detokenize.$O\
6161 # error_concealment.$O\
6262 onyxd_if.$O\
63−# threading.$O\
63+ threading.$O\
6464 # vp8/encoder \
6565 bitstream.$O\
6666 boolhuff.$O\
plan9/pthread.h+75−0
@@ -0,0 +1,75 @@
1+#ifndef __pthread_h__
2+#define __pthread_h__
3+
4+typedef struct pthread_t pthread_t;
5+typedef struct pthread_cond_t pthread_cond_t;
6+typedef struct pthread_once_t pthread_once_t;
7+typedef struct pthread_mutex_t pthread_mutex_t;
8+
9+struct pthread_cond_t {
10+ Rendez;
11+ QLock lock;
12+};
13+
14+struct pthread_once_t {
15+ QLock;
16+ int done;
17+};
18+
19+struct pthread_mutex_t {
20+ QLock;
21+};
22+
23+#define PTHREAD_ONCE_INIT {0}
24+
25+struct pthread_t {
26+ void *waitchan;
27+ void *(*func)(void*);
28+ void *arg;
29+ int pid;
30+};
31+
32+typedef struct {
33+ unsigned stack_size;
34+} pthread_attr_t;
35+
36+void dav1d_set_thread_name(const char *const name);
37+int dav1d_pthread_join(pthread_t *thread, void **res);
38+#define pthread_join(thread, res) dav1d_pthread_join(&(thread), res)
39+
40+static int pthread_attr_init(pthread_attr_t *const attr) {
41+ attr->stack_size = 0;
42+ return 0;
43+}
44+
45+static int pthread_attr_destroy(pthread_attr_t *const attr) {
46+ USED(attr);
47+ return 0;
48+}
49+
50+static int pthread_attr_setstacksize(pthread_attr_t *const attr,
51+ const int stack_size)
52+{
53+ attr->stack_size = stack_size;
54+ return 0;
55+}
56+
57+static int
58+pthread_mutex_trylock(pthread_mutex_t *const mutex)
59+{
60+ return canqlock(mutex) ? 0 : -1;
61+}
62+
63+int pthread_mutex_init(pthread_mutex_t *const mutex, const void *const attr);
64+int pthread_mutex_destroy(pthread_mutex_t *const mutex);
65+int pthread_mutex_lock(pthread_mutex_t *const mutex);
66+int pthread_mutex_unlock(pthread_mutex_t *const mutex);
67+int pthread_cond_init(pthread_cond_t *const cond, const void *const attr);
68+int pthread_cond_destroy(pthread_cond_t *const cond);
69+int pthread_cond_wait(pthread_cond_t *const cond, pthread_mutex_t *const mutex);
70+int pthread_cond_signal(pthread_cond_t *const cond);
71+int pthread_cond_broadcast(pthread_cond_t *const cond);
72+int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*func)(void*), void *arg);
73+int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
74+
75+#endif
plan9/sched.h+0−0

Empty file added.

plan9/semaphore.h+50−0
@@ -0,0 +1,50 @@
1+#ifndef __semaphore_h__
2+#define __semaphore_h__
3+
4+typedef struct sem_t sem_t;
5+
6+struct sem_t {
7+ Channel *c;
8+};
9+
10+static int
11+sem_post(sem_t *s)
12+{
13+ void *p;
14+
15+ if(s == nil || s->c == nil)
16+ return -1;
17+ nbrecv(s->c, &p);
18+
19+ return 0;
20+}
21+
22+static int
23+sem_wait(sem_t *s)
24+{
25+ void *p;
26+
27+ if(s == nil || s->c == nil)
28+ return -1;
29+ sendp(s->c, nil);
30+
31+ return 0;
32+}
33+
34+static int
35+sem_init(sem_t *s, int pshared, unsigned int value)
36+{
37+ s->c = chancreate(sizeof(void*), value);
38+
39+ return 0;
40+}
41+
42+static int
43+sem_destroy(sem_t *s)
44+{
45+ chanclose(s->c);
46+
47+ return 0;
48+}
49+
50+#endif
plan9/vpx_config.h+13−4
@@ -11,6 +11,7 @@ · 10 unmodified lines
1111
1212 #include <u.h>
1313 #include <libc.h>
14+#include <thread.h>
1415 #include </sys/include/stdio.h>
1516 typedef u8int uint8_t;
1617 typedef u16int uint16_t;
@@ -59,6 +60,14 @@ int gettimeofday(struct timeval *, struct timezone *); · 42 unmodified lines
5960 double round(double);
6061 #define logf log
6162
63+#define sched_yield() yield()
64+#define __atomic_load_n(p,o) *(p)
65+#define __atomic_store_n(p,v,x) do { *(p) = (v); } while(0)
66+#define __has_builtin(x) 1
67+
68+#define __ATOMIC_RELEASE 0
69+#define __ATOMIC_ACQUIRE 1
70+
6271 #define RESTRICT
6372 #define INLINE inline
6473 #define VPX_ARCH_ARM 0
@@ -84,7 +93,7 @@ double round(double); · 19 unmodified lines
8493 #define HAVE_VSX 0
8594 #define HAVE_MMI 0
8695 #define HAVE_VPX_PORTS 0
87−#define HAVE_PTHREAD_H 0
96+#define HAVE_PTHREAD_H 1
8897 #define HAVE_UNISTD_H 1
8998 #define CONFIG_DEPENDENCY_TRACKING 1
9099 #define CONFIG_EXTERNAL_BUILD 0
@@ -107,7 +116,7 @@ double round(double); · 16 unmodified lines
107116 #define CONFIG_RUNTIME_CPU_DETECT 1
108117 #define CONFIG_POSTPROC 0
109118 #define CONFIG_VP9_POSTPROC 0
110−#define CONFIG_MULTITHREAD 0
119+#define CONFIG_MULTITHREAD 1
111120 #define CONFIG_INTERNAL_STATS 0
112121 #define CONFIG_VP8_ENCODER 1
113122 #define CONFIG_VP8_DECODER 1
@@ -122,12 +131,12 @@ double round(double); · 8 unmodified lines
122131 #define CONFIG_REALTIME_ONLY 0
123132 #define CONFIG_ONTHEFLY_BITPACKING 0
124133 #define CONFIG_ERROR_CONCEALMENT 0
125−#define CONFIG_SHARED 1
134+#define CONFIG_SHARED 0
126135 #define CONFIG_STATIC 1
127136 #define CONFIG_SMALL 0
128137 #define CONFIG_POSTPROC_VISUALIZER 0
129138 #define CONFIG_OS_SUPPORT 1
130−#define CONFIG_UNIT_TESTS 1
139+#define CONFIG_UNIT_TESTS 0
131140 #define CONFIG_WEBM_IO 0
132141 #define CONFIG_LIBYUV 0
133142 #define CONFIG_DECODE_PERF_TESTS 0
vp8/common/generic/systemdependent.c+7−1
@@ -36,7 +36,7 @@ typedef void(WINAPI *PGNSI)(LPSYSTEM_INFO); · 35 unmodified lines
3636 #endif
3737
3838 #if CONFIG_MULTITHREAD
39−static int get_cpu_count() {
39+static int get_cpu_count(void) {
4040 int core_count = 16;
4141
4242 #if HAVE_UNISTD_H && !defined(__OS2__)
@@ -79,6 +79,12 @@ static int get_cpu_count() { · 36 unmodified lines
7979 if (status == PROC_ONLINE) core_count++;
8080 }
8181 }
82+#elif defined(__plan9__)
83+ {
84+ char *s = getenv("NPROC");
85+ core_count = atoi(s ? s : "1");
86+ fprint(2, "core count: %d\n", core_count);
87+ }
8288 #else
8389 /* other platforms */
8490 #endif
vp8/vp8_dx_iface.c+1−0
@@ -11,6 +11,7 @@ · 10 unmodified lines
1111 #include <assert.h>
1212 #include <stdlib.h>
1313 #include <string.h>
14+#include "vpx_config.h"
1415 #include "./vp8_rtcd.h"
1516 #include "./vpx_dsp_rtcd.h"
1617 #include "./vpx_scale_rtcd.h"
vpx_util/endian_inl.h+2−0
@@ -48,6 +48,7 @@ · 47 unmodified lines
4848 #define HToBE32(X) BSwap32(X)
4949 #endif
5050
51+#ifndef __plan9__
5152 #if LOCAL_GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16)
5253 #define HAVE_BUILTIN_BSWAP16
5354 #endif
@@ -59,6 +60,7 @@ · 5 unmodified lines
5960 #if LOCAL_GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64)
6061 #define HAVE_BUILTIN_BSWAP64
6162 #endif
63+#endif
6264
6365 #if HAVE_MIPS32 && defined(__mips__) && !defined(__mips64) && \
6466 defined(__mips_isa_rev) && (__mips_isa_rev >= 2) && (__mips_isa_rev < 6)
vpx_util/vpx_thread.h+3−0
@@ -383,6 +383,7 @@ typedef int (*VPxWorkerHook)(void *, void *); · 382 unmodified lines
383383
384384 // Platform-dependent implementation details for the worker.
385385 typedef struct VPxWorkerImpl VPxWorkerImpl;
386+#pragma incomplete VPxWorkerImpl
386387
387388 // Synchronization object used to launch job in the worker thread
388389 typedef struct {
@@ -393,6 +394,7 @@ typedef struct { · 4 unmodified lines
393394 void *data2; // second argument passed to 'hook'
394395 int had_error; // return value of the last call to 'hook'
395396 } VPxWorker;
397+#pragma incomplete VPxWorker
396398
397399 // The interface for all thread-worker related functions. All these functions
398400 // must be implemented.
@@ -418,6 +420,7 @@ typedef struct { · 19 unmodified lines
418420 // must call reset() again.
419421 void (*end)(VPxWorker *const worker);
420422 } VPxWorkerInterface;
423+#pragma incomplete VPxWorkerInterface
421424
422425 // Install a new set of threading functions, overriding the defaults. This
423426 // should be done before any workers are started, i.e., before any encoding or

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t