]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/commitdiff
Added the freelist module that implements a list of free cells in a
authormgh <mgh@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Tue, 17 Jul 2007 07:53:43 +0000 (07:53 +0000)
committermgh <mgh@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Tue, 17 Jul 2007 07:53:43 +0000 (07:53 +0000)
table

git-svn-id: http://www.frescor.org/private/svn/frescor/frsh/trunk/include@540 35b4ef3e-fd22-0410-ab77-dab3279adceb

frsh_freelist.h [new file with mode: 0644]

diff --git a/frsh_freelist.h b/frsh_freelist.h
new file mode 100644 (file)
index 0000000..a10f64f
--- /dev/null
@@ -0,0 +1,103 @@
+// -----------------------------------------------------------------------
+//  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
+//
+//    Universidad de Cantabria,              SPAIN
+//    University of York,                    UK
+//    Scuola Superiore Sant'Anna,            ITALY
+//    Kaiserslautern University,             GERMANY
+//    Univ. Politécnica  Valencia,           SPAIN
+//    Czech Technical University in Prague,  CZECH REPUBLIC
+//    ENEA                                   SWEDEN
+//    Thales Communication S.A.              FRANCE
+//    Visual Tools S.A.                      SPAIN
+//    Rapita Systems Ltd                     UK
+//    Evidence                               ITALY
+//
+//    See http://www.frescor.org for a link to partners' websites
+//
+//           FRESCOR project (FP6/2005/IST/5-034026) is funded
+//        in part by the European Union Sixth Framework Programme
+//        The European Union is not liable of any use that may be
+//        made of this code.
+//
+//
+//  This file is part of FRSH Implementation
+//
+//  FRSH API is free software; you can  redistribute it and/or  modify
+//  it under the terms of  the GNU General Public License as published by
+//  the Free Software Foundation;  either  version 2, or (at  your option)
+//  any later version.
+//
+//  FRSH API  is distributed  in  the hope  that  it  will  be useful,  but
+//  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
+//  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
+//  distributed  with  FRSH API;  see file COPYING.   If not,  write to the
+//  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
+//  02111-1307, USA.
+//
+//  As a special exception, if you include this header file into source
+//  files to be compiled, this header file does not by itself cause
+//  the resulting executable to be covered by the GNU General Public
+//  License.  This exception does not however invalidate any other
+//  reasons why the executable file might be covered by the GNU General
+//  Public License.
+// -----------------------------------------------------------------------
+//==============================================
+//  ******** *******    ********  **      **
+//  **///// /**////**  **//////  /**     /**
+//  **      /**   /** /**        /**     /**
+//  ******* /*******  /********* /**********
+//  **////  /**///**  ////////** /**//////**
+//  **      /**  //**        /** /**     /**
+//  **      /**   //** ********  /**     /**
+//  //       //     // ////////   //      //
+//
+// FRSH(FRescor ScHeduler), pronounced "fresh"
+//==============================================
+//
+
+// This header file defines the interface to a pair of functions used
+// to manage a sinly linked list that is used to find free cells in
+// some external table.
+//
+// Parallel to the external table, there is a table of indexes
+// organized as a singly linked list; it is the free list. A separate
+// index, free_cell, indicates which is the first element of the sibly
+// linked list. The list is terminated with an index of -1.
+
+
+#ifndef FRSH_FREELIST
+#define FRSH_FREELIST
+
+typedef struct {
+  int * freelist;
+  int first_free;
+} frsh_freelist_t;
+
+/**
+ *  Initialize a free list adding all the cells to the list of free cells
+ *  The size of the list is specified by size.
+ *  Returns: 0 if successful
+ *           FRSH_ERR_NO_SPACE if there is not enough memory available
+ */
+int frsh_freelist_init(frsh_freelist_t *list, int size);
+
+/**
+ *  Obtain the index of a free cell from the free list specified by list
+ *  the cell is removed from the list 
+ *  Returns the index to the requested cell, or -1 if there are no free cells
+ */
+int frsh_freelist_alloc(frsh_freelist_t *list);
+
+
+/**
+ * Deallocate the cell specified by index cell adding it to the list
+ * of free cells specified by list
+ * Returns 0 if successful, or -1 if the cell was not free
+ */
+int frsh_freelist_free(frsh_freelist_t *list, int cell);
+
+#endif // FRSH_FREELIST