/* * Copyright (c) 2019 AVM GmbH . * * 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 2 * 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 . */ #ifndef __OFFLOAD__HANDLES_H__ #define __OFFLOAD__HANDLES_H__ #include #include #define HANDLE_POOL_DECLARE(name, size) DECLARE_BITMAP(name, size) #define handle_request(candidate, pool) (!test_and_set_bit(candidate, pool)) static inline unsigned long handle_alloc(unsigned long *pool, unsigned long size) { unsigned long candidate; do { candidate = find_first_zero_bit(pool, size); } while (candidate < size && test_and_set_bit(candidate, pool)); return candidate; } static inline void handle_free(unsigned long handle, unsigned long *pool) { clear_bit(handle, pool); } #endif // __OFFLOAD__HANDLES_H__