Lines Matching refs:worker

10 // Multi-threaded worker
30 VP9Worker* const worker = (VP9Worker*)ptr;
33 pthread_mutex_lock(&worker->mutex_);
34 while (worker->status_ == OK) { // wait in idling mode
35 pthread_cond_wait(&worker->condition_, &worker->mutex_);
37 if (worker->status_ == WORK) {
38 vp9_worker_execute(worker);
39 worker->status_ = OK;
40 } else if (worker->status_ == NOT_OK) { // finish the worker
44 pthread_cond_signal(&worker->condition_);
45 pthread_mutex_unlock(&worker->mutex_);
51 static void change_state(VP9Worker* const worker,
54 if (worker->status_ < OK) return;
56 pthread_mutex_lock(&worker->mutex_);
57 // wait for the worker to finish
58 while (worker->status_ != OK) {
59 pthread_cond_wait(&worker->condition_, &worker->mutex_);
63 worker->status_ = new_status;
64 pthread_cond_signal(&worker->condition_);
66 pthread_mutex_unlock(&worker->mutex_);
73 void vp9_worker_init(VP9Worker* const worker) {
74 memset(worker, 0, sizeof(*worker));
75 worker->status_ = NOT_OK;
78 int vp9_worker_sync(VP9Worker* const worker) {
80 change_state(worker, OK);
82 assert(worker->status_ <= OK);
83 return !worker->had_error;
86 int vp9_worker_reset(VP9Worker* const worker) {
88 worker->had_error = 0;
89 if (worker->status_ < OK) {
91 if (pthread_mutex_init(&worker->mutex_, NULL) ||
92 pthread_cond_init(&worker->condition_, NULL)) {
95 pthread_mutex_lock(&worker->mutex_);
96 ok = !pthread_create(&worker->thread_, NULL, thread_loop, worker);
97 if (ok) worker->status_ = OK;
98 pthread_mutex_unlock(&worker->mutex_);
100 worker->status_ = OK;
102 } else if (worker->status_ > OK) {
103 ok = vp9_worker_sync(worker);
105 assert(!ok || (worker->status_ == OK));
109 void vp9_worker_execute(VP9Worker* const worker) {
110 if (worker->hook != NULL) {
111 worker->had_error |= !worker->hook(worker->data1, worker->data2);
115 void vp9_worker_launch(VP9Worker* const worker) {
117 change_state(worker, WORK);
119 vp9_worker_execute(worker);
123 void vp9_worker_end(VP9Worker* const worker) {
124 if (worker->status_ >= OK) {
126 change_state(worker, NOT_OK);
127 pthread_join(worker->thread_, NULL);
128 pthread_mutex_destroy(&worker->mutex_);
129 pthread_cond_destroy(&worker->condition_);
131 worker->status_ = NOT_OK;
134 assert(worker->status_ == NOT_OK);