sphdirectpcqueue.h
Go to the documentation of this file.
/*
* Copyright (c) 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 SRC_SPHDIRECTPCQUEUE_H_
#define SRC_SPHDIRECTPCQUEUE_H_
#include <stdint.h>
#include "sastype.h"
#include "sasatom.h"
#include "sphlfentry.h"
#include "sphsinglepcqueue.h"
#ifdef __cplusplus
#define __C__ "C"
#else
#define __C__
#endif
typedef void* SPHLFEntryDirect_t;
static inline int
SPHLFEntryDirectComplete (SPHLFEntryDirect_t directHandle,
sphLFEntryID_t entry_template,
int catcode, int subcode)
{
int rc = 1;
SPHLFEntryHeader_t *entryPtr = (SPHLFEntryHeader_t*)directHandle;
sphLFEntry_t entrytemp;
sas_read_barrier();
/* the template should have allocated and len already set. */
entrytemp.idUnit = entry_template;
entrytemp.detail.valid = 1;
entrytemp.detail.category = catcode;
entrytemp.detail.subcat = subcode;
entryPtr->entryID.idUnit = entrytemp.idUnit;
return (rc);
}
static inline void*
SPHLFEntryDirectGetFreePtr (SPHLFEntryDirect_t directHandle)
{
char *ptr = (char*)directHandle + sizeof (sphLFEntry_t);
return ((void*)ptr);
}
static inline void*
SPHLFEntryDirectGetPtrAligned (SPHLFEntryDirect_t directHandle,
size_t alignval)
{
uintptr_t ptr = (uintptr_t)directHandle;
uintptr_t adjust = alignval - 1;
uintptr_t mask = ~adjust;
ptr = ((ptr + sizeof (sphLFEntry_t) + adjust) & mask);
return ((void*)ptr);
}
static inline void*
SPHLFEntryDirectIncAndAlign (void *directptr, size_t incval, size_t alignval)
{
uintptr_t ptr = (uintptr_t)directptr;
uintptr_t adjust = alignval - 1;
uintptr_t mask = ~adjust;
ptr = ((ptr + incval + adjust) & mask);
return ((void*)ptr);
}
static inline int
SPHLFEntryDirectIsComplete (SPHLFEntryDirect_t directHandle)
{
SPHLFEntryHeader_t *entryPtr = (SPHLFEntryHeader_t*)directHandle;
return (entryPtr->entryID.detail.valid == 1);
}
static inline int
SPHLFEntryDirectIsTimestamped (SPHLFEntryDirect_t directHandle)
{
SPHLFEntryHeader_t *entryPtr = (SPHLFEntryHeader_t*)directHandle;
return ((entryPtr->entryID.detail.valid == 1)
&&(entryPtr->entryID.detail.timestamped == 1));
}
static inline int
SPHLFEntryDirectCategory (SPHLFEntryDirect_t directHandle)
{
SPHLFEntryHeader_t *entryPtr = (SPHLFEntryHeader_t*)directHandle;
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);
}
static inline int
SPHLFEntryDirectSubcat (SPHLFEntryDirect_t directHandle)
{
SPHLFEntryHeader_t *entryPtr = (SPHLFEntryHeader_t*)directHandle;
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);
}
extern __C__ sphLFEntryID_t
SPHSinglePCQueueGetEntryTemplate (SPHSinglePCQueue_t queue);
extern __C__ SPHLFEntryDirect_t
SPHSinglePCQueueAllocStrideDirect (SPHSinglePCQueue_t queue);
extern __C__ SPHLFEntryDirect_t
SPHSinglePCQueueAllocStrideDirectSpin (SPHSinglePCQueue_t queue);
extern __C__ SPHLFEntryDirect_t
SPHSinglePCQueueAllocStrideDirectSpinPause (SPHSinglePCQueue_t queue);
extern __C__ SPHLFEntryDirect_t
SPHSinglePCQueueGetNextCompleteDirectSpin (SPHSinglePCQueue_t queue);
extern __C__ SPHLFEntryDirect_t
SPHSinglePCQueueGetNextCompleteDirectSpinPause (SPHSinglePCQueue_t queue);
extern __C__ SPHLFEntryDirect_t
SPHSinglePCQueueGetNextCompleteDirect (SPHSinglePCQueue_t queue);
extern __C__ int
SPHSinglePCQueueFreeNextEntryDirect (SPHSinglePCQueue_t queue,
SPHLFEntryDirect_t next_entry);
extern __C__ SPHLFEntryDirect_t
SPHSinglePCQueueGetNextEntryDirect (SPHSinglePCQueue_t queue);
extern __C__ int
SPHSinglePCQueueEntryIsCompleteDirect (SPHLFEntryDirect_t directHandle);
#endif /* SRC_SPHDIRECTPCQUEUE_H_ */
sasatom.h
Type and functions for SAS atomic operations.
sas_read_barrier
#define sas_read_barrier()
Definition: sasatom.h:56
SPHLFEntryDirect_t
void * SPHLFEntryDirect_t
Instance of a Lock Free event direct data Handle.
Definition: sphdirectpcqueue.h:146
SPHLFEntryDirectIncAndAlign
static void * SPHLFEntryDirectIncAndAlign(void *directptr, size_t incval, size_t alignval)
Return the next free byte address within direct entry specified by a current address within that dire...
Definition: sphdirectpcqueue.h:238
SPHSinglePCQueueGetNextCompleteDirectSpinPause
__C__ SPHLFEntryDirect_t SPHSinglePCQueueGetNextCompleteDirectSpinPause(SPHSinglePCQueue_t queue)
Allows the consumer to get the next completed queue entry from the specified single producer single c...
SPHSinglePCQueueGetEntryTemplate
__C__ sphLFEntryID_t SPHSinglePCQueueGetEntryTemplate(SPHSinglePCQueue_t queue)
Return the entry template for an existing Lock Free Single Producer Single Consumer Queue....
SPHSinglePCQueueEntryIsCompleteDirect
__C__ int SPHSinglePCQueueEntryIsCompleteDirect(SPHLFEntryDirect_t directHandle)
Return the status of the entry specified by the direct entry handle.
SPHLFEntryDirectGetFreePtr
static void * SPHLFEntryDirectGetFreePtr(SPHLFEntryDirect_t directHandle)
Return the first free byte address for the direct entry specified by the direct entry handle....
Definition: sphdirectpcqueue.h:192
SPHSinglePCQueueGetNextCompleteDirect
__C__ SPHLFEntryDirect_t SPHSinglePCQueueGetNextCompleteDirect(SPHSinglePCQueue_t queue)
Allows the consumer to get the next completed queue entry from the specified single producer single c...
SPHLFEntryDirectComplete
static int SPHLFEntryDirectComplete(SPHLFEntryDirect_t directHandle, sphLFEntryID_t entry_template, int catcode, int subcode)
Marks the entry specified by the entry handle as complete. Also executes any memory barriers required...
Definition: sphdirectpcqueue.h:159
SPHSinglePCQueueGetNextCompleteDirectSpin
__C__ SPHLFEntryDirect_t SPHSinglePCQueueGetNextCompleteDirectSpin(SPHSinglePCQueue_t queue)
Allows the consumer to get the next completed queue entry from the specified single producer single c...
__C__
#define __C__
ignore this macro behind the curtain
Definition: sphdirectpcqueue.h:134
SPHSinglePCQueueAllocStrideDirectSpin
__C__ SPHLFEntryDirect_t SPHSinglePCQueueAllocStrideDirectSpin(SPHSinglePCQueue_t queue)
Allows the producer thread to allocate and initialize the header of a queue entry for access....
SPHSinglePCQueueGetNextEntryDirect
__C__ SPHLFEntryDirect_t SPHSinglePCQueueGetNextEntryDirect(SPHSinglePCQueue_t queue)
Allows the consumer to get the next allocated queue entry from the specified single producer single c...
SPHLFEntryDirectSubcat
static int SPHLFEntryDirectSubcat(SPHLFEntryDirect_t directHandle)
Return the entry sub-category for the entry specified by the direct entry handle.
Definition: sphdirectpcqueue.h:308
SPHLFEntryDirectIsTimestamped
static int SPHLFEntryDirectIsTimestamped(SPHLFEntryDirect_t directHandle)
Return the status of the entry specified by the direct entry handle.
Definition: sphdirectpcqueue.h:270
SPHLFEntryDirectIsComplete
static int SPHLFEntryDirectIsComplete(SPHLFEntryDirect_t directHandle)
Return the status of the entry specified by the direct entry handle.
Definition: sphdirectpcqueue.h:256
SPHLFEntryDirectCategory
static int SPHLFEntryDirectCategory(SPHLFEntryDirect_t directHandle)
Return the entry category for the entry specified by the direct entry handle.
Definition: sphdirectpcqueue.h:286
SPHSinglePCQueueAllocStrideDirectSpinPause
__C__ SPHLFEntryDirect_t SPHSinglePCQueueAllocStrideDirectSpinPause(SPHSinglePCQueue_t queue)
Allows the producer thread to allocate and initialize the header of a queue entry for access....
SPHSinglePCQueueAllocStrideDirect
__C__ SPHLFEntryDirect_t SPHSinglePCQueueAllocStrideDirect(SPHSinglePCQueue_t queue)
Allows the producer thread to allocate and initialize the header of a queue entry for access....
SPHSinglePCQueueFreeNextEntryDirect
__C__ int SPHSinglePCQueueFreeNextEntryDirect(SPHSinglePCQueue_t queue, SPHLFEntryDirect_t next_entry)
Allows the consumer to free the queue entry it just processed (using SPHSinglePCQueueGetNextComplete)...
SPHLFEntryDirectGetPtrAligned
static void * SPHLFEntryDirectGetPtrAligned(SPHLFEntryDirect_t directHandle, size_t alignval)
Return the first free byte address, with required alignment, within the direct entry specified by the...
Definition: sphdirectpcqueue.h:213
sphlfentry.h
Shared Persistent Heap, logger/queue etc event entry status, update, and access functions.
sphLFEntryID_t
unsigned int sphLFEntryID_t
Aggregate type for handling sphLogEntryLayout_t.
Definition: sphlfentry.h:77
sphsinglepcqueue.h
Shared Persistent Heap, single producer single consumer queue. For shared memory multi-thread/multi-c...
SPHSinglePCQueue_t
void * SPHSinglePCQueue_t
Handle to an instance of SPH Lock Free Single Producer, Single Consumer Queue.
Definition: sphsinglepcqueue.h:180
SPHLFEntryHeader_t
Instance of a Lock Free Entry Header.
Definition: sphlfentry.h:95
SPHLFEntryHeader_t::entryID
sphLFEntry_t entryID
Definition: sphlfentry.h:97
sphLFEntryLayout_t::subcat
unsigned int subcat
Definition: sphlfentry.h:71
sphLFEntryLayout_t::timestamped
unsigned int timestamped
Definition: sphlfentry.h:63
sphLFEntryLayout_t::category
unsigned int category
Definition: sphlfentry.h:69
sphLFEntryLayout_t::valid
unsigned int valid
Definition: sphlfentry.h:61
sphLFEntry_t
Union of Entry details with 32-bit word for atomic update.
Definition: sphlfentry.h:81
sphLFEntry_t::detail
sphLFEntryLayout_t detail
Definition: sphlfentry.h:85
sphLFEntry_t::idUnit
sphLFEntryID_t idUnit
Definition: sphlfentry.h:83