File: sphlflogentry.h

package info (click to toggle)
sphde 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 4,400 kB
  • sloc: ansic: 38,652; cpp: 20,246; sh: 11,427; makefile: 252
file content (1034 lines) | stat: -rw-r--r-- 28,978 bytes parent folder | download | duplicates (4)
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
/*
 * Copyright (c) 2011-2014 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_LOGENTRY_H
#define __SPH_LOCK_FREE_LOGENTRY_H

/**! \file sphlflogentry.h
*  \brief Shared Persistent Heap, logger entry status, update and
*   access functions.
*
*  \author Steven Munroe - initial API and implementation
*
*	For shared memory multi-thread/multi-core applications. Once the
*	SPHLFLogger_t functions have atomically allocated a Logger 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 Logger 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 (SPHLFLogEntryComplete)
*	which provides and memory barriers required by the platform and
*	marks the entry complete.
*
*	\todo This API should be migrated to use the common sphlfentry.h API.
*/


#include <string.h>
#include "sasatom.h"
#include "sphlflogger.h"


/** \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 Logger Entry Handle for an allocated entry.
*	@return a 0 value indicates success.
*/
static inline int
SPHLFLogEntryStrongComplete (SPHLFLoggerHandle_t *handlespace)
{
    int rc = 0;
    SPHLFLogHeader_t	*entryPtr = handlespace->entry;
    sphLogEntry_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 Logger Entry Handle for an allocated entry.
*	@return a 0 value indicates success.
*/
static inline int
SPHLFLogEntryWeakComplete (SPHLFLoggerHandle_t *handlespace)
{
    int rc = 0;
    SPHLFLogHeader_t	*entryPtr = handlespace->entry;
    sphLogEntry_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.
*	On out-of-order machines this barrier does not guarantee that all
*	previous stores by this thread are visible to other threads.
*
*   @param handlespace Logger Entry Handle for an allocated entry.
*	@return a 0 value indicates success.
*/
static inline int
SPHLFLogEntryComplete (SPHLFLoggerHandle_t *handlespace)
{
    int rc = 0;
    SPHLFLogHeader_t	*entryPtr = handlespace->entry;
    sphLogEntry_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 Logger 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
SPHLFLogEntryIsComplete (SPHLFLoggerHandle_t *handlespace)
{
    SPHLFLogHeader_t	*entryPtr = handlespace->entry;

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

/** \brief Return the status of the entry specified by the entry handle.
*
*   @param handlespace Logger Entry Handle for an allocated entry.
*	@return true if the entry was time stamped. Otherwise False.
*/
static inline int
SPHLFLogEntryIsTimestamped (SPHLFLoggerHandle_t *handlespace)
{
    SPHLFLogHeader_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 Logger 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
SPHLFLogEntryTimeStamp (SPHLFLoggerHandle_t *handlespace)
{
    SPHLFLogHeader_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 Logger 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
SPHLFLogEntryPID (SPHLFLoggerHandle_t *handlespace)
{
    SPHLFLogHeader_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 Logger 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
SPHLFLogEntryTID (SPHLFLoggerHandle_t *handlespace)
{
    SPHLFLogHeader_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 Logger Entry Handle for an allocated entry.
*	@return the address from the entry header, if the entry was valid.
*	Otherwise return NULL.
*/
static inline SPHLFLogHeader_t*
SPHLFLogEntryHeader (SPHLFLoggerHandle_t *handlespace)
{
    SPHLFLogHeader_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 Logger Entry Handle for an allocated entry.
*	@return the category from the entry, if the entry was valid.
*	Otherwise return 0.
*/
static inline int
SPHLFLogEntryCategory (SPHLFLoggerHandle_t *handlespace)
{
    SPHLFLogHeader_t	*entryPtr = handlespace->entry;
    int result = -1;
#if 0
    printf ("SPHLFLogEntryCategory(%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 Logger Entry Handle for an allocated entry.
*	@return the sub-category from the entry, if the entry was valid.
*	Otherwise return 0.
*/
static inline int
SPHLFLogEntrySubcat (SPHLFLoggerHandle_t *handlespace)
{
    SPHLFLogHeader_t	*entryPtr = handlespace->entry;
    int result = -1;
#if 0
    printf ("SPHLFLogEntrySubcat(%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 address first free byte 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 Logger Entry Handle for an allocated entry.
*	@return address the entries free space.
*/
static inline void*
SPHLFLogEntryGetFreePtr (SPHLFLoggerHandle_t *handle)
{
	char		*ptr	= handle->next;
	
	return (void*)ptr;
}

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

/** \brief Return the correctly aligned pointer for a struct or array
*   starting at the next free location within the logger 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 SPHLOGENTRYGETSTRUCTPTR can be used to insure the correct usage
*   sizeof and __alignof__ to provide values for the __size and __align
*   parameters.
*
*   @param handle Logger 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*
SPHLFlogEntryGetStructPtr (SPHLFLoggerHandle_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
*   SPHLFlogEntryAllocStruct function.  **/
#define SPHLOGENTRYALLOCSTRUCT(__handle, __struct) SPHLFlogEntryAllocStruct(__handle, sizeof(__struct), __alignof__(__struct))

/** \brief Allocate space for struct starting at the next free location
*   within the logger 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 SPHLOGENTRYALLOCSTRUCT 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 SPHLFLogEntryGetFreePtr
*   if additional data may be added later to the same entry.
*
*   @param handle Logger 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*
SPHLFlogEntryAllocStruct (SPHLFLoggerHandle_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 logger entry.
*
*   @param handle Logger 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
SPHLFlogEntryAddString (SPHLFLoggerHandle_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 logger entry.
*
*   @param handle Logger 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
SPHLFlogEntryAddChar (SPHLFLoggerHandle_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 logger entry.
*
*   @param handle Logger 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
SPHLFlogEntryAddShort (SPHLFLoggerHandle_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 logger entry.
*
*   @param handle Logger 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
SPHLFlogEntryAddInt (SPHLFLoggerHandle_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 logger entry.
*
*   @param handle Logger 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
SPHLFlogEntryAddLong (SPHLFLoggerHandle_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 logger entry.
*
*   @param handle Logger 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
SPHLFlogEntryAddPtr (SPHLFLoggerHandle_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 logger entry.
*
*   @param handle Logger 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
SPHLFlogEntryAddLongLong (SPHLFLoggerHandle_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 logger entry.
*
*   @param handle Logger 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
SPHLFlogEntryAddFloat (SPHLFLoggerHandle_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 logger entry.
*
*   @param handle Logger 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
SPHLFlogEntryAddDouble (SPHLFLoggerHandle_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 logger entry via the current
*   next value pointer.
*	The internal next value pointer is advanced to the next location.
*
*   @param handle Logger 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
SPHLFlogEntryGetNextChar (SPHLFLoggerHandle_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 Logger 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*
SPHLFlogEntryGetNextString (SPHLFLoggerHandle_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 logger 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 Logger 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
SPHLFlogEntryGetNextShort (SPHLFLoggerHandle_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 logger 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 Logger 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
SPHLFlogEntryGetNextInt (SPHLFLoggerHandle_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 logger 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 Logger 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
SPHLFlogEntryGetNextLong (SPHLFLoggerHandle_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 logger 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 Logger 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*
SPHLFlogEntryGetNextPtr (SPHLFLoggerHandle_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 logger 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 Logger 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
SPHLFlogEntryGetNextLongLong (SPHLFLoggerHandle_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 logger 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 Logger 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
SPHLFlogEntryGetNextFloat (SPHLFLoggerHandle_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 logger 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 Logger 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
SPHLFlogEntryGetNextDouble (SPHLFLoggerHandle_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_LOGENTRY_H */