 e0a98a4d65
			
		
	
	
		e0a98a4d65
		
	
	
	
	
		
			
			caused interrupts to be reenabled (due to unlock), which caused a race. The problems were especially visible on slower machines. * Relocated free memory parsing to process manager. This saved quite some code at the kernel level. Text size was reduced by about 650 bytes. * Removed locks for updating the realtime in the clock's main loop and the get_uptime function. Interrupts are no longer reentrant, so realtime is immediately updated.
		
			
				
	
	
		
			83 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			83 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| /* This file contains a collection of miscellaneous procedures:
 | |
|  *   panic	    abort MINIX due to a fatal error
 | |
|  *   alloc_bit      bit map manipulation
 | |
|  *   free_bit       bit map manipulation
 | |
|  */
 | |
| 
 | |
| #include "kernel.h"
 | |
| #include "assert.h"
 | |
| #include <unistd.h>
 | |
| #include <minix/com.h>
 | |
| 
 | |
| 
 | |
| /*===========================================================================*
 | |
|  *                                   panic                                   *
 | |
|  *===========================================================================*/
 | |
| PUBLIC void panic(s,n)
 | |
| _CONST char *s;
 | |
| int n;
 | |
| {
 | |
| /* The system has run aground of a fatal kernel error. Terminate execution. */
 | |
|   static int panicking = 0;
 | |
|   if (panicking ++)		/* prevent recursive panics */
 | |
|   	return;
 | |
| 
 | |
|   if (s != NULL) {
 | |
| 	kprintf("\nKernel panic: %s", karg(s));
 | |
| 	if (n != NO_NUM) kprintf(" %d", n);
 | |
| 	kprintf("\n",NO_NUM);
 | |
|   }
 | |
|   prepare_shutdown(RBT_PANIC);
 | |
| }
 | |
| 
 | |
| /*===========================================================================*
 | |
|  *			   	free_bit				     * 
 | |
|  *===========================================================================*/
 | |
| PUBLIC void free_bit(bit_nr, bitmap, nr_bits) 
 | |
| bit_t bit_nr;
 | |
| bitchunk_t *bitmap;
 | |
| bit_t nr_bits;
 | |
| {
 | |
|   bitchunk_t *chunk;
 | |
|   if (bit_nr >= nr_bits) {
 | |
|   	kprintf("Warning, free_bit: %d illegal index\n", bit_nr);
 | |
|   	return;
 | |
|   }
 | |
|   chunk = &bitmap[(bit_nr/BITCHUNK_BITS)];
 | |
|   *chunk &= ~(1 << (bit_nr % BITCHUNK_BITS));
 | |
| }
 | |
| 
 | |
| /*===========================================================================*
 | |
|  *			   	alloc_bit				     * 
 | |
|  *===========================================================================*/
 | |
| PUBLIC int alloc_bit(bitmap, nr_bits) 
 | |
| bitchunk_t *bitmap;
 | |
| bit_t nr_bits;
 | |
| {
 | |
|     bitchunk_t *chunk;
 | |
|     int nr_chunks;
 | |
|     int bit_nr;
 | |
|     int i;
 | |
|     
 | |
|     /* Iterate over the words in block. */
 | |
|     nr_chunks = BITMAP_CHUNKS(nr_bits);
 | |
|     for (chunk = &bitmap[0]; chunk < &bitmap[nr_chunks]; chunk++) {
 | |
| 
 | |
|         /* Does this chunk contain a free bit? */
 | |
|         if (*chunk == (bitchunk_t) ~0) continue;
 | |
|         
 | |
|         /* Get bit number from the start of the bit map. */
 | |
|         for (i = 0; (*chunk & (1 << i)) != 0; ++i) {}
 | |
|         bit_nr = (chunk - &bitmap[0]) * BITCHUNK_BITS + i;
 | |
|         
 | |
|         /* Don't allocate bits beyond the end of the map. */
 | |
|         if (bit_nr >= nr_bits) break;
 | |
| 
 | |
|         *chunk |= 1 << bit_nr % BITCHUNK_BITS;
 | |
|         return(bit_nr);        
 | |
|         
 | |
|     }
 | |
|     return(-1);    
 | |
| }
 | |
| 
 |