Shared Persistent Heap Data Environment Manual  1.1.0
sphdirectpcqueue.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 IBM Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation, Steven Munroe - initial API and implementation
10  */
11 #ifndef SRC_SPHDIRECTPCQUEUE_H_
12 #define SRC_SPHDIRECTPCQUEUE_H_
13 #include <stdint.h>
14 
124 #include "sastype.h"
125 #include "sasatom.h"
126 #include "sphlfentry.h"
127 #include "sphsinglepcqueue.h"
128 
129 
131 #ifdef __cplusplus
132 #define __C__ "C"
133 #else
134 #define __C__
135 #endif
136 
146 typedef void* SPHLFEntryDirect_t;
147 
158 static inline int
160  sphLFEntryID_t entry_template,
161  int catcode, int subcode)
162 {
163  int rc = 1;
164  SPHLFEntryHeader_t *entryPtr = (SPHLFEntryHeader_t*)directHandle;
165  sphLFEntry_t entrytemp;
166 
168  /* the template should have allocated and len already set. */
169  entrytemp.idUnit = entry_template;
170  entrytemp.detail.valid = 1;
171  entrytemp.detail.category = catcode;
172  entrytemp.detail.subcat = subcode;
173 
174  entryPtr->entryID.idUnit = entrytemp.idUnit;
175 
176  return (rc);
177 }
178 
191 static inline void*
193 {
194  char *ptr = (char*)directHandle + sizeof (sphLFEntry_t);
195 
196  return ((void*)ptr);
197 }
198 
212 static inline void*
214  size_t alignval)
215 {
216  uintptr_t ptr = (uintptr_t)directHandle;
217  uintptr_t adjust = alignval - 1;
218  uintptr_t mask = ~adjust;
219 
220  ptr = ((ptr + sizeof (sphLFEntry_t) + adjust) & mask);
221 
222  return ((void*)ptr);
223 }
224 
237 static inline void*
238 SPHLFEntryDirectIncAndAlign (void *directptr, size_t incval, size_t alignval)
239 {
240  uintptr_t ptr = (uintptr_t)directptr;
241  uintptr_t adjust = alignval - 1;
242  uintptr_t mask = ~adjust;
243 
244  ptr = ((ptr + incval + adjust) & mask);
245  return ((void*)ptr);
246 }
247 
255 static inline int
257 {
258  SPHLFEntryHeader_t *entryPtr = (SPHLFEntryHeader_t*)directHandle;
259 
260  return (entryPtr->entryID.detail.valid == 1);
261 }
262 
269 static inline int
271 {
272  SPHLFEntryHeader_t *entryPtr = (SPHLFEntryHeader_t*)directHandle;
273 
274  return ((entryPtr->entryID.detail.valid == 1)
275  &&(entryPtr->entryID.detail.timestamped == 1));
276 }
277 
285 static inline int
287 {
288  SPHLFEntryHeader_t *entryPtr = (SPHLFEntryHeader_t*)directHandle;
289  int result = -1;
290 #if 0
291  printf ("SPHLFEntryCategory(%p) entry=%p id=%x\n",
292  handlespace, entryPtr, entryPtr->entryID.idUnit);
293 #endif
294  if (entryPtr->entryID.detail.valid == 1)
295  result = entryPtr->entryID.detail.category;
296 
297  return (result);
298 }
299 
307 static inline int
309 {
310  SPHLFEntryHeader_t *entryPtr = (SPHLFEntryHeader_t*)directHandle;
311  int result = -1;
312 #if 0
313  printf ("SPHLFEntrySubcat(%p) entry=%p id=%x\n",
314  handlespace, entryPtr, entryPtr->entryID.idUnit);
315 #endif
316  if (entryPtr->entryID.detail.valid == 1)
317  result = entryPtr->entryID.detail.subcat;
318 
319  return (result);
320 }
321 
330 extern __C__ sphLFEntryID_t
332 
357 
383 
411 
429 
449 
467 
487 extern __C__ int
489  SPHLFEntryDirect_t next_entry);
490 
510 
517 extern __C__ int
519 
520 #endif /* SRC_SPHDIRECTPCQUEUE_H_ */
__C__ SPHLFEntryDirect_t SPHSinglePCQueueGetNextCompleteDirectSpinPause(SPHSinglePCQueue_t queue)
Allows the consumer to get the next completed queue entry from the specified single producer single c...
static int SPHLFEntryDirectIsTimestamped(SPHLFEntryDirect_t directHandle)
Return the status of the entry specified by the direct entry handle.
Definition: sphdirectpcqueue.h:270
Instance of a Lock Free Entry Header.
Definition: sphlfentry.h:95
__C__ int SPHSinglePCQueueEntryIsCompleteDirect(SPHLFEntryDirect_t directHandle)
Return the status of the entry specified by the direct entry handle.
__C__ SPHLFEntryDirect_t SPHSinglePCQueueGetNextCompleteDirect(SPHSinglePCQueue_t queue)
Allows the consumer to get the next completed queue entry from the specified single producer single c...
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
sphLFEntryID_t idUnit
Definition: sphlfentry.h:83
__C__ sphLFEntryID_t SPHSinglePCQueueGetEntryTemplate(SPHSinglePCQueue_t queue)
Return the entry template for an existing Lock Free Single Producer Single Consumer Queue...
static int SPHLFEntryDirectIsComplete(SPHLFEntryDirect_t directHandle)
Return the status of the entry specified by the direct entry handle.
Definition: sphdirectpcqueue.h:256
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
Shared Persistent Heap, logger/queue etc event entry status, update, and access functions.
__C__ SPHLFEntryDirect_t SPHSinglePCQueueAllocStrideDirectSpin(SPHSinglePCQueue_t queue)
Allows the producer thread to allocate and initialize the header of a queue entry for access...
Type and functions for SAS atomic operations.
sphLFEntry_t entryID
Definition: sphlfentry.h:97
__C__ SPHLFEntryDirect_t SPHSinglePCQueueGetNextEntryDirect(SPHSinglePCQueue_t queue)
Allows the consumer to get the next allocated queue entry from the specified single producer single c...
unsigned int timestamped
Definition: sphlfentry.h:63
__C__ int SPHSinglePCQueueFreeNextEntryDirect(SPHSinglePCQueue_t queue, SPHLFEntryDirect_t next_entry)
Allows the consumer to free the queue entry it just processed (using SPHSinglePCQueueGetNextComplete)...
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
__C__ SPHLFEntryDirect_t SPHSinglePCQueueAllocStrideDirect(SPHSinglePCQueue_t queue)
Allows the producer thread to allocate and initialize the header of a queue entry for access...
#define sas_read_barrier()
Definition: sasatom.h:56
__C__ SPHLFEntryDirect_t SPHSinglePCQueueGetNextCompleteDirectSpin(SPHSinglePCQueue_t queue)
Allows the consumer to get the next completed queue entry from the specified single producer single c...
sphLFEntryLayout_t detail
Definition: sphlfentry.h:85
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
static int SPHLFEntryDirectSubcat(SPHLFEntryDirect_t directHandle)
Return the entry sub-category for the entry specified by the direct entry handle. ...
Definition: sphdirectpcqueue.h:308
unsigned int sphLFEntryID_t
Aggregate type for handling sphLogEntryLayout_t.
Definition: sphlfentry.h:77
__C__ SPHLFEntryDirect_t SPHSinglePCQueueAllocStrideDirectSpinPause(SPHSinglePCQueue_t queue)
Allows the producer thread to allocate and initialize the header of a queue entry for access...
Union of Entry details with 32-bit word for atomic update.
Definition: sphlfentry.h:81
#define __C__
ignore this macro behind the curtain
Definition: sphdirectpcqueue.h:134
unsigned int subcat
Definition: sphlfentry.h:71
void * SPHLFEntryDirect_t
Instance of a Lock Free event direct data Handle.
Definition: sphdirectpcqueue.h:146
unsigned int category
Definition: sphlfentry.h:69
void * SPHSinglePCQueue_t
Handle to an instance of SPH Lock Free Single Producer, Single Consumer Queue.
Definition: sphsinglepcqueue.h:180
Shared Persistent Heap, single producer single consumer queue. For shared memory multi-thread/multi-c...
unsigned int valid
Definition: sphlfentry.h:61
static int SPHLFEntryDirectCategory(SPHLFEntryDirect_t directHandle)
Return the entry category for the entry specified by the direct entry handle.
Definition: sphdirectpcqueue.h:286