This file is indexed.

/usr/include/sphde/sphlfentry.h is in libsphde-dev 1.3.0-1+b1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
/*
 * Copyright (c) 2011-2015 IBM Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation, Steven Munroe - initial API and implementation
 */

#ifndef __SPH_LOCK_FREE_ENTRY_H
#define __SPH_LOCK_FREE_ENTRY_H

/** \file sphlfentry.h
*  \brief Shared Persistent Heap, logger/queue etc event entry status,
*   update, and access functions.
*
*  \author Steven Munroe - initial API and implementation
*
*	For shared memory multi-thread/multi-core applications. Once the
*	Logger or Queue functions have atomically allocated an entry,
*	the "entry" APIs supports adding additional data to the entry and
*	retrieving that date later.
*
*	Supported functions include:
*	storing category specific event data,
*	atomic completion of an entry,
*	Getting entry status (complete and timestamped)
*	Getting entry header elements (timestamp, PID, TID, Category, and Sub-category),
*	Retrieving category specific event data entries,
*	and direct pointer access the header and data of the entry.
*
*	This Entry access API supports read out of the 16 byte
*	entry header including: Entry status and length.  Entry
*	Category and SubCategory codes. Process and Thread Ids.  High
*	resolution timestamp.
*
*	Any additional storage allocated to the entry
*	is available for application specific data.  This API also provides
*	several mechanisms to store application data including; direct
*	array or structure overlay, and a streams like mechanism.  Finally
*	the API provides a completion functions (SPHLFEntryComplete)
*	which provides and memory barriers required by the platform and
*	marks the entry complete.
*/


#include <string.h>
#include "sastype.h"
#include "sasatom.h"
#include "sphtimer.h"

/** \brief unsigned int type, consistent with the size of a pointer and used for pointer calculations **/
typedef unsigned long longPtr_t;

/** \brief Fields defining the entry header details word.
*/
typedef struct {
	/** Boolean: Indicates that this entry is valid (complete). **/
	unsigned int 	valid : 1;
	/** Boolean: Indicates that this entry is time stamped. **/
	unsigned int 	timestamped : 1;
	/** Boolean that indicates this entry is allocated. **/
	unsigned int 	allocated : 1;
	/** reserved **/
	unsigned int 	__reserved : 1;
	/** Application defined Event category code **/
	unsigned int 	category : 12;
	/** Application defined Event sub-category code **/
	unsigned int 	subcat : 8;
	/** Length of this entry **/
	unsigned int 	len : 8;
	} sphLFEntryLayout_t;

/** \brief Aggregate type for handling sphLogEntryLayout_t. **/
typedef unsigned int sphLFEntryID_t;

/** \brief Union of Entry details with 32-bit word for atomic update.
*/
typedef union {
	/** Logger Entry header as a Unit **/
	sphLFEntryID_t		idUnit;
	/** Logger Entry header in detail **/
	sphLFEntryLayout_t	detail;
	} sphLFEntry_t;

/** \brief Common type for PID/TID values stored in event entries.  **/
typedef unsigned short sphpid16_t;

/** \brief Instance of a Lock Free Entry Header.
*
*   Contains fields defining the standard timestamped entry header.
*/
typedef struct {
		/** Entry header detailes **/
        sphLFEntry_t   entryID;
        /** Process ID **/
        sphpid16_t      PID;
        /** Thread ID **/
        sphpid16_t      TID;
        /** High resolution 64-bit Time Stamp **/
        sphtimer_t      timeStamp;
        } SPHLFEntryHeader_t;

/** \brief Instance of a Lock Free event data Entry Handle.
*
*   Contains fields required to: locate the entry, record the total
*   space allocated to the entry, and manage the next location within
*   the entry and remaining storage.
*
*	Entry Handles should be allocated in private (local stack) storage
*	to allow concurrent access to independent entries from multiple threads.
*/
typedef struct {
    /** address of the start of the Queue entry **/
     SPHLFEntryHeader_t	*entry;
	/** address of the next avail byte(s) of storage **/
	char			*next;
	/** Total allocated size of the event entry **/
	unsigned short int	total_size;
	/** Remaining bytes of free storage in the entry **/
	unsigned short int	remaining;
	} SPHLFEntryHandle_t;

