solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit 9d33f8d47feb43b0d7f3f7368eb07a3e888587fb
parent 6d6a89e511d960d84ac1cd085e5ee1a3a820130d
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu, 23 Jun 2016 18:07:45 +0200

First try at ssol_device.

Specific content of the device still missing, though.

Diffstat:
Asrc/ssol_device.c | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ssol_device_c.h | 32++++++++++++++++++++++++++++++++
2 files changed, 125 insertions(+), 0 deletions(-)

diff --git a/src/ssol_device.c b/src/ssol_device.c @@ -0,0 +1,93 @@ +/* Copyright (C) CNRS 2016 + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "ssol.h" +#include "ssol_device_c.h" + +#include <rsys/logger.h> +#include <rsys/mem_allocator.h> + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +device_release(ref_T* ref) +{ + struct ssol_device* dev; + ASSERT(ref); + dev = CONTAINER_OF(ref, struct ssol_device, ref); + + MEM_RM(dev->allocator, dev); +} + +/******************************************************************************* + * Exported ssol_device functions + ******************************************************************************/ +res_T +ssol_device_create + (struct logger* logger, + struct mem_allocator* mem_allocator, + const unsigned nthreads_hint, + const int verbose, + struct ssol_device** out_dev) +{ + struct ssol_device* dev = NULL; + struct mem_allocator* allocator; + res_T res = RES_OK; + + if(nthreads_hint == 0 || !out_dev) { + res = RES_BAD_ARG; + goto error; + } + + allocator = mem_allocator ? mem_allocator : &mem_default_allocator; + dev = (struct ssol_device*)MEM_CALLOC(allocator, 1, sizeof(struct ssol_device)); + if(!dev) { + res = RES_MEM_ERR; + goto error; + } + dev->logger = logger ? logger : LOGGER_DEFAULT; + dev->allocator = allocator; + dev->verbose = verbose; + + ref_init(&dev->ref); + +exit: + if(out_dev) *out_dev = dev; + return res; +error: + if(dev) { + SSOL(device_ref_put(dev)); + dev = NULL; + } + goto exit; +} + +res_T +ssol_device_ref_get(struct ssol_device* dev) +{ + if(!dev) return RES_BAD_ARG; + ref_get(&dev->ref); + return RES_OK; +} + +res_T +ssol_device_ref_put(struct ssol_device* dev) +{ + if(!dev) return RES_BAD_ARG; + ref_put(&dev->ref, device_release); + return RES_OK; +} + diff --git a/src/ssol_device_c.h b/src/ssol_device_c.h @@ -0,0 +1,32 @@ +/* Copyright (C) CNRS 2016 + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SSOL_DEVICE_C_H +#define SSOL_DEVICE_C_H + +#include <rsys/ref_count.h> +#include <rsys/free_list.h> + +struct ssol_device { + struct logger* logger; + struct mem_allocator* allocator; + const unsigned nthreads_hint; + int verbose; + + ref_T ref; +}; + +#endif /* SSOL_DEVICE_C_H */ +