Example #1
0
double dmatdmatmult(size_t N, size_t iterations = 1) {
    
    blaze::DynamicMatrix<value_type> a(N, N), b(N, N), c(N, N);
    
    minit(a.rows(), a);
    minit(b.rows(), b);
    
    std::vector<double> times;
    for(size_t i = 0; i < iterations; ++i){
        
        auto start = std::chrono::steady_clock::now();
        c = a*b;
        auto end = std::chrono::steady_clock::now();
        
        auto diff = end - start;
        times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration
    }
    
    double tmin = *(std::min_element(times.begin(), times.end()));
    double tavg = average_time(times);

    // check to see if anything happened during run to invalidate the times
    if(variance(tavg, times) > max_variance){
        std::cerr << "blaze kernel 'dmatdmatmult': Time deviation too large! \n";
    }
    
    return tavg;
    
}
double dmatdmatmult(size_t N, size_t iterations = 1) {
    
    Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> a(N, N), b(N, N), c(N, N);
    
    minit(a.rows(), a);
    minit(b.rows(), b);
    
    std::vector<double> times;
    for(size_t i = 0; i < iterations; ++i){
        
        auto start = std::chrono::steady_clock::now();
        c = a*b;
        auto end = std::chrono::steady_clock::now();
        
        auto diff = end - start;
        times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration
    }
    
    double tmin = *(std::min_element(times.begin(), times.end()));
    double tavg = average_time(times);
 /*
    // check to see if nothing happened during rum to invalidate the times
    if(tmin*(1.0 + deviation*0.01) < tavg){
        std::cerr << "uBLAS kernel 'dmatdmatmult': Time deviation too large!!!" << std::endl;
    }
*/
    return tavg;
    
}
Example #3
0
double symm2(size_t N, size_t iterations = 1){
    
    blaze::DynamicMatrix<value_type, blaze::rowMajor> A(N, N), B(N, N), C(N, N);
    value_type c = 3;
    
    minit(N, A);
    minit(N, B);
    minit(N, C);
    
    std::vector<double> times;
    for(size_t i = 0; i < iterations; ++i){
        
        auto start = std::chrono::steady_clock::now();
        C = c * C + c * A.transpose() * B;
        auto end = std::chrono::steady_clock::now();
        
        auto diff = end - start;
        times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration
    }
    
    double tmin = *(std::min_element(times.begin(), times.end()));
    double tavg = average_time(times);

    // check to see if anything happened during run to invalidate the times
    if(variance(tavg, times) > max_variance){
        std::cerr << "blaze kernel 'symm2': Time deviation too large! \n";
    }
    
    return tavg;
    
}
double rmajordmdmmult(size_t N, size_t iterations = 1){
    
    Eigen::Matrix<value_type, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> A(N, N), B(N, N), C(N, N);
    
    minit(N, A);
    minit(N, B);
    
    std::vector<double> times;
    for(size_t i = 0; i < iterations; ++i){
        
        auto start = std::chrono::steady_clock::now();
        C.noalias() = A * B;
        auto end = std::chrono::steady_clock::now();
        
        auto diff = end - start;
        times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration
    }
    
    double tmin = *(std::min_element(times.begin(), times.end()));
    double tavg = average_time(times);

    // check to see if nothing happened during run to invalidate the times
    if(variance(tavg, times) > max_variance){
        std::cerr << "eigen kernel 'rmajordmdmmult': Time deviation too large! \n";
    }
    
    return tavg;
    
}
Example #5
0
double nestedprod(size_t N, size_t iterations = 1){
    
    typedef boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::row_major> matrix_type;
    boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::row_major> A(N, N), B(N, N), C(N, N), D(N, N), E(N, N), F(N, N);
    
    minit(N, B);
    minit(N, C);
    minit(N, D);
    minit(N, E);
    minit(N, F);
    
    std::vector<double> times;
    for(size_t i = 0; i < iterations; ++i){
        
        auto start = std::chrono::steady_clock::now();
        noalias(A) = prod( B, matrix_type( prod( C, matrix_type( prod( D, matrix_type( prod( E, F) ) ) ) ) ) );
        auto end = std::chrono::steady_clock::now();
        
        auto diff = end - start;
        times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration
    }

    double tmin = *(std::min_element(times.begin(), times.end()));
    double tavg = average_time(times);
    
    // check to see if nothing happened during run to invalidate the times
    if(variance(tavg, times) > max_variance){
        std::cerr << "boost kernel 'nestedprod': Time deviation too large! \n";
    }
    
    return tavg;
}
double cmajordmdmmult(size_t N, size_t iterations = 1){

    typedef mtl::tag::col_major col_major;
    typedef mtl::mat::parameters<col_major> parameters;
    typedef mtl::dense2D<value_type, parameters> dense2D;
    typedef mtl::dense_vector<value_type> dense_vector;
    
    dense2D A(N, N), B(N, N), C(N, N);
    
    minit(N, A);
    minit(N, B);
    
    std::vector<double> times;
    for(size_t i = 0; i < iterations; ++i){
        
        auto start = std::chrono::steady_clock::now();
        C = A * B;
        auto end = std::chrono::steady_clock::now();
        
        auto diff = end - start;
        times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration
    }
    
    double tmin = *(std::min_element(times.begin(), times.end()));
    double tavg = average_time(times);
  
    // check to see if nothing happened during run to invalidate the times
    if(variance(tavg, times) > max_variance){
        std::cerr << "mtl kernel 'cmajordmdmmult': Time deviation too large! \n";
    }

    return tavg;
    
}
Example #7
0
char *g95_intent_string(sym_intent u) {     
static mstring intents[] = {          
  minit("UNKNOWN-INTENT", INTENT_UNKNOWN),  minit("IN", INTENT_IN),          
  minit("OUT", INTENT_OUT),                 minit("INOUT", INTENT_INOUT),  
  minit(NULL, -1)          
};        
        
  return g95_code2string(intents, u);         
}  
Example #8
0
double dmatdmatmult(size_t N, size_t iterations = 1) {
    
    value_type** a = new value_type*[N];
    value_type** b = new value_type*[N];
    value_type** c = new value_type*[N];
    
    for(size_t i = 0; i < N; ++i){
        a[i] = new value_type[N];
        b[i] = new value_type[N];
        c[i] = new value_type[N];
    }
    
    minit(N, a);
    minit(N, b);
    
    std::vector<double> times;
    for(size_t i = 0; i < iterations; ++i){
        
        auto start = std::chrono::steady_clock::now();
        for(size_t i = 0; i < N; ++i) {
            for(size_t j = 0; j < N; ++j) {
                
                double sum = 0;
                for(size_t inner = 0; inner < N; ++inner) {
                    sum += a[i][inner] * b[inner][j];
                }
                
                c[i][j] = sum;
            }
        }
        auto end = std::chrono::steady_clock::now();
        
        auto diff = end - start;
        times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration
    }
    
    for(size_t i = 0; i < N; ++i){
        delete [] a[i];
        delete [] b[i];
        delete [] c[i];
    }
    
    delete [] a;
    delete [] b;
    delete [] c;
    
    double tmin = *(std::min_element(times.begin(), times.end()));
    double tavg = average_time(times);
    
    // check to see if nothing happened during run to invalidate the times
    if(variance(tavg, times) > max_variance){
        std::cerr << "clike kernel 'dmatdmatmult': Time deviation too large! \n";
    }
    
    return tavg;
    
}
Example #9
0
/*
** PSF driver main() replacement
*/
int psfdrv(void) {
  unsigned long seq_size = *((unsigned long *)MY_SEQ);

  /*
  ** Initialize and startup stuff
  */
  SetSp(0x800C58E4);
  SpuInit();
  minit();

  /*
  ** Load sound file for instrument set
  */
  mopen_file(MY_INSTR);

  /*
  ** Load sound file for sequence
  */
  if (seq_size != 0) {
    /* this call should always execute mopenplay_seq, since I modified mopen_file a lot */
    mopen_file(MY_SEQ);

    mplay_seq(MY_SEQ, 0x1200);
  }
  else {
    die();
  }

  /*
  ** Loop a while.
  */
  loopforever();

  return 0;
}
Example #10
0
double syr2krect(size_t N, size_t iterations = 1){
    
    Eigen::Matrix<value_type, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> A(N, size_t(1.5*N)), B(N, size_t(1.5*N)), C(N, N);
    value_type c = 3, d = 5;
    
    rminit(N, 1.5*N, A);
    rminit(N, 1.5*N, B);
    minit(N, C);

    std::vector<double> times;
    for(size_t i = 0; i < iterations; ++i){
        
        auto start = std::chrono::steady_clock::now();
        //C = c * B * A.transpose() + c * A * B.transpose() + d * C;
        C *= d;
        C += c * A * B.transpose();
        C += c * B * A.transpose();
        auto end = std::chrono::steady_clock::now();
        
        auto diff = end - start;
        times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration
    }
    
    double tmin = *(std::min_element(times.begin(), times.end()));
    double tavg = average_time(times);
    
    // check to see if nothing happened during run to invalidate the times
    if(variance(tavg, times) > max_variance){
        std::cerr << "eigen kernel 'syr2krect': Time deviation too large! \n";
    }
    
    return tavg;
    
}
Example #11
0
File: med.c Project: paud/d2x-xl
void init_editor()
{
	minit();

	ui_init();

	init_med_functions();	// Must be called before medlisp_init

	ui_pad_read( 0, "segmove.pad" );
	ui_pad_read( 1, "segsize.pad" );
	ui_pad_read( 2, "curve.pad" );
	ui_pad_read( 3, "texture.pad" );
	ui_pad_read( 4, "tObject.pad" );
	ui_pad_read( 5, "objmov.pad" );
	ui_pad_read( 6, "group.pad" );
	ui_pad_read( 7, "lighting.pad" );
	ui_pad_read( 8, "test.pad" );

	medKeyInit();

	editor_font = GrInitFont( "pc8x16.fnt" );

	menubar_init( "MED.MNU" );

	canv_offscreen = GrCreateCanvas(LVIEW_W,LVIEW_H);

	Draw_all_segments = 1;						// Say draw all segments, not just connected ones

	init_autosave();
  
//	atexit(close_editor);

	nClearWindow = 1;	//	do full window clear.
}
Example #12
0
// Called to start an M.
void
runtime·mstart(void)
{
    // It is used by windows-386 only. Unfortunately, seh needs
    // to be located on os stack, and mstart runs on os stack
    // for both m0 and m.
    SEH seh;

    if(g != m->g0)
        runtime·throw("bad runtime·mstart");

    // Record top of stack for use by mcall.
    // Once we call schedule we're never coming back,
    // so other calls can reuse this stack space.
    runtime·gosave(&m->g0->sched);
    m->g0->sched.pc = (void*)-1;  // make sure it is never used
    m->seh = &seh;
    runtime·asminit();
    runtime·minit();

    // Install signal handlers; after minit so that minit can
    // prepare the thread to be able to handle the signals.
    if(m == &runtime·m0)
        runtime·initsig();

    schedule(nil);

    // TODO(brainman): This point is never reached, because scheduler
    // does not release os threads at the moment. But once this path
    // is enabled, we must remove our seh here.
}
Example #13
0
double gemv2(size_t N, size_t iterations = 1){
    
    Eigen::Matrix<value_type, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> A(N, N);
    Eigen::Matrix<value_type, Eigen::Dynamic, 1> a(N), b(N);
    value_type c = 3, d = 5;
    
    vinit(a.rows(), a);
    vinit(b.rows(), b);
    minit(A.rows(), A);

    std::vector<double> times;
    for(size_t i = 0; i < iterations; ++i){
        
        auto start = std::chrono::steady_clock::now();
        b = c * A.transpose() * a + d * b;
        auto end = std::chrono::steady_clock::now();
        
        auto diff = end - start;
        times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration
    }
    
    double tmin = *(std::min_element(times.begin(), times.end()));
    double tavg = average_time(times);
    
    // check to see if nothing happened during run to invalidate the times
    if(variance(tavg, times) > max_variance){
        std::cerr << "eigen kernel 'gemv2': Time deviation too large! \n";
    }
    
    return tavg;
    
}
double dmatvecmult(size_t N, size_t iterations = 1) {
    
    boost::numeric::ublas::matrix<double> a(N, N);
    boost::numeric::ublas::vector<double> b(N), c(N);
    
    minit(a.size1(), a);
    vinit(b.size(), b);
    
    std::vector<double> times;
    for(size_t i = 0; i < iterations; ++i){
        
        auto start = std::chrono::steady_clock::now();
        boost::numeric::ublas::axpy_prod(a, b, c, false);
        auto end = std::chrono::steady_clock::now();
        
        auto diff = end - start;
        times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration
    }
    
    double tmin = *(std::min_element(times.begin(), times.end()));
    double tavg = average_time(times);
    /*
     // check to see if nothing happened during rum to invalidate the times
     if(tmin*(1.0 + deviation*0.01) < tavg){
     std::cerr << "uBLAS kernel 'dmatvecmult': Time deviation too large!!!" << std::endl;
     }
     */
    return tavg;
    
}
double dmatscalarmult(size_t N, size_t iterations = 1) {
    
    mtl::dense2D<value_type> a(N, N), b(N, N);
    value_type c = 3;
    
    minit(N, b);
    
    std::vector<double> times;
    for(size_t i = 0; i < iterations; ++i){
        
        auto start = std::chrono::steady_clock::now();
        a = b * c;
        auto end = std::chrono::steady_clock::now();
        
        auto diff = end - start;
        times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration
    }
    
    double tmin = *(std::min_element(times.begin(), times.end()));
    double tavg = average_time(times);
    
    // check to see if nothing happened during run to invalidate the times
    if(variance(tavg, times) > max_variance){
        std::cerr << "mtl kernel 'dmatscalarmult': Time deviation too large! \n";
    }
    
    return tavg;
    
}
Example #16
0
/**
 * load a lib
 */