/** \brief Marks the entry specified by the entry handle as complete.
*	Also executes any memory barriers required by the platform to ensure
*	that all previous stores to this entry by this thread are visible
*	to other threads.
*
*   @param handlespace Entry Handle for an allocated entry.
*	@return a 0 value indicates success.
*/
static inline int
SPHLFEntryStrongComplete (SPHLFEntryHandle_t *handlespace)
{
    int rc = 0;
    SPHLFEntryHeader_t	*entryPtr = handlespace->entry;
    sphLFEntry_t	entrytemp;

    sas_read_barrier();
    entrytemp.idUnit = entryPtr->entryID.idUnit;
    entrytemp.detail.valid = 1;
    entryPtr->entryID.idUnit = entrytemp.idUnit;

    return rc;
}

/** \brief Marks the entry specified by the entry handle as complete.
*	No memory barriers are performance.
*	On out-of-order machines there are no guarantee that all
*	previous stores by this thread are visible to other threads.
*
*   @param handlespace Entry Handle for an allocated entry.
*	@return a 0 value indicates success.
*/
static inline int
SPHLFEntryWeakComplete (SPHLFEntryHandle_t *handlespace)
{
    int rc = 0;
    SPHLFEntryHeader_t	*entryPtr = handlespace->entry;
    sphLFEntry_t	entrytemp;

    entrytemp.idUnit = entryPtr->entryID.idUnit;
    entrytemp.detail.valid = 1;
    entryPtr->entryID.idUnit = entrytemp.idUnit;

    return rc;
}

/** \brief Marks the entry specified by the entry handle as complete.
*	Also executes write memory barries required by the platform to ensure
*	that all previous stores by this thread to this entry are complete.
*
*   @param handlespace Entry Handle for an allocated entry.
*	@return a 0 value indicates success.
*/
static inline int
SPHLFEntryComplete (SPHLFEntryHandle_t *handlespace)
{
    int rc = 0;
    SPHLFEntryHeader_t	*entryPtr = handlespace->entry;
    sphLFEntry_t	entrytemp;

    sas_write_barrier();
    entrytemp.idUnit = entryPtr->entryID.idUnit;
    entrytemp.detail.valid = 1;
    entryPtr->entryID.idUnit = entrytemp.idUnit;

    return rc;
}

/** \brief Return the status of the entry specified by the entry handle.
*
*   @param handlespace Entry Handle for an allocated entry.
*	@return true if the entry was complete (SPHLFLoggerEntryComplete
*	has been called fo this entry). Otherwise False.
*/
static inline int
SPHLFEntryIsComplete (SPHLFEntryHandle_t *handlespace)
{
    SPHLFEntryHeader_t	*entryPtr = handlespace->entry;

    return (entryPtr->entryID.detail.valid == 1);
}

/** \brief Return the status of the entry specified by the entry handle.
*
*   @param handlespace Entry Handle for an allocated entry.
*	@return true if the entry was time stamped. Otherwise False.
*/
static inline int
SPHLFEntryIsTimestamped (SPHLFEntryHandle_t *handlespace)
{
    SPHLFEntryHeader_t	*entryPtr = handlespace->entry;

    return ((entryPtr->entryID.detail.valid == 1)
	  &&(entryPtr->entryID.detail.timestamped == 1));
}

