1/* 2 * Copyright (c) 2012 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#ifndef CommonNumerics_cn_globals_h 25#define CommonNumerics_cn_globals_h 26 27 28/* 29 * cn_globals.h - CommonNumerics global DATA 30 */ 31 32#include <asl.h> 33#include <dispatch/dispatch.h> 34#include "crc.h" 35#include "basexx.h" 36#include "CommonCRC.h" 37 38#if __has_include(<os/alloc_once_private.h>) 39#include <os/alloc_once_private.h> 40#if defined(OS_ALLOC_ONCE_KEY_LIBCOMMONNUMERICS) && !defined(KERNEL) 41#define _LIBCOMMONNUMERICS_HAS_ALLOC_ONCE 1 42#endif 43#endif 44 45#define CN_SUPPORTED_CRCS kCN_CRC_64_ECMA_182+1 46#define CN_STANDARD_BASE_ENCODERS kCNEncodingBase16+1 47 48struct cn_globals_s { 49 // CommonCRC.c 50 dispatch_once_t crc_init; 51 crcInfo crcSelectionTab[CN_SUPPORTED_CRCS]; 52 dispatch_once_t basexx_init; 53 BaseEncoderFrame encoderTab[CN_STANDARD_BASE_ENCODERS]; 54}; 55typedef struct cn_globals_s *cn_globals_t; 56 57__attribute__((__pure__)) 58static inline cn_globals_t 59_cn_globals(void) { 60#if _LIBCOMMONNUMERICS_HAS_ALLOC_ONCE 61 return (cn_globals_t) os_alloc_once(OS_ALLOC_ONCE_KEY_LIBCOMMONNUMERICS, 62 sizeof(struct cn_globals_s), 63 NULL); 64#else 65 static struct cn_globals_s storage; 66 return &storage; 67#endif 68} 69 70#endif 71