stardis-solver

Solve coupled heat transfers
git clone git://git.meso-star.fr/stardis-solver.git
Log | Files | Refs | README | LICENSE

sdis_tile.c (1940B)


      1 /* Copyright (C) 2016-2025 |Méso|Star> (contact@meso-star.com)
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #include "sdis_tile.h"
     17 
     18 /*******************************************************************************
     19  * Helper functions
     20  ******************************************************************************/
     21 static INLINE void
     22 release_tile(ref_T* ref)
     23 {
     24   struct tile* tile = CONTAINER_OF(ref, struct tile, ref);
     25   ASSERT(ref);
     26   MEM_RM(tile->allocator, tile);
     27 }
     28 
     29 /*******************************************************************************
     30  * Helper functions
     31  ******************************************************************************/
     32 res_T
     33 tile_create(struct mem_allocator* allocator, struct tile** out_tile)
     34 {
     35   struct tile* tile = NULL;
     36   res_T res = RES_OK;
     37   ASSERT(allocator && out_tile);
     38 
     39   tile = MEM_ALLOC_ALIGNED(allocator, sizeof(*tile), 16);
     40   if(!tile) { res = RES_MEM_ERR; goto error; }
     41 
     42   ref_init(&tile->ref);
     43   list_init(&tile->node);
     44   tile->allocator = allocator;
     45   memset(&tile->data, 0, sizeof(tile->data));
     46 exit:
     47   *out_tile = tile;
     48   return res;
     49 error:
     50   if(tile) { tile_ref_put(tile); tile = NULL; }
     51   goto exit;
     52 }
     53 
     54 void
     55 tile_ref_get(struct tile* tile)
     56 {
     57   ASSERT(tile);
     58   ref_get(&tile->ref);
     59 }
     60 
     61 void
     62 tile_ref_put(struct tile* tile)
     63 {
     64   ASSERT(tile);
     65   ref_put(&tile->ref, release_tile);
     66 }
     67