/** \brief Return the time stamp value for the entry specified by the entry handle.
*
*   @param handlespace Entry Handle for an allocated entry.
*	@return the time stamp value from the entry, if the entry was valid
*	and time stamped. Otherwise return 0.
*/
static inline sphtimer_t
SPHLFEntryTimeStamp (SPHLFEntryHandle_t *handlespace)
{
    SPHLFEntryHeader_t	*entryPtr = handlespace->entry;
    sphtimer_t result = 0;

    if ((entryPtr->entryID.detail.valid == 1)
	  &&(entryPtr->entryID.detail.timestamped == 1))
	result = entryPtr->timeStamp;

    return result;
}

/** \brief Return the process ID for the entry specified by the entry handle.
*
*   @param handlespace Entry Handle for an allocated entry.
*	@return the PID from the entry, if the entry was valid
*	and time stamped. Otherwise return 0.
*/
static inline sphpid16_t
SPHLFEntryPID (SPHLFEntryHandle_t *handlespace)
{
    SPHLFEntryHeader_t	*entryPtr = handlespace->entry;
    sphpid16_t result = 0;

    if ((entryPtr->entryID.detail.valid == 1)
	  &&(entryPtr->entryID.detail.timestamped == 1))
	result = entryPtr->PID;

    return result;
}

/** \brief Return the thread ID for the entry specified by the entry handle.
*
*   @param handlespace Entry Handle for an allocated entry.
*	@return the TID from the entry, if the entry was valid
*	and time stamped. Otherwise return 0.
*/
static inline sphpid16_t
SPHLFEntryTID (SPHLFEntryHandle_t *handlespace)
{
    SPHLFEntryHeader_t	*entryPtr = handlespace->entry;
    sphpid16_t result = 0;

    if ((entryPtr->entryID.detail.valid == 1)
	  &&(entryPtr->entryID.detail.timestamped == 1))
	result = entryPtr->TID;

    return result;
}

/** \brief Return the address for the entry header specified by the entry handle.
*
*   @param handlespace Entry Handle for an allocated entry.
*	@return the address from the entry header, if the entry was valid.
*	Otherwise return NULL.
*/
static inline SPHLFEntryHeader_t*
SPHLFEntryHeader (SPHLFEntryHandle_t *handlespace)
{
    SPHLFEntryHeader_t	*entryPtr = handlespace->entry;

    if (entryPtr->entryID.detail.valid != 1)
	entryPtr = NULL;

    return entryPtr;
}

/** \brief Return the entry category for the entry specified by the entry handle.
*
*   @param handlespace Entry Handle for an allocated entry.
*	@return the category from the entry, if the entry was valid.
*	Otherwise return 0.
*/
static inline int
SPHLFEntryCategory (SPHLFEntryHandle_t *handlespace)
{
    SPHLFEntryHeader_t	*entryPtr = handlespace->entry;
    int result = -1;
#if 0
    printf ("SPHLFEntryCategory(%p) entry=%p id=%x\n",
		handlespace, entryPtr, entryPtr->entryID.idUnit);
#endif
    if (entryPtr->entryID.detail.valid == 1)
	result = entryPtr->entryID.detail.category;

    return result;
}

/** \brief Return the entry sub-category for the entry specified by the entry handle.
*
*   @param handlespace Entry Handle for an allocated entry.
*	@return the sub-category from the entry, if the entry was valid.
*	Otherwise return 0.
*/
static inline int
SPHLFEntrySubcat (SPHLFEntryHandle_t *handlespace)
{
    SPHLFEntryHeader_t	*entryPtr = handlespace->entry;
    int result = -1;
#if 0
    printf ("SPHLFEntrySubcat(%p) entry=%p id=%x\n",
		handlespace, entryPtr, entryPtr->entryID.idUnit);
#endif
    if (entryPtr->entryID.detail.valid == 1)
	result = entryPtr->entryID.detail.subcat;

    return result;
}

