jere-software / bullfrog

Library containing various Ada utilities
Mozilla Public License 2.0
1 stars 1 forks source link

Bullfrog Ada Library

Introduction

The Bullfrog library is an collection of various Ada packages, some useful and some just for play. It includes packages that work with access types, containers, tasking, and low level memory access.

License

This project is licensed under the Mozilla Public License (version 2.0). A local copy of the license is available in this repository. It can also be found at https://mozilla.org/MPL/2.0/

Platforms

The Bullfrog library currently builds and runs under mingw64 x86_64 FSF GNAT 13.2. I have not tested on linux or with other compilers than GNAT. The following platforms have been tested:

Windows 11

Linux

Building

Components

Smart_Access Types

In the Bullfrog.Access_Types.Smart_Access and Bullfrog.Access_Types.Advanced_Smart_Access packages, the Bullfrog library provides a variety of types designed to make memory management as automatic as possible. These are intended to be "building block" types and not client facing types. In a basic sense, the 3 primary types are:

Smart_Access types don't have atomic reference counting by default. This can be turned on when instantiating the generic if using them in a multithreaded context. Even when atomic reference counts are enabled, the Smart_Access types are not themselves task safe, nor are the resources task safe. Protected objects or other primatives must be used to achieve task safety in those two contexts.

The main differences between the Smart_Access and Advanced_Smart_Access packages is that the Smart_Access package is intended to be used with most types while the various Advanced_Smart_Access packages are intended to be used with incomplete formal types and/or types that need custom storage pools. In 99% of applications, the Smart_Access will probably be the package of choice. Only use the Advanced_Smart_Access package if:


Circular_Buffer Types

In the Bullfrog.Containers.Circular_Buffers package, the library provdes a 1 consumer to 1 producer lock free circular buffer. In the majority of cases where two threads share a buffer, a protected object wrapping the buffer is the correct method. however, there are instances where either you can't use protected objects (some runtimes restrict this) or you find that a lock free alternative is better. This package provides this functionality as long as there is only one consumer and one producer. If the program is single threaded, use a regular non synchronized buffer. If the program has either more than one consumer or more than one producer, look for other alternatives such as a protected buffer.


Sync_Wrapper types

In the Bullfrog.Synchronization.Sync_Wrappers package, the Bullfrog library provides a wrapper type that can be used to quickly add synchronization to another more complex type that doesn't provide it by default. To use the package, simply instantiate a generic with the type that you want and create a variable with the type from the generic. You then can call variable_name.lock.some_operation_or_variable and it will autmoatically add synchronization around the call. There are some known bugs in GNAT when doing this in a declarative region though, so keep an eye for any if you use this package. They will manifest as deadlocks (Essentially GNAT doesn't always call Finalize on objects in certain situations).


Endianess Functionality

In the Bullfrog.Endianess package, the library provides a means to detect what type of byte order your system uses. The Ada language does not provide this standard. It only covers bit order (which is not the same and rarely an issue for modern processors). It defines a type and a constant (elaborated at runtime) to indicate what byte order you system currently uses. If the system is not Big_Endian or Little_Endian, it is defaulted to Middle_Endian as a catch all.


Modular_To_Array_Conversions operations

In the Bullfrog.Modular_To_Array_Conversions package, the library provides may operations designed to convert from the multibyte Unsigned_x types found in the Interfaces package of the Ada stanadard library to arrays of Unsigned_8 values. This is useful in both interfacing to hardware registers and also creating/parsing message interfaces. The package provides four different contexts for the conversions:


Reference_Counts Types

In the Bullfrog.Access_Types.Reference_Counts package, the library provides a utility type that provides "reference counting" functionality with the option to either include or exclude atomic operations as the mechanism.


Mutexes Types

In the Bullfrog.Synchronization.Mutexes package, the library provides both a basic mutex type and a recursive mutex type for utility operations in other packages:


Test and Debug Folders

These folders hold various tests and debug packages used by the tests to verify functionality. They aren't written to the same coding standard as the library (this will be fixed one day). They might also be useful for finding examples. There is a separate GNAT project file for compiling the tests.

Legal Stuff

Warranty and Liablity sections for this project (pulled from the license document):


************************************************************************
*                                                                      *
*  6. Disclaimer of Warranty                                           *
*  -------------------------                                           *
*                                                                      *
*  Covered Software is provided under this License on an "as is"       *
*  basis, without warranty of any kind, either expressed, implied, or  *
*  statutory, including, without limitation, warranties that the       *
*  Covered Software is free of defects, merchantable, fit for a        *
*  particular purpose or non-infringing. The entire risk as to the     *
*  quality and performance of the Covered Software is with You.        *
*  Should any Covered Software prove defective in any respect, You     *
*  (not any Contributor) assume the cost of any necessary servicing,   *
*  repair, or correction. This disclaimer of warranty constitutes an   *
*  essential part of this License. No use of any Covered Software is   *
*  authorized under this License except under this disclaimer.         *
*                                                                      *
************************************************************************

************************************************************************
*                                                                      *
*  7. Limitation of Liability                                          *
*  --------------------------                                          *
*                                                                      *
*  Under no circumstances and under no legal theory, whether tort      *
*  (including negligence), contract, or otherwise, shall any           *
*  Contributor, or anyone who distributes Covered Software as          *
*  permitted above, be liable to You for any direct, indirect,         *
*  special, incidental, or consequential damages of any character      *
*  including, without limitation, damages for lost profits, loss of    *
*  goodwill, work stoppage, computer failure or malfunction, or any    *
*  and all other commercial damages or losses, even if such party      *
*  shall have been informed of the possibility of such damages. This   *
*  limitation of liability shall not apply to liability for death or   *
*  personal injury resulting from such party's negligence to the       *
*  extent applicable law prohibits such limitation. Some               *
*  jurisdictions do not allow the exclusion or limitation of           *
*  incidental or consequential damages, so this exclusion and          *
*  limitation may not apply to You.                                    *
*                                                                      *
************************************************************************