(root)/
glib-2.79.0/
glib/
gbitlock.h
       1  /*
       2   * Copyright © 2008 Ryan Lortie
       3   * Copyright © 2010 Codethink Limited
       4   *
       5   * SPDX-License-Identifier: LGPL-2.1-or-later
       6   *
       7   * This library is free software; you can redistribute it and/or
       8   * modify it under the terms of the GNU Lesser General Public
       9   * License as published by the Free Software Foundation; either
      10   * version 2.1 of the License, or (at your option) any later version.
      11   *
      12   * This library is distributed in the hope that it will be useful,
      13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15   * Lesser General Public License for more details.
      16   *
      17   * You should have received a copy of the GNU Lesser General Public
      18   * License along with this library; if not, see <http://www.gnu.org/licenses/>.
      19   *
      20   * Author: Ryan Lortie <desrt@desrt.ca>
      21   */
      22  
      23  #ifndef __G_BITLOCK_H__
      24  #define __G_BITLOCK_H__
      25  
      26  #include <glib/gtypes.h>
      27  
      28  #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
      29  #error "Only <glib.h> can be included directly."
      30  #endif
      31  
      32  G_BEGIN_DECLS
      33  
      34  GLIB_AVAILABLE_IN_ALL
      35  void      g_bit_lock                      (volatile gint *address,
      36                                             gint           lock_bit);
      37  GLIB_AVAILABLE_IN_ALL
      38  gboolean  g_bit_trylock                   (volatile gint *address,
      39                                             gint           lock_bit);
      40  GLIB_AVAILABLE_IN_ALL
      41  void      g_bit_unlock                    (volatile gint *address,
      42                                             gint           lock_bit);
      43  
      44  GLIB_AVAILABLE_IN_ALL
      45  void      g_pointer_bit_lock              (volatile void *address,
      46                                             gint           lock_bit);
      47  GLIB_AVAILABLE_IN_ALL
      48  gboolean  g_pointer_bit_trylock           (volatile void *address,
      49                                             gint           lock_bit);
      50  GLIB_AVAILABLE_IN_ALL
      51  void      g_pointer_bit_unlock            (volatile void *address,
      52                                             gint           lock_bit);
      53  
      54  #ifdef __GNUC__
      55  
      56  #define g_pointer_bit_lock(address, lock_bit) \
      57    (G_GNUC_EXTENSION ({                                                       \
      58      G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer));                \
      59      g_pointer_bit_lock ((address), (lock_bit));                              \
      60    }))
      61  
      62  #define g_pointer_bit_trylock(address, lock_bit) \
      63    (G_GNUC_EXTENSION ({                                                       \
      64      G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer));                \
      65      g_pointer_bit_trylock ((address), (lock_bit));                           \
      66    }))
      67  
      68  #define g_pointer_bit_unlock(address, lock_bit) \
      69    (G_GNUC_EXTENSION ({                                                       \
      70      G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer));                \
      71      g_pointer_bit_unlock ((address), (lock_bit));                            \
      72    }))
      73  
      74  #endif
      75  
      76  G_END_DECLS
      77  
      78  #endif /* __G_BITLOCK_H_ */