#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <signal.h>#include <string.h>#include <errno.h>#include <sys/time.h>#include <pthread.h>#include <ngc/core/ngcb.h>Go to the source code of this file.
Classes | |
| struct | ngcb_sema_t |
| struct | ngcb_lock_t |
Macros | |
| #define | _REENTRANT |
| #define | NGC_CCV 11 |
| #define | ngcbCPU_PROFILE_DMA 1 |
| #define | ngcbCPU_PROFILE_UDP 2 |
| #define | ngcbCPU_ANY -1 |
| #define | ngcbCPU_SHARED -2 |
| #define | ngcbCPU_HIGH -3 |
| #define | ngcbCPU_EXACT 0x1 |
| #define | ngcbCPU_EXCLUDE 0x2 |
| #define | ngcbGetAbsTime(t) |
| #define | ngcbSEM_FAST 0 |
| #define | ngcbSEM_CHECKED 1 |
| #define | ngcbPRI_TS 1 |
| #define | ngcbPRI_IA 2 |
| #define | ngcbPRI_RT 3 |
| #define | ngcbTQ_DEF 0 |
| #define | ngcbTQ_NC -1 |
| #define | ngcbTQ_INF -2 |
| #define | ngcbClockWait(fd, waitTime) |
| #define | ngcbPROC_MAX_SET 8 |
| #define | ngcbPROC_MAX_PROC 1024 |
| #define | ngcbProcId(x) |
| #define | ngcbProcNum(x) |
Typedefs | |
| typedef pthread_t | ngcb_thread_t |
| typedef struct timespec | ngcb_abstime_t |
Functions | |
| int | ngcbSetPrio (int priority, int schedClass, int quantum) |
| int | ngcbGetPrio (int *priority, int *schedClass, int *quantum) |
| void | ngcbClockInit (void) |
| void | ngcbClockGet (ngcb_time_hr *t) |
| void | ngcbClockGetAbs (ngcb_time_hr *t) |
| double | ngcbTimeStamp () |
| uint64_t | ngcbTimeStamp64 () |
| int | _ngcbClockWait (int fd, int waitTime) |
| int | ngcbThrCreate (void *(*startFunc)(void *), void *arg, size_t stack, ngcb_thread_t *thread) |
| void | ngcbThrExit (void *status) |
| int | ngcbThrCancel (ngcb_thread_t thread) |
| int | ngcbThrKill (ngcb_thread_t thread, int sig) |
| int | ngcbThrJoin (ngcb_thread_t thread) |
| ngcb_thread_t | ngcbThrId (void) |
| int | ngcbThrEqual (ngcb_thread_t t1, ngcb_thread_t t2) |
| int | ngcbCpuNumCores (void) |
| int | ngcbCpuRT (void) |
| int | ngcbCpu2Thread (ngcb_thread_t thread, int cpu, int flag) |
| int | ngcbCpuAssign (int cpu, int flag) |
| void | ngcbCpuShow (const char *name) |
| int | ngcbCpuDisableLatencyStates (char *erms) |
| void | ngcbCpuResetLatencyStates (int fd) |
| int | ngcbSemInit (ngcb_sema_t *sp, unsigned int count, int type, void *arg) |
| int | ngcbSemDestroy (ngcb_sema_t *sp) |
| int | ngcbSemLock (ngcb_sema_t *sp) |
| int | ngcbSemUnlock (ngcb_sema_t *sp) |
| int | ngcbSemTryLock (ngcb_sema_t *sp) |
| int | ngcbSemPost (ngcb_sema_t *sp) |
| int | ngcbSemSet (ngcb_sema_t *sp, unsigned int cnt) |
| int | ngcbSemWait (ngcb_sema_t *sp) |
| size_t | ngcbSemWaitCnt (ngcb_sema_t *sp, size_t cnt) |
| int | ngcbSemWaitAbsTime (ngcb_sema_t *sp, ngcb_abstime_t *absTime) |
| int | ngcbSemTryWait (ngcb_sema_t *sp) |
| size_t | ngcbSemCnt (ngcb_sema_t *sp) |
| int | ngcbRwLockInit (ngcb_lock_t *rwlp, int type, void *arg) |
| int | ngcbRwLockDestroy (ngcb_lock_t *rwlp) |
| int | ngcbRwRdLock (ngcb_lock_t *rwlp) |
| int | ngcbRwTryRdLock (ngcb_lock_t *rwlp) |
| int | ngcbRwWrLock (ngcb_lock_t *rwlp) |
| int | ngcbRwTryWrLock (ngcb_lock_t *rwlp) |
| int | ngcbRwUnlock (ngcb_lock_t *rwlp) |
| int | ngcbProcCreate (void(*calcProcess)(void *), int n, char *erms) |
| int | ngcbProcCreate2 (void(*calcProcess)(void *), int n, size_t stack, char *erms) |
| int | ngcbProcWaitStart (int procId) |
| int | ngcbProcWaitTrigger (int procId) |
| int | ngcbProcAck (int procId) |
| int | ngcbProcStart (int setId) |
| int | ngcbProcTrigger (int setId) |
| int | ngcbProcWaitAck (int setId) |
| int | ngcbProcSync (int procId) |
| void | ngcbProcJoin (int setId) |
| void | ngcbProcFree (int setId) |
Variables | |
| int | ngcbPrio |
| int | ngcbCpuProfile |
| #define _REENTRANT |
| #define NGC_CCV 11 |
CC version
| #define ngcbClockWait | ( | fd, | |
| waitTime ) |
High precision microsleep macro.
| #define ngcbCPU_ANY -1 |
any CPU
| #define ngcbCPU_EXACT 0x1 |
exact this CPU
| #define ngcbCPU_EXCLUDE 0x2 |
exclude this CPU
| #define ngcbCPU_HIGH -3 |
high-priority CPUs
| #define ngcbCPU_PROFILE_DMA 1 |
DMA interrupts
| #define ngcbCPU_PROFILE_UDP 2 |
UDP RT-polling
| #define ngcbCPU_SHARED -2 |
shared CPUs
| #define ngcbGetAbsTime | ( | t | ) |
Read the real-time clock (absulute time since UNIX epoch)
| #define ngcbPRI_IA 2 |
inter-active class id
| #define ngcbPRI_RT 3 |
real-time class id
| #define ngcbPRI_TS 1 |
time-sharing class id
| #define ngcbPROC_MAX_PROC 1024 |
Maximum number of processes per set
| #define ngcbPROC_MAX_SET 8 |
Maximum number of processing sets
| #define ngcbProcId | ( | x | ) |
Get process id from argument.
| #define ngcbProcNum | ( | x | ) |
Get process number from id.
| #define ngcbSEM_CHECKED 1 |
Semaphore with error-checking
| #define ngcbSEM_FAST 0 |
Fast semaphore
| #define ngcbTQ_DEF 0 |
default time quantum
| #define ngcbTQ_INF -2 |
infinite time quantum
| #define ngcbTQ_NC -1 |
don't change time quantum
| typedef struct timespec ngcb_abstime_t |
Absolute time
| typedef pthread_t ngcb_thread_t |
Thread type
| int _ngcbClockWait | ( | int | fd, |
| int | waitTime ) |
Suspend process execution for waitTime microseconds. The sleep can be interrupted by writing to the file descriptor fd which will be closed in that case. If fd has a negative value then the sleep cannot be interrupted.
| void ngcbClockGet | ( | ngcb_time_hr * | t | ) |
Read a high resolution timestamp from the most stable available clock. To be used to measure time differences.
| void ngcbClockGetAbs | ( | ngcb_time_hr * | t | ) |
Read a high resolution absolute timestamp representing the seconds since UNIX epoch. The functuion uses the most precise available clock.
| void ngcbClockInit | ( | void | ) |
Select and initialize the high resolution clock.
| int ngcbCpu2Thread | ( | ngcb_thread_t | thread, |
| int | cpu, | ||
| int | flag ) |
Assign CPUs to a thread.
| int ngcbCpuAssign | ( | int | cpu, |
| int | flag ) |
Assign CPUs to the current process.
| int ngcbCpuDisableLatencyStates | ( | char * | erms | ) |
Disable CPU DMA latency states
| int ngcbCpuNumCores | ( | void | ) |
Return the number of available CPU cores.
| void ngcbCpuResetLatencyStates | ( | int | fd | ) |
Reset CPU DMA latency states to default value
| int ngcbCpuRT | ( | void | ) |
Return the lowest number of the RT-service CPUs.
| void ngcbCpuShow | ( | const char * | name | ) |
Print out CPU assignment (debugging function).
| int ngcbGetPrio | ( | int * | priority, |
| int * | schedClass, | ||
| int * | quantum ) |
Get the process scheduling priority,
| int ngcbProcAck | ( | int | procId | ) |
Acknowledge that the process is ready to get the next data.
| int ngcbProcCreate | ( | void(* | calcProcess )(void *), |
| int | n, | ||
| char * | erms ) |
Create a set of n user defined calculation threads with default stack size (1M) using the ngcbProc... routines to synchronize.
| int ngcbProcCreate2 | ( | void(* | calcProcess )(void *), |
| int | n, | ||
| size_t | stack, | ||
| char * | erms ) |
Create a set of n user defined calculation threads using the ngcbProc... routines to synchronize. The stack size is given in bytes. When the stack size is set to zero then the system default value (1M) is used.
| void ngcbProcFree | ( | int | setId | ) |
Free all thread-resources in set.
| void ngcbProcJoin | ( | int | setId | ) |
Join all threads in set.
| int ngcbProcStart | ( | int | setId | ) |
Perform synchronous start of a set of threads.
| int ngcbProcSync | ( | int | procId | ) |
Synchronize a set of threads created with ngcbProcCreate() from inside the threads.
| int ngcbProcTrigger | ( | int | setId | ) |
Send trigger to a set of threads.
| int ngcbProcWaitAck | ( | int | setId | ) |
Wait for acknowledge from a set threads.
| int ngcbProcWaitStart | ( | int | procId | ) |
Wait for start signal from main process.
| int ngcbProcWaitTrigger | ( | int | procId | ) |
Wait for next trigger from main process.
| int ngcbRwLockDestroy | ( | ngcb_lock_t * | rwlp | ) |
Destroy a readers/writer lock pointed to by rwlp.
| int ngcbRwLockInit | ( | ngcb_lock_t * | rwlp, |
| int | type, | ||
| void * | arg ) |
Initialize a new readers/writer lock.
| int ngcbRwRdLock | ( | ngcb_lock_t * | rwlp | ) |
Get a read lock on the readers/writer lock pointed to by rwlp. If the readers/writer lock is currently locked for writing, the calling thread blocks until the write lock is freed. Multiple threads may simultaneously hold a read lock on a readers/writer lock.
| int ngcbRwTryRdLock | ( | ngcb_lock_t * | rwlp | ) |
Try to get a read lock on the readers/writer lock pointed to by rwlp. If the readers/writer lock is locked for writing, it returns (-1). Otherwise, the read lock is acquired.
| int ngcbRwTryWrLock | ( | ngcb_lock_t * | rwlp | ) |
Try to get a write lock on the readers/writer lock pointed to by rwlp. If the readers/writer lock is currently locked for reading or writing, it returns (-1).
| int ngcbRwUnlock | ( | ngcb_lock_t * | rwlp | ) |
Unlock a readers/writer lock pointed to by rwlp. If the readers/writer lock is currently locked for writing, the write-lock is released and all suspended readers or writers are unlocked. If the readers/writer lock is currently locked for reading then the number of readers is decremented. When the number of readers becomes zero the read-lock is released and one of the other threads that is waiting for the readers/writer lock will be unblocked.
| int ngcbRwWrLock | ( | ngcb_lock_t * | rwlp | ) |
Get a write lock on the readers/writer lock pointed to by rwlp. If the readers/writer lock is currently locked for reading or writing, the calling thread blocks until all the read/write locks are freed. At any given time, only one thread may have a write lock on a readers/writer lock.
| size_t ngcbSemCnt | ( | ngcb_sema_t * | sp | ) |
Return the current counter value of the specified semaphore.
| int ngcbSemDestroy | ( | ngcb_sema_t * | sp | ) |
Destroy the specified semphore.
| int ngcbSemInit | ( | ngcb_sema_t * | sp, |
| unsigned int | count, | ||
| int | type, | ||
| void * | arg ) |
Create a new counting semaphore. The count specifies the initial semaphore counter value. Depending on the value of type either a fast (ngcbSEM_FAST) or a checked (ngcbSEM_CHECKED) semaphore will be created.
| int ngcbSemLock | ( | ngcb_sema_t * | sp | ) |
Acquire the fast lock associated with the semaphore. The function will block until the lock is available or an error occured (if error checking is requested).
| int ngcbSemPost | ( | ngcb_sema_t * | sp | ) |
Increment the semaphore counter for the specified semaphore.
| int ngcbSemSet | ( | ngcb_sema_t * | sp, |
| unsigned int | cnt ) |
Set the semaphore counter for the specified semaphore.
| int ngcbSemTryLock | ( | ngcb_sema_t * | sp | ) |
Try to get the fast lock associated with the semaphore. If the lock is not available, the function returns (-1). Otherwise the lock is acquired and zero is returned.
| int ngcbSemTryWait | ( | ngcb_sema_t * | sp | ) |
Decrement the semphore counter for the specified semaphore. If the counter was zero, the function returns (-1).
| int ngcbSemUnlock | ( | ngcb_sema_t * | sp | ) |
Release the fast lock associated with the semaphore.
| int ngcbSemWait | ( | ngcb_sema_t * | sp | ) |
Decrements the semphore counter for the specified semaphore. If the counter was zero, the calling process is suspended until the semaphore is posted.
| int ngcbSemWaitAbsTime | ( | ngcb_sema_t * | sp, |
| ngcb_abstime_t * | absTime ) |
Decrement the semphore counter for the specified semaphore. If the counter was zero, the calling process is suspended until either the semphore is posted or the given absolute time has been reached. When the semaphore counter is still zero the function returns (-1).
| size_t ngcbSemWaitCnt | ( | ngcb_sema_t * | sp, |
| size_t | cnt ) |
Suspend the calling process until the semaphore counter value is equal to or greater than cnt. The function returns the actual semaphore counter value.
| int ngcbSetPrio | ( | int | priority, |
| int | schedClass, | ||
| int | quantum ) |
Set the process scheduling priority,
| int ngcbThrCancel | ( | ngcb_thread_t | thread | ) |
Cancel a thread defined by its thread-id.
| int ngcbThrCreate | ( | void *(* | startFunc )(void *), |
| void * | arg, | ||
| size_t | stack, | ||
| ngcb_thread_t * | thread ) |
Create a new thread. The stack size is given in bytes. When the stack size is set to zero then the system default value (4M) is used.
| int ngcbThrEqual | ( | ngcb_thread_t | t1, |
| ngcb_thread_t | t2 ) |
Test the equality of the two threads t1 and t2. The function returns non-zero if t1 and t2 refer to the same thread, otherwise zero.
| void ngcbThrExit | ( | void * | status | ) |
Function to be be called when exitig from a thread.
| ngcb_thread_t ngcbThrId | ( | void | ) |
Return the thread-id of the calling process.
| int ngcbThrJoin | ( | ngcb_thread_t | thread | ) |
Waits until the thread given by its thread-id exits.
| int ngcbThrKill | ( | ngcb_thread_t | thread, |
| int | sig ) |
Send a signal to a thread defined by its thread-id.
| double ngcbTimeStamp | ( | ) |
Read a high-resolution timestamp and return a double precision floating point value representing the seconds since UNIX epoch.
| uint64_t ngcbTimeStamp64 | ( | ) |
Read a high-resolution timestamp and return a double precision floating point value representing the seconds since UNIX epoch. The value is stored in 64-bit data field.
|
extern |
CPU profile
|
extern |
Global flag to apply priority setting