mirror of
				https://github.com/encounter/SDL.git
				synced 2025-10-27 12:10:24 +00:00 
			
		
		
		
	switch: update for latest libnx
This commit is contained in:
		
							parent
							
								
									43be1d5030
								
							
						
					
					
						commit
						9e06af0445
					
				| @ -33,10 +33,14 @@ | |||||||
| 
 | 
 | ||||||
| struct SDL_cond | struct SDL_cond | ||||||
| { | { | ||||||
|     Mutex mutex; |  | ||||||
|     CondVar var; |     CondVar var; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | struct SDL_mutex | ||||||
|  | { | ||||||
|  |     RMutex mtx; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| /* Create a condition variable */ | /* Create a condition variable */ | ||||||
| SDL_cond * | SDL_cond * | ||||||
| SDL_CreateCond(void) | SDL_CreateCond(void) | ||||||
| @ -45,8 +49,7 @@ SDL_CreateCond(void) | |||||||
| 
 | 
 | ||||||
|     cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); |     cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); | ||||||
|     if (cond) { |     if (cond) { | ||||||
|         mutexInit(&cond->mutex); |         condvarInit(&cond->var); | ||||||
|         condvarInit(&cond->var, &cond->mutex); |  | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         SDL_OutOfMemory(); |         SDL_OutOfMemory(); | ||||||
| @ -113,17 +116,22 @@ Thread B: | |||||||
| int | int | ||||||
| SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) | SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) | ||||||
| { | { | ||||||
|  |     uint32_t mutex_state[2]; | ||||||
|  | 
 | ||||||
|     if (!cond) { |     if (!cond) { | ||||||
|         return SDL_SetError("Passed a NULL condition variable"); |         return SDL_SetError("Passed a NULL condition variable"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /* Unlock the mutex, as is required by condition variable semantics */ | 	// backup mutex state
 | ||||||
|     SDL_UnlockMutex(mutex); |     mutex_state[0] = mutex->mtx.thread_tag; | ||||||
|  |     mutex_state[1] = mutex->mtx.counter; | ||||||
|  |     mutex->mtx.thread_tag = 0; | ||||||
|  |     mutex->mtx.counter = 0; | ||||||
| 
 | 
 | ||||||
|     condvarWaitTimeout(&cond->var, ms * 1000000); |     condvarWaitTimeout(&cond->var, &mutex->mtx.lock, ms * 1000000); | ||||||
| 
 | 
 | ||||||
|     /* Lock the mutex, as is required by condition variable semantics */ |     mutex->mtx.thread_tag = mutex_state[0]; | ||||||
|     SDL_LockMutex(mutex); |     mutex->mtx.counter = mutex_state[1]; | ||||||
| 
 | 
 | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user