void slib_import(const char *name, const char *fullname) {
#if defined(LNX_EXTLIB) || defined(WIN_EXTLIB)
  slib_t *lib;
  int (*minit) (void);
  const char *(*get_module_name) (void);
  int mok = 0;
  int name_index = 0;

  if (strncmp(name, "lib", 3) == 0) {
    // libmysql -> store mysql
    name_index = 3;
  }

  lib = &slib_table[slib_count];
  memset(lib, 0, sizeof(slib_t));
  strncpy(lib->name, name + name_index, 255);
  strncpy(lib->fullname, fullname, 1023);
  lib->id = slib_count;

  if (!opt_quiet) {
    log_printf("lib: importing %s", fullname);
  }
  if (slib_llopen(lib)) {
    mok = 1;

    // init
    minit = slib_getoptptr(lib, "sblib_init");
    if (minit) {
      if (!minit()) {
        mok = 0;
        log_printf("lib: %s->sblib_init(), failed", lib->name);
      }
    }

    // override default name
    get_module_name = slib_getoptptr(lib, "sblib_get_module_name");
    if (get_module_name) {
      strncpy(lib->name, get_module_name(), 255);
    }

    slib_import_routines(lib);
    mok = 1;
  }
  else {
    log_printf("lib: can't open %s", fullname);
  }
  if (mok) {
    slib_count++;
    if (!opt_quiet) {
      log_printf("... done\n");
    }
  }
  else {
    if (!opt_quiet) {
      log_printf("... error\n");
    }
  }
#endif
}
Example #17
0
File: test.c Project: paud/d2x-xl
main()
{
	minit();
	mclear(0);

	macro_test();

}
Example #18
0
void delayed_start(void *arg)
{
	if (wifi_station_get_connect_status() != STATION_GOT_IP) return;

	os_timer_disarm(&delayed_start_timer);
    os_printf("wifi connected in client mode, starting mdns and ntp.\n");
    minit();
    ninit();
}
Example #19
0
int main(int argc, char *argv[])
{
  minit(argc,argv);
  pingpong(0);
  mloop();
  pingpong(2);
  mexit();
  return(0);
}
Example #20
0
void *malloc(size_t size)
{
    register PACKET *current;
    register size_t  newsize;
    register size_t  oldsize;

    if (size <= 0) return NULL;

    if (check_alloc_size(size) == 0) return 0;

    if (need_mem_init)  minit();

    _lock();

    /*-----------------------------------------------------------------------*/
    /* SIZE IS CALCULATED BY FIRST ALIGNING (SIZE + BLOCK OVERHEAD) TO THE   */
    /* REQUIRED MINIMUM ALIGNMENT AND THEN SUBTRACTING THE BLOCK OVERHEAD.   */
    /*-----------------------------------------------------------------------*/
    newsize = _M_RNDUP((size + _M_BLOCK_OVERHEAD), _M_MIN_ALN) - 
	                                                    _M_BLOCK_OVERHEAD;

    current = sys_free;

    /*-----------------------------------------------------------------------*/
    /* SCAN THROUGH FREE LIST FOR PACKET LARGE ENOUGH TO CONTAIN PACKET      */
    /*-----------------------------------------------------------------------*/
    while (current && current->packet_size < newsize)
       current = current->size_ptr;

    if (!current)
    {
	_unlock();
	return NULL;
    }
    
    oldsize = current->packet_size;	    /* REMEMBER OLD SIZE	     */
    mremove(current);		            /* REMOVE PACKET FROM FREE LIST  */

    /*-----------------------------------------------------------------------*/
    /* IF PACKET IS LARGER THAN NEEDED, FREE EXTRA SPACE AT END	             */
    /* BY INSERTING REMAINING SPACE INTO FREE LIST.			     */
    /*-----------------------------------------------------------------------*/
    if (oldsize - newsize >= (_M_MIN_BLOCK + _M_BLOCK_OVERHEAD))
    {
       register PACKET *next = 
	       (PACKET *) ((char *) current + _M_BLOCK_OVERHEAD + newsize);
 
       next->packet_size    = oldsize - newsize - _M_BLOCK_OVERHEAD;
       minsert(next);
       current->packet_size = newsize;
    }

   current->packet_size |= _M_BLOCK_USED;
   _unlock();
   return (char *)current + _M_BLOCK_OVERHEAD;
}
Example #21
0
int
main (void) {
  man_t man = minit(1000);
  void* p1 = malloc(man, 20);
  void* p2 = malloc(man, 20);
  void* p3 = malloc(man, 20);
  void* p4 = malloc(man, 20);
  mfree(man, p1);
  mfree(man, p3);
  return 0;
}
Example #22
0
void memmap()
{
    PACKET *current;
    int free_block_num		= 0;
    int free_block_space	= 0;
    int free_block_max		= 0;
    int used_block_num		= 0;
    int used_block_space	= 0;
    int used_block_max		= 0;

    if (need_mem_init)  minit();

    _lock();

    current = _M_SYS_FIRST;

    /*-----------------------------------------------------------------------*/
    /* LOOP THROUGH ALL PACKETS                                              */
    /*-----------------------------------------------------------------------*/
    while (current < (PACKET *) &heap_mem[_memory_size-_M_BLOCK_OVERHEAD]) 
    {
	int size = current->packet_size & ~_M_BLOCK_USED;
        int used = current->packet_size & _M_BLOCK_USED;

        printf(">> Used:%1d size:%d addr:%x\n", used, size, current);

        if (used)
	{
	    used_block_num++;
	    used_block_space += size;
	    used_block_max   = MAX(used_block_max, size);
	}
	else
	{
	    free_block_num++;
	    free_block_space += size;
	    free_block_max   = MAX(free_block_max, size);
	}

        current = (PACKET *)((char *)current + size + _M_BLOCK_OVERHEAD);
    }

    printf("fr_nm:%d fr_sp:%d fr_mx:%d us_nm:%d us_sp:%d us_mx:%d ovr:%d\n\n", 
	    free_block_num, free_block_space, free_block_max,
	    used_block_num, used_block_space, used_block_max,
	    (free_block_num + used_block_num) * _M_BLOCK_OVERHEAD);

    _unlock();
    fflush(stdout);
}
Example #23
0
File: proc.c Project: rlcook0/go
// Called to start an M.
void
runtime·mstart(void)
{
	if(g != m->g0)
		runtime·throw("bad runtime·mstart");

	// Record top of stack for use by mcall.
	// Once we call schedule we're never coming back,
	// so other calls can reuse this stack space.
	runtime·gosave(&m->g0->sched);
	m->g0->sched.pc = (void*)-1;  // make sure it is never used
	runtime·asminit();
	runtime·minit();
	schedule(nil);
}
Example #24
0
// Called to start an M.
void
runtime·mstart(void)
{
	if(g != m->g0)
		runtime·throw("bad runtime·mstart");

	// Record top of stack for use by mcall.
	// Once we call schedule we're never coming back,
	// so other calls can reuse this stack space.
	runtime·gosave(&m->g0->sched);
	m->g0->sched.pc = (void*)-1;  // make sure it is never used
	runtime·asminit();
	runtime·minit();

	// Install signal handlers; after minit so that minit can
	// prepare the thread to be able to handle the signals.
	if(m == &runtime·m0)
		runtime·initsig();

	schedule(nil);
}
Example #25
0
main(int argc, char * argv[] )
{
	int x, y;
	grs_bitmap bmp;
	grs_bitmap bmp1;
	ubyte palette[768];

	minit();

	printf( "Reading %s...\n", "john.pcx" );
	gr_init( SM_320x200U );
	bmp.bm_data = NULL;
	pcx_read_bitmap( "big.pcx", &bmp, BM_LINEAR, palette );
	gr_palette_load( palette );
	key_init();

	x = y = 0;
	while(!keyd_pressed[KEY_ESC]) {
		y += keyd_pressed[KEY_UP] - keyd_pressed[KEY_DOWN];
		x += keyd_pressed[KEY_LEFT] - keyd_pressed[KEY_RIGHT];
		gr_bitmap( x, y, &bmp );
	}

}
Example #26
0
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with G95; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

