1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-07-01 15:20:34 +02:00
guile/libguile/atomic.h
Andy Wingo 9290698977 Move atomic box off of scm_cell
* libguile/Makefile.am:
* libguile/atomic.h: Make private.  Define "struct scm_atomic_box".
* libguile/atomic.c: Allocate scm_atomic_box via scm_allocate_tagged.
2025-06-20 16:23:02 +02:00

81 lines
2 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef SCM_ATOMIC_H
#define SCM_ATOMIC_H
/* Copyright 2016,2018,2025
Free Software Foundation, Inc.
This file is part of Guile.
Guile is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Guile 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 Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Guile. If not, see
<https://www.gnu.org/licenses/>. */
#include "libguile/gc.h"
/* Atomic boxes
*/
struct scm_atomic_box
{
scm_t_bits tag;
SCM value;
};
static inline int
scm_is_atomic_box (SCM x)
{
return SCM_HAS_TYP7 (x, scm_tc7_atomic_box);
}
static inline struct scm_atomic_box *
scm_to_atomic_box (SCM x)
{
if (!scm_is_atomic_box (x))
abort ();
return (struct scm_atomic_box *) SCM_UNPACK_POINTER (x);
}
static inline SCM
scm_from_atomic_box (struct scm_atomic_box *box)
{
return SCM_PACK_POINTER (box);
}
static inline SCM*
scm_atomic_box_loc (struct scm_atomic_box *box)
{
return &box->value;
}
#define SCM_VALIDATE_ATOMIC_BOX(pos, var) \
do { \
SCM_ASSERT_TYPE (scm_is_atomic_box (var), var, pos, FUNC_NAME, \
"atomic box"); \
} while (0)
SCM_INTERNAL SCM scm_make_atomic_box (SCM init);
SCM_INTERNAL SCM scm_atomic_box_p (SCM obj);
SCM_INTERNAL SCM scm_atomic_box_ref (SCM box);
SCM_INTERNAL SCM scm_atomic_box_set_x (SCM box, SCM val);
SCM_INTERNAL SCM scm_atomic_box_swap_x (SCM box, SCM val);
SCM_INTERNAL SCM scm_atomic_box_compare_and_swap_x (SCM box, SCM expected, SCM desired);
SCM_INTERNAL void scm_i_atomic_box_print (SCM box, SCM port, scm_print_state *pstate);
SCM_INTERNAL void scm_register_atomic (void);
#endif /* SCM_ATOMIC_H */