Home | History | Annotate | Download | only in memory_replay
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <pthread.h>
     18 
     19 #include "Action.h"
     20 #include "Thread.h"
     21 
     22 Thread::Thread() {
     23   pthread_cond_init(&cond_, nullptr);
     24 }
     25 
     26 Thread::~Thread() {
     27   pthread_cond_destroy(&cond_);
     28 }
     29 
     30 void Thread::WaitForReady() {
     31   pthread_mutex_lock(&mutex_);
     32   while (pending_) {
     33     pthread_cond_wait(&cond_, &mutex_);
     34   }
     35   pthread_mutex_unlock(&mutex_);
     36 }
     37 
     38 void Thread::WaitForPending() {
     39   pthread_mutex_lock(&mutex_);
     40   while (!pending_) {
     41     pthread_cond_wait(&cond_, &mutex_);
     42   }
     43   pthread_mutex_unlock(&mutex_);
     44 }
     45 
     46 void Thread::SetPending() {
     47   pthread_mutex_lock(&mutex_);
     48   pending_ = true;
     49   pthread_mutex_unlock(&mutex_);
     50   pthread_cond_signal(&cond_);
     51 }
     52 
     53 void Thread::ClearPending() {
     54   pthread_mutex_lock(&mutex_);
     55   pending_ = false;
     56   pthread_mutex_unlock(&mutex_);
     57   pthread_cond_signal(&cond_);
     58 }
     59 
     60 Action* Thread::CreateAction(uintptr_t key_pointer, const char* type, const char* line) {
     61   return Action::CreateAction(key_pointer, type, line, action_memory_);
     62 }
     63