1    /*
     2     * Copyright (c) 2016, Texas Instruments Incorporated
     3     * https://www.ti.com
     4     * All rights reserved.
     5     *
     6     * Redistribution and use in source and binary forms, with or without
     7     * modification, are permitted provided that the following conditions
     8     * are met:
     9     *
    10     * *  Redistributions of source code must retain the above copyright
    11     *    notice, this list of conditions and the following disclaimer.
    12     *
    13     * *  Redistributions in binary form must reproduce the above copyright
    14     *    notice, this list of conditions and the following disclaimer in the
    15     *    documentation and/or other materials provided with the distribution.
    16     *
    17     * *  Neither the name of Texas Instruments Incorporated nor the names of
    18     *    its contributors may be used to endorse or promote products derived
    19     *    from this software without specific prior written permission.
    20     *
    21     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    22     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    23     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    24     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    25     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    26     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    27     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    28     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    29     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    30     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    31     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    32     * --/COPYRIGHT--*/
    33    /*
    34     *  ======== ThreadLocalStorage.xdc ========
    35     */
    36    
    37    import xdc.runtime.Types;
    38    import xdc.runtime.IHeap;
    39    import xdc.runtime.Error;
    40    import ti.sysbios.knl.Task;
    41    
    42    /*!
    43     *  ======== ThreadLocalStorage ========
    44     *  Thread-local RTS data support module
    45     *
    46     *  The ThreadLocalStorage module allows SYS/BIOS Tasks to maintain
    47     *  RTS data that is private to each Task.  RTS data includes, among
    48     *  other things, the errno variable from the RTS library and the C++
    49     *  exception stack.
    50     *
    51     *  This support is achieved by way of per-Task "TLS" data areas and
    52     *  a Task switch hook function that tracks the current Task's TLS
    53     *  data area on behalf of the RTS library code.
    54     *
    55     *  Currently requires use of the --multithreaded option for the CG tools
    56     *  compiler.
    57     */
    58    
    59    @DirectCall
    60    
    61    module ThreadLocalStorage
    62    {
    63        /*!
    64         *  ======== heapHandle ========
    65         *  Heap to use for TLS allocation. If null, uses the default Heap
    66         */
    67        config IHeap.Handle heapHandle = null;
    68    
    69        /*!
    70         *  ======== enableTLSSupport ========
    71         *  Enable TI TLS support
    72         */
    73        config Bool enableTLSSupport = false;
    74    
    75        /*!
    76         *  ======== TItlsSectMemory ========
    77         *  Memory section in which to place .TI.tls output data section
    78         */
    79        config String TItlsSectMemory = null;
    80    
    81        /*!
    82         *  ======== TItls_initSectMemory ========
    83         *  Memory section in which to place .TI.tls_init output data section
    84         */
    85        config String TItls_initSectMemory = null;
    86    
    87    internal:
    88        /*!
    89         *  ======== createFxn ========
    90         */
    91        Void createFxn(Task.Handle tsk, Error.Block *eb);
    92    
    93        /*!
    94         *  ======== switchFxn ========
    95         */
    96        Void switchFxn(Task.Handle from, Task.Handle to);
    97    
    98        /*!
    99         *  ======== deleteFxn ========
   100         */
   101        Void deleteFxn(Task.Handle tsk);
   102    
   103        /*!
   104         *  ======== registerFxn ========
   105         */
   106        Void registerFxn(Int id);
   107    
   108        struct Module_State {
   109            Ptr          currentTP;
   110            UInt         contextId;
   111            IHeap.Handle heapHandle;
   112        };
   113    }