/** \brief Return the first free byte address for the entry specified by
*   the entry handle.
*
*   \warning This function should be used carefully. It is not safe to use
*   if other application functions may need to update the same entry.
*   It is also not safe to use for software that needs to cross platform
*   because it does not handle platform specific size and alignment
*   requirements.
*
*   \note The SPHLOGENTRYALLOCSTRUCT/SPHLFlogEntryAllocStruct API is recommended
*   for code that needs to operate cross platform.
*
*   @param handle Entry Handle for an allocated entry.
*	@return address the entries free space.
*/
static inline void*
SPHLFEntryGetFreePtr (SPHLFEntryHandle_t *handle)
{
	char		*ptr	= handle->next;
	
	return (void*)ptr;
}

/** \brief Macro for using sizeof/__alignof__ parms with
*   SPHLFEntryGetStructPtr function.  **/
#define SPHENTRYGETSTRUCTPTR(__handle, __struct) SPHLFEntryGetStructPtr(__handle, sizeof(__struct), __alignof__(__struct))

/** \brief Return the correctly aligned pointer for a struct or array
*   starting at the next free location within the entry.
*
*   The entries next pointer is adjusted for alignment and returned.
*   The entries next pointer and remaining fields are updated for the
*   next field following the struct/array.
*
*   \note The SPHENTRYGETSTRUCTPTR can be used to insure the correct usage
*   sizeof and __alignof__ to provide values for the __size and __align
*   parameters.
*
*   @param handle Entry Handle for an allocated entry.
*   @param __size of the struct/array to allocate.
*   @param __align alignment requirement of the struct/array space
*   to allocated.
*	@return address of the allocated free space. NULL indicates failure.
*	For example if remaining entry space
*	is insufficient to hold the struct at the required alignment.
*/
static inline  void*
SPHLFEntryGetStructPtr (SPHLFEntryHandle_t *handle,
		unsigned long __size, unsigned long __align)
{
	char	*ptr	= (char*)handle->next;
	unsigned long	len	= handle->remaining;
	unsigned long	adjust	= __align - 1;
	unsigned long	mask	= ~adjust;

	ptr = (char*)
		((((unsigned long)ptr)
		+ adjust)
		& mask);

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= __size)
	{
		handle->next = ptr + __size;
		handle->remaining = len - __size;
	} else {
		ptr = NULL;
	}
	return ptr;
}

/** \brief Macro for using sizeof/__alignof__ parms with
*   SPHLFEntryAllocStruct function.  **/
#define SPHENTRYALLOCSTRUCT(__handle, __struct) SPHLFEntryAllocStruct(__handle, sizeof(__struct), __alignof__(__struct))

/** \brief Allocate space for struct starting at the next free location
*   within the entry.
*
*   Allocate space in the log entry for a multi-field structure or an array.
*   The returned pointer can then be used to directly store data into struct
*   fields or array entries.
*   The SPHENTRYALLOCSTRUCT can be used to insure the correct usage
*   sizeof and __alignof__ to provide values for the __size and __align
*   parameters.
*
*   \note This function should be used instead of SPHLFEntryGetFreePtr
*   if additional data may be added later to the same entry.
*
*   @param handle Entry Handle for an allocated entry.
*   @param __size of the struct/array to allocate.
*   @param __align alignment requirement of the struct/array space
*   to allocated.
*	@return address of the allocated free space. NULL indicates failure.
*	For example if remaining entry space
*	is insufficient to hold the struct at the required alignment.
*/
static inline  void*
SPHLFEntryAllocStruct (SPHLFEntryHandle_t *handle,
		unsigned long __size, unsigned long __align)
{
	char	*ptr	= (char*)handle->next;
	unsigned long	len	= handle->remaining;
	unsigned long	adjust	= __align - 1;
	unsigned long	mask	= ~adjust;

	ptr = (char*)
		((((unsigned long)ptr)
		+ adjust)
		& mask);

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= __size)
	{
		handle->next = ptr + __size;
		handle->remaining = len - __size;
	} else {
		ptr = NULL;
	}
	return ptr;
}

