mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 00:22:43 +00:00 
			
		
		
		
	 6a6dbf5b0b
			
		
	
	
		6a6dbf5b0b
		
	
	
	
	
		
			
			This caused all open file streams to be flushed. This commit also changes `FILE::create` to handle buffer allocation failure gracefully.
		
			
				
	
	
		
			35 lines
		
	
	
	
		
			630 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
	
		
			630 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Daniel Bertalan <dani@danielbertalan.dev>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <pthread.h>
 | |
| 
 | |
| // We don't want to bring LibThreading headers into LibC, so we use plain
 | |
| // pthread mutexes and this RAII guard.
 | |
| namespace LibC {
 | |
| 
 | |
| class [[nodiscard]] MutexLocker {
 | |
| public:
 | |
|     explicit MutexLocker(pthread_mutex_t& mutex)
 | |
|         : m_mutex(mutex)
 | |
|     {
 | |
|         lock();
 | |
|     }
 | |
| 
 | |
|     ~MutexLocker()
 | |
|     {
 | |
|         unlock();
 | |
|     }
 | |
| 
 | |
|     void lock() { pthread_mutex_lock(&m_mutex); }
 | |
|     void unlock() { pthread_mutex_unlock(&m_mutex); }
 | |
| 
 | |
| private:
 | |
|     pthread_mutex_t& m_mutex;
 | |
| };
 | |
| 
 | |
| }
 |