#include "g95.h"


static int show_level=0;


static mstring array_specs[] = {
    minit("EXPLICIT",       AS_EXPLICIT),
    minit("ASSUMED-SHAPE",  AS_ASSUMED_SHAPE),
    minit("DEFERRED",       AS_DEFERRED),
    minit("ASSUMED-SIZE",   AS_ASSUMED_SIZE),
    minit(NULL, 0) };


void show_code(int, g95_code *);



/* show_actual_arglist()-- Show an actual argument list */

static void show_actual_arglist(g95_actual_arglist *a) {

    g95_status_char('[');
Example #27
0
void *malloc(size_t size)
{
    memsz_t allocsize;
    PACKET *current, *next, *prev;

    if (check_alloc_size(size) == 0) return 0;

    allocsize = (memsz_t)size;

    if (allocsize == 0) return 0;

    /*-----------------------------------------------------------------------*/
    /* We may need to adjust the size of the allocation request to ensure    */
    /* that the address of the field "next_free" remains strictly aligned    */
    /* in all packets on the free list.					     */
    /*-----------------------------------------------------------------------*/
    if ((allocsize ^ OVERHEAD) & 1) ++allocsize;

    _lock();

    if (first_call) minit();

    current = sys_free;
    prev = 0;

    /*-----------------------------------------------------------------------*/
    /* Find the first block large enough to hold the requested allocation    */
    /*-----------------------------------------------------------------------*/
    while (current != LIMIT && -current->packet_size < allocsize)
    {
	prev = current;
	current = current->next_free;
    }

    if (current == LIMIT)
    {
        /*-------------------------------------------------------------------*/
        /* No block large enough was found, so return NULL.		     */
        /*-------------------------------------------------------------------*/
	_unlock();
	return 0;
    }

    if (-current->packet_size > (allocsize + OVERHEAD + MINSIZE))
    {
        /*-------------------------------------------------------------------*/
        /* The packet is larger than needed; split the block and mark the    */
        /* smaller-addressed block as used.  The smaller-addressed block     */
        /* was chosen as a way to ensure that freed blocks get recycled	     */
        /* before allocations are made from the large original free block.   */
        /* However, this may tend to increase the length of the free list    */
        /* search for a large enough block.				     */
        /*-------------------------------------------------------------------*/
        /* Knuth's algorithm 2.5a instead allocates the larger-addressed     */
        /* block to the user.  This tends to leave the largest free blocks   */
        /* at the beginning of the free list.  Knuth's 2.5a' uses a "rover"  */
        /* pointer to prevent small free blocks from being concentrated in   */
        /* any part of the list.					     */
        /*-------------------------------------------------------------------*/
	next = (PACKET *)((char *)current + allocsize + OVERHEAD);
	next->packet_size=current->packet_size+allocsize+OVERHEAD;/*NEG==FREE*/
#ifdef DEBUG
	next->guard = GUARDWORD;
#endif
	current->packet_size = allocsize; /* POSITIVE==IN USE */

	if (prev) prev->next_free = next;
	else      sys_free        = next;

	next->next_free = current->next_free;
    }
    else
    {
        /*-------------------------------------------------------------------*/
        /* Allocate the whole block and remove it from the free list.	     */
        /*-------------------------------------------------------------------*/
	if (prev) prev->next_free = current->next_free;
	else      sys_free        = current->next_free;

	current->packet_size = -current->packet_size; /* POSITIVE==IN USE */
    }

    _unlock();
    return &(current->next_free);
}
Example #28
0
uint64_t mutex_init(mutex * m){
	return minit(m,NULL)->id;
}
Example #29
0
uint64_t mutex_nameinit(mutex * m,uint8_t * name){
	if(mutex_getbyname(name)!=NULL){
		return -1;
	}
	return minit(m,name)->id;
}
Example #30
0
int
init_suite_mman(void)
{
  man = minit(MMAN_CAPACITY);
  return 0;
}