/** \brief Insert a C string at the next free location within the entry.
*
*   @param handle Entry Handle for an allocated entry.
*   @param value pointer to a C string value.
*	@return 0 if successful, -1 if the insert fails.
*	For example if the string is too
*	large for the remain entry free space.
*/
static inline int
SPHLFEntryAddString (SPHLFEntryHandle_t *handle,
			char *value)
{
	char		*ptr	= handle->next;
	unsigned short int	len	= handle->remaining;
	int		vlen	= (strlen(value) + 1);
	int		rc	= 0;

	if (len >= vlen)
	{
		strcpy (ptr, value);
		ptr += vlen;
		len -= vlen;
		handle->next = ptr;
		handle->remaining = len;
	} else {
		rc = -1;
	}
	return rc;
}

/** \brief Insert a character at the next free location within the entry.
*
*   @param handle Entry Handle for an allocated entry.
*   @param value a char value.
*	@return 0 if successful, -1 if the insert fails.
*	For example if remaining entry space
*	is insufficient to hold a char.
*/
static inline int
SPHLFEntryAddChar (SPHLFEntryHandle_t *handle,
			char value)
{
	char	*ptr	= handle->next;
	unsigned short int	len	= handle->remaining;
	int	rc	= 0;

	if (len >= sizeof(char))
	{
		*ptr++ = value;
		len -= sizeof(char);
		handle->next = (char*)ptr;
		handle->remaining = len;
	} else {
		rc = -1;
	}
	return rc;
}

/** \brief Insert a short int at the next free location within the entry.
*
*   @param handle Entry Handle for an allocated entry.
*   @param value a short int value.
*	@return 0 if successful, -1 if the insert fails.
*	For example if remaining entry space
*	is insufficient to hold a short int plus any required alignment.
*/
static inline  int
SPHLFEntryAddShort (SPHLFEntryHandle_t *handle,
			short int value)
{
	short int	*ptr	= (short int*)handle->next;
	unsigned short int	len	= handle->remaining;
	int		rc	= 0;
	unsigned long	adjust	= __alignof__(short int) -1;
	unsigned long	mask	= ~adjust;

	ptr = (short int*)
		((((unsigned long)ptr)
		+ adjust)
		& mask);

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(short int))
	{
		*ptr++ = value;
		len -= sizeof(short);
		handle->next = (char*)ptr;
		handle->remaining = len;
	} else {
		rc = -1;
	}
	return rc;
}

/** \brief Insert a int at the next free location within the entry.
*
*   @param handle Entry Handle for an allocated entry.
*   @param value a int value.
*	@return 0 if successful, -1 if the insert fails.
*	For example if remaining entry space
*	is insufficient to hold a int plus any required alignment.
*/
static inline  int
SPHLFEntryAddInt (SPHLFEntryHandle_t *handle,
			int value)
{
	int		*ptr	= (int*)handle->next;
	unsigned short int	len	= handle->remaining;
	int		rc	= 0;

	ptr = (int*)(((((unsigned long)ptr))
		+ (__alignof__(int) -1))
		& (~(__alignof__(int) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(int))
	{
		*ptr++ = value;
		len -= sizeof(int);
		handle->next = (char*)ptr;
		handle->remaining = len;
	} else {
		rc = -1;
	}
	return rc;
}

/** \brief Insert a long int at the next free location within the entry.
*
*   @param handle Entry Handle for an allocated entry.
*   @param value a long int value.
*	@return 0 if successful, -1 if the insert fails.
*	For example if remaining entry space
*	is insufficient to hold a long int plus any required alignment.
*/
static inline  int
SPHLFEntryAddLong (SPHLFEntryHandle_t *handle,
			long value)
{
	long		*ptr	= (long*)handle->next;
	unsigned short int	len	= handle->remaining;
	int		rc	= 0;

	ptr = (long*)(((((unsigned long)ptr))
		+ (__alignof__(long) -1))
		& (~(__alignof__(long) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(long))
	{
		*ptr++ = value;
		len -= sizeof(long);
		handle->next = (char*)ptr;
		handle->remaining = len;
	} else {
		rc = -1;
	}
	return rc;
}

/** \brief Insert a void* at the next free location within the entry.
*
*   @param handle Entry Handle for an allocated entry.
*   @param value a void* (C pointer) value.
*	@return 0 if successful, -1 if the insert fails.
*	For example if remaining entry space
*	is insufficient to hold a void* plus any required alignment.
*/
static inline  int
SPHLFEntryAddPtr (SPHLFEntryHandle_t *handle,
			void *value)
{
	void		**ptr	= (void**)handle->next;
	unsigned short int	len	= handle->remaining;
	int		rc	= 0;

	ptr = (void**)(((((unsigned long)ptr))
		+ (__alignof__(void*) -1))
		& (~(__alignof__(void*) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(void*))
	{
		*ptr++ = value;
		len -= sizeof(void*);
		handle->next = (char*)ptr;
		handle->remaining = len;
	} else {
		rc = -1;
	}
	return rc;
}

/** \brief Insert a long long int at the next free location within the entry.
*
*   @param handle Entry Handle for an allocated entry.
*   @param value a long long int value.
*	@return 0 if successful, -1 if the insert fails.
*	For example if remaining entry space
*	is insufficient to hold a long long int plus any required alignment.
*/
static inline  int
SPHLFEntryAddLongLong (SPHLFEntryHandle_t *handle,
			long long value)
{
	long long	*ptr	= (long long*)handle->next;
	unsigned short int	len	= handle->remaining;
	int		rc	= 0;

	ptr = (long long*)(((((unsigned long)ptr))
		+ (__alignof__(long long) -1))
		& (~(__alignof__(long long) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(long long))
	{
		*ptr++ = value;
		len -= sizeof(long long);
		handle->next = (char*)ptr;
		handle->remaining = len;
	} else {
		rc = -1;
	}
	return rc;
}

/** \brief Insert a float at the next free location within the entry.
*
*   @param handle Entry Handle for an allocated entry.
*   @param value a float value.
*	@return 0 if successful, -1 if the insert fails.
*	For example if remaining entry space
*	is insufficient to hold a float plus any required alignment.
*/
static inline  int
SPHLFEntryAddFloat (SPHLFEntryHandle_t *handle,
			float value)
{
	float		*ptr	= (float*)handle->next;
	unsigned short int	len	= handle->remaining;
	int		rc	= 0;

	ptr = (float*)(((((unsigned long)ptr))
		+ (__alignof__(float) -1))
		& (~(__alignof__(float) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(float))
	{
		*ptr++ = value;
		len -= sizeof(float);
		handle->next = (char*)ptr;
		handle->remaining = len;
	} else {
		rc = -1;
	}
	return rc;
}

/** \brief Insert a double at the next free location within the entry.
*
*   @param handle Entry Handle for an allocated entry.
*   @param value a double value.
*	@return 0 if successful, -1 if the insert fails.
*	For example if remaining entry space
*	is insufficient to hold a double plus any required alignment.
*/
static inline  int
SPHLFEntryAddDouble (SPHLFEntryHandle_t *handle,
			double value)
{
	double		*ptr	= (double*)handle->next;
	unsigned short int	len	= handle->remaining;
	int		rc	= 0;

	ptr = (double*)(((((unsigned long)ptr))
		+ (__alignof__(double) -1))
		& (~(__alignof__(double) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(double))
	{
		*ptr++ = value;
		len -= sizeof(double);
		handle->next = (char*)ptr;
		handle->remaining = len;
	} else {
		rc = -1;
	}
	return rc;
}

/** \brief Return the next char from the entry via the current
*   next value pointer.
*	The internal next value pointer is advanced to the next location.
*
*   @param handle Entry Handle for an allocated entry.
*	@return the char value if successful, 0 (NUL) if the get fails.
*	For example if the next is at the end of the Logger entry.
*/
static inline  char
SPHLFEntryGetNextChar (SPHLFEntryHandle_t *handle)
{
	char	*ptr	= handle->next;
	unsigned short int	len	= handle->remaining;
	char	value = 0;

	if (len >= sizeof(char))
	{
		value = *ptr++;
		len -= sizeof(char);
		handle->next = (char*)ptr;
		handle->remaining = len;
	}
	return value;
}

/** \brief Return the pointer to the next C string from the logger
*   entry via the current next value pointer.
*	The internal next value pointer is advanced to the next location after the string NUL char.
*
*   @param handle Entry Handle for an allocated entry.
*	@return the C string pointer value if successful, 0 (NULL) if the get fails.
*	For example if the next is at the end of the Logger entry.
*/
static inline  char*
SPHLFEntryGetNextString (SPHLFEntryHandle_t *handle)
{
	char		*ptr	= handle->next;
	unsigned short int	len	= handle->remaining;
	int		vlen	= (strlen(ptr) + 1);
	char		*value	= 0;

	if (len >= vlen)
	{
		value = ptr;
		ptr += vlen;
		len -= vlen;
		handle->next = ptr;
		handle->remaining = len;
	}
	return value;
}

/** \brief Return the next short int from the entry via the
*   current next value pointer.
*	Leading bytes may be skipped to get the required alignment.
*	The internal next value pointer is advanced to the next location.
*
*   @param handle Entry Handle for an allocated entry.
*	@return the short int value if successful, 0 if the get fails.
*	For example if the next is at the end of the Logger entry.
*/
static inline short int
SPHLFEntryGetNextShort (SPHLFEntryHandle_t *handle)
{
	short int	*ptr	= (short int*)handle->next;
	unsigned short int	len	= handle->remaining;
	unsigned long	adjust	= __alignof__(short int) -1;
	unsigned long	mask	= ~adjust;
	short int	value	= 0;

	ptr = (short int*)
		((((unsigned long)ptr)
		+ adjust)
		& mask);

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(short int))
	{
		value = *ptr++;
		len -= sizeof(short);
		handle->next = (char*)ptr;
		handle->remaining = len;
	}
	return value;
}

/** \brief Return the next int from the entry via the
*   current next value pointer.
*	Leading bytes may be skipped to get the required alignment.
*	The internal next value pointer is advanced to the next location.
*
*   @param handle Entry Handle for an allocated entry.
*	@return the int value if successful, 0 if the get fails.
*	For example if the next is at the end of the Logger entry.
*/
static inline  int
SPHLFEntryGetNextInt (SPHLFEntryHandle_t *handle)
{
	int		*ptr	= (int*)handle->next;
	unsigned short int	len	= handle->remaining;
	int		value	= 0;

	ptr = (int*)(((((unsigned long)ptr))
		+ (__alignof__(int) -1))
		& (~(__alignof__(int) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(int))
	{
		value = *ptr++;
		len -= sizeof(int);
		handle->next = (char*)ptr;
		handle->remaining = len;
	}
	return value;
}

/** \brief Return the next long int from the entry via the
*   current next value pointer.
*	Leading bytes may be skipped to get the required alignment.
*	The internal next value pointer is advanced to the next location.
*
*   @param handle Entry Handle for an allocated entry.
*	@return the long int value if successful, 0 if the get fails.
*	For example if the next is at the end of the Logger entry.
*/
static inline  long
SPHLFEntryGetNextLong (SPHLFEntryHandle_t *handle)
{
	long		*ptr	= (long*)handle->next;
	unsigned short int	len	= handle->remaining;
	long		value	= 0;

	ptr = (long*)(((((unsigned long)ptr))
		+ (__alignof__(long) -1))
		& (~(__alignof__(long) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(long))
	{
		value = *ptr++;
		len -= sizeof(long);
		handle->next = (char*)ptr;
		handle->remaining = len;
	}
	return value;
}

/** \brief Return the next void* from the entry via the current
*   next value pointer.
*	Leading bytes may be skipped to get the required alignment.
*	The internal next value pointer is advanced to the next location.
*
*   @param handle Entry Handle for an allocated entry.
*	@return the void* value if successful, 0 (NULL) if the get fails.
*	For example if the next is at the end of the Logger entry.
*/
static inline  void*
SPHLFEntryGetNextPtr (SPHLFEntryHandle_t *handle)
{
	void		**ptr	= (void**)handle->next;
	unsigned short int	len	= handle->remaining;
	void		*value	= NULL;

	ptr = (void**)(((((unsigned long)ptr))
		+ (__alignof__(void*) -1))
		& (~(__alignof__(void*) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(void*))
	{
		value = *ptr++;
		len -= sizeof(void*);
		handle->next = (char*)ptr;
		handle->remaining = len;
	}
	return value;
}

/** \brief Return the next long long int from the entry via the
*   current next value pointer.
*	Leading bytes may be skipped to get the required alignment.
*	The internal next value pointer is advanced to the next location.
*
*   @param handle Entry Handle for an allocated entry.
*	@return the long long int value if successful,0 if the get fails. For example if the next is at the end
*	of the Logger entry.
*/
static inline  long long
SPHLFEntryGetNextLongLong (SPHLFEntryHandle_t *handle)
{
	long long	*ptr	= (long long*)handle->next;
	unsigned short int	len	= handle->remaining;
	long long		value	= 0LL;

	ptr = (long long*)(((((unsigned long)ptr))
		+ (__alignof__(long long) -1))
		& (~(__alignof__(long long) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(long long))
	{
		value = *ptr++;
		len -= sizeof(long long);
		handle->next = (char*)ptr;
		handle->remaining = len;
	}
	return value;
}

/** \brief Return the next float from the entry via the current
*   next value pointer.
*	Leading bytes may be skipped to get the required alignment.
*	The internal next value pointer is advanced to the next location.
*
*   @param handle Entry Handle for an allocated entry.
*	@return the float value if successful, 0.0 if the get fails.
*	For example if the next is at the end of the Logger entry.
*/
static inline  float
SPHLFEntryGetNextFloat (SPHLFEntryHandle_t *handle)
{
	float		*ptr	= (float*)handle->next;
	unsigned short int	len	= handle->remaining;
	float		value	= 0.0;

	ptr = (float*)(((((unsigned long)ptr))
		+ (__alignof__(float) -1))
		& (~(__alignof__(float) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(float))
	{
		value = *ptr++;
		len -= sizeof(float);
		handle->next = (char*)ptr;
		handle->remaining = len;
	}
	return value;
}

/** \brief Return the next double from the entry via the current
*   next value pointer.
*	Leading bytes may be skipped to get the required alignment.
*	The internal next value pointer is advanced to the next location.
*
*   @param handle Entry Handle for an allocated entry.
*	@return the double value if successful, 0.0 if the get fails.
*	For example if the next is at the end of the Logger entry.
*/
static inline  double
SPHLFEntryGetNextDouble (SPHLFEntryHandle_t *handle)
{
	double		*ptr	= (double*)handle->next;
	unsigned short int	len	= handle->remaining;
	double		value	= 0.0;

	ptr = (double*)(((((unsigned long)ptr))
		+ (__alignof__(double) -1))
		& (~(__alignof__(double) -1)));

	if ((unsigned long)ptr != (unsigned long)handle->next)
	{
		len -= ((unsigned long)ptr
			- (unsigned long)handle->next);
	}

	if (len >= sizeof(double))
	{
		value = *ptr++;
		len -= sizeof(double);
		handle->next = (char*)ptr;
		handle->remaining = len;
	}
	return value;
}

#endif /* __SPH_LOCK_FREE_ENTRY_H */