1 /* 2 * Copyright (C) 2024 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 #ifndef CHRE_PLATFORM_LINUX_NOTIFIER_BASE_H_ 18 #define CHRE_PLATFORM_LINUX_NOTIFIER_BASE_H_ 19 20 #include <pthread.h> 21 22 #include <condition_variable> 23 #include <mutex> 24 #include <optional> 25 26 namespace chre { 27 28 /** 29 * Storage for Linux implementation of a direct task notifier. 30 */ 31 class NotifierBase { 32 protected: 33 static constexpr uint32_t kWaitFlag = 0x80000000; 34 35 //! The task this Notifier instance is bound to. 36 std::optional<pthread_t> mTarget; 37 38 //! Mutex protecting the notified state. 39 std::mutex mLock; 40 41 //! Condition variable used to notify the waiting task. 42 std::condition_variable mCondVar; 43 44 //! Whether the Notifier has been notified. 45 bool mNotified = false; 46 }; 47 48 } // namespace chre 49 50 #endif // CHRE_PLATFORM_LINUX_NOTIFIER_BASE_H_ 51