1 /* 2 * Copyright 2021, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef KERNEL_UTIL_THREAD_AUTO_LOCKER_H 6 #define KERNEL_UTIL_THREAD_AUTO_LOCKER_H 7 8 9 #include <shared/AutoLocker.h> 10 11 #include <thread.h> 12 13 14 namespace BPrivate { 15 16 17 class ThreadCPUPinLocking { 18 public: 19 inline bool Lock(Thread* thread) 20 { 21 thread_pin_to_current_cpu(thread); 22 return true; 23 } 24 25 inline void Unlock(Thread* thread) 26 { 27 thread_unpin_from_current_cpu(thread); 28 } 29 }; 30 31 typedef AutoLocker<Thread, ThreadCPUPinLocking> ThreadCPUPinner; 32 typedef AutoLocker<Team> TeamLocker; 33 typedef AutoLocker<Thread> ThreadLocker; 34 35 36 } // namespace BPrivate 37 38 using BPrivate::ThreadCPUPinner; 39 using BPrivate::TeamLocker; 40 using BPrivate::ThreadLocker; 41 42 43 #endif // KERNEL_UTIL_THREAD_AUTO_LOCKER_H 44