gonzui


Format: Advanced Search

t2ex/t2ex_source/t2ex/load/src/pminfo.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T2EX Software Package
    4:  *
    5:  *    Copyright 2012 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2012/12/12.
   10:  *    Modified by T-Engine Forum at 2013/03/08.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/04.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: /*
   16:  * This software package is available for use, modification, 
   17:  * and redistribution in accordance with the terms of the attached 
   18:  * T-License 2.x.
   19:  * If you want to redistribute the source code, you need to attach 
   20:  * the T-License 2.x document.
   21:  * There's no obligation to publish the content, and no obligation 
   22:  * to disclose it to the TRON Forum if you have modified the 
   23:  * software package.
   24:  * You can also distribute the modified source code. In this case, 
   25:  * please register the modification to T-Kernel traceability service.
   26:  * People can know the history of modifications by the service, 
   27:  * and can be sure that the version you have inherited some 
   28:  * modification of a particular version or not.
   29:  *
   30:  *    http://trace.tron.org/tk/?lang=en
   31:  *    http://trace.tron.org/tk/?lang=ja
   32:  *
   33:  * As per the provisions of the T-License 2.x, TRON Forum ensures that 
   34:  * the portion of the software that is copyrighted by Ken Sakamura or 
   35:  * the TRON Forum does not infringe the copyrights of a third party.
   36:  * However, it does not make any warranty other than this.
   37:  * DISCLAIMER: TRON Forum and Ken Sakamura shall not be held
   38:  * responsible for any consequences or damages caused directly or
   39:  * indirectly by the use of this software package.
   40:  *
   41:  * The source codes in bsd_source.tar.gz in this software package are 
   42:  * derived from NetBSD or OpenBSD and not covered under T-License 2.x.
   43:  * They need to be changed or redistributed according to the 
   44:  * representation of each source header.
   45:  */
   46: 
   47: /*
   48:  *      pminfo.c
   49:  *
   50:  *       T2EX: program load functions
   51:  *       program module information
   52:  */
   53: 
   54: #include <basic.h>
   55: #include <errno.h>
   56: #include <sys/debug.h>
   57: #include "pminfo.h"
   58: 
   59: EXPORT  ProgInfo*        pmInfoTable = NULL;
   60: EXPORT  INT              pmInfoCount;
   61: LOCAL   QUEUE             pmFreeQue;
   62: 
   63: /*
   64:  * Initialize control block of program module information
   65:  */
   66: EXPORT ER pmInitInfo( INT n )
   67: {
   68:         ER     er;
   69:         INT    i;
   70: 
   71:         if ( n < 0 ) {
   72:                 er = EX_INVAL;
   73:                 goto err_ret;
   74:         }
   75: 
   76:         /* Allocate control block for program module information */
   77:         pmInfoTable = (ProgInfo*)Kcalloc(n, sizeof(ProgInfo));
   78:         if ( pmInfoTable == NULL ) {
   79:                 er = EX_NOMEM;
   80:                 goto err_ret;
   81:         }
   82: 
   83:         /* Initialize queue and count */
   84:         pmInfoCount = n;
   85:         QueInit(&pmFreeQue);
   86: 
   87:         /* Initialize program module information */
   88:         for ( i = 0; i < n; i++ ) {
   89:                 pmInfoTable[i].pmid = (i + 1);
   90:                 QueInsert(&(pmInfoTable[i].q), &pmFreeQue);
   91:         }
   92: 
   93:         return E_OK;
   94: 
   95: err_ret:
   96:         TM_DEBUG_PRINT(("pmInitInfo ercd = %d\n", er));
   97:         return er;
   98: }
   99: 
  100: /*
  101:  * Cleanup control block of program module information
  102:  *      Entries in used queue are not unloaded automatically;
  103:  *      thus needed to unload them before calling this function.
  104:  */
  105: EXPORT void pmCleanupInfo()
  106: {
  107:         Kfree(pmInfoTable);
  108:         pmInfoTable = NULL;
  109: }
  110: 
  111: /*
  112:  * Allocate a free program module information
  113:  */
  114: EXPORT ProgInfo* pmAllocInfo()
  115: {
  116:         ProgInfo*      prog;
  117: 
  118:         /* Get the first entry in free queue */
  119:         prog = (ProgInfo*)QueRemoveNext(&pmFreeQue);
  120: 
  121:         if ( prog ) {
  122:                 /* Mark the program as used */
  123:                 prog->used = TRUE;
  124:         }
  125: 
  126:         return prog;
  127: }
  128: 
  129: /*
  130:  * Deallocate program module information
  131:  */
  132: EXPORT void pmFreeInfo( ProgInfo* prog )
  133: {
  134:         /* Append to the end of free queue */
  135:         QueInsert(&(prog->q), &pmFreeQue);
  136: 
  137:         /* Mark the program as free */
  138:         prog->used = FALSE;
  139: }