media/libvpx/vp9/decoder/vp9_thread.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 // Copyright 2013 Google Inc. All Rights Reserved.
michael@0 2 //
michael@0 3 // Use of this source code is governed by a BSD-style license
michael@0 4 // that can be found in the COPYING file in the root of the source
michael@0 5 // tree. An additional intellectual property rights grant can be found
michael@0 6 // in the file PATENTS. All contributing project authors may
michael@0 7 // be found in the AUTHORS file in the root of the source tree.
michael@0 8 // -----------------------------------------------------------------------------
michael@0 9 //
michael@0 10 // Multi-threaded worker
michael@0 11 //
michael@0 12 // Original source:
michael@0 13 // http://git.chromium.org/webm/libwebp.git
michael@0 14 // 100644 blob 13a61a4c84194c3374080cbf03d881d3cd6af40d src/utils/thread.h
michael@0 15
michael@0 16
michael@0 17 #ifndef VP9_DECODER_VP9_THREAD_H_
michael@0 18 #define VP9_DECODER_VP9_THREAD_H_
michael@0 19
michael@0 20 #include "./vpx_config.h"
michael@0 21
michael@0 22 #if defined(__cplusplus) || defined(c_plusplus)
michael@0 23 extern "C" {
michael@0 24 #endif
michael@0 25
michael@0 26 #if CONFIG_MULTITHREAD
michael@0 27
michael@0 28 #if defined(_WIN32)
michael@0 29
michael@0 30 #include <windows.h> // NOLINT
michael@0 31 typedef HANDLE pthread_t;
michael@0 32 typedef CRITICAL_SECTION pthread_mutex_t;
michael@0 33 typedef struct {
michael@0 34 HANDLE waiting_sem_;
michael@0 35 HANDLE received_sem_;
michael@0 36 HANDLE signal_event_;
michael@0 37 } pthread_cond_t;
michael@0 38
michael@0 39 #else
michael@0 40
michael@0 41 #include <pthread.h> // NOLINT
michael@0 42
michael@0 43 #endif /* _WIN32 */
michael@0 44 #endif /* CONFIG_MULTITHREAD */
michael@0 45
michael@0 46 // State of the worker thread object
michael@0 47 typedef enum {
michael@0 48 NOT_OK = 0, // object is unusable
michael@0 49 OK, // ready to work
michael@0 50 WORK // busy finishing the current task
michael@0 51 } VP9WorkerStatus;
michael@0 52
michael@0 53 // Function to be called by the worker thread. Takes two opaque pointers as
michael@0 54 // arguments (data1 and data2), and should return false in case of error.
michael@0 55 typedef int (*VP9WorkerHook)(void*, void*);
michael@0 56
michael@0 57 // Synchronize object used to launch job in the worker thread
michael@0 58 typedef struct {
michael@0 59 #if CONFIG_MULTITHREAD
michael@0 60 pthread_mutex_t mutex_;
michael@0 61 pthread_cond_t condition_;
michael@0 62 pthread_t thread_;
michael@0 63 #endif
michael@0 64 VP9WorkerStatus status_;
michael@0 65 VP9WorkerHook hook; // hook to call
michael@0 66 void* data1; // first argument passed to 'hook'
michael@0 67 void* data2; // second argument passed to 'hook'
michael@0 68 int had_error; // return value of the last call to 'hook'
michael@0 69 } VP9Worker;
michael@0 70
michael@0 71 // Must be called first, before any other method.
michael@0 72 void vp9_worker_init(VP9Worker* const worker);
michael@0 73 // Must be called to initialize the object and spawn the thread. Re-entrant.
michael@0 74 // Will potentially launch the thread. Returns false in case of error.
michael@0 75 int vp9_worker_reset(VP9Worker* const worker);
michael@0 76 // Makes sure the previous work is finished. Returns true if worker->had_error
michael@0 77 // was not set and no error condition was triggered by the working thread.
michael@0 78 int vp9_worker_sync(VP9Worker* const worker);
michael@0 79 // Triggers the thread to call hook() with data1 and data2 argument. These
michael@0 80 // hook/data1/data2 can be changed at any time before calling this function,
michael@0 81 // but not be changed afterward until the next call to vp9_worker_sync().
michael@0 82 void vp9_worker_launch(VP9Worker* const worker);
michael@0 83 // This function is similar to vp9_worker_launch() except that it calls the
michael@0 84 // hook directly instead of using a thread. Convenient to bypass the thread
michael@0 85 // mechanism while still using the VP9Worker structs. vp9_worker_sync() must
michael@0 86 // still be called afterward (for error reporting).
michael@0 87 void vp9_worker_execute(VP9Worker* const worker);
michael@0 88 // Kill the thread and terminate the object. To use the object again, one
michael@0 89 // must call vp9_worker_reset() again.
michael@0 90 void vp9_worker_end(VP9Worker* const worker);
michael@0 91
michael@0 92 //------------------------------------------------------------------------------
michael@0 93
michael@0 94 #if defined(__cplusplus) || defined(c_plusplus)
michael@0 95 } // extern "C"
michael@0 96 #endif
michael@0 97
michael@0 98 #endif // VP9_DECODER_VP9_THREAD_H_

mercurial