| Apama
    9.10.0.4.289795
    | 
Provides macros for threading and concurrency primitives. More...
#include <pthread.h>#include <semaphore.h>#include <unistd.h>#include <signal.h>Go to the source code of this file.
| Macros | |
| #define | SAG_MUTEX_LOCK(m) pthread_mutex_lock(&m) | 
| Lock the given mutex.  More... | |
| #define | SAG_MUTEX_UNLOCK(m) pthread_mutex_unlock(&m) | 
| Unlock the given mutex.  More... | |
| #define | SAG_MUTEX_INIT(m) pthread_mutex_init(&m, NULL) | 
| Create a mutex.  More... | |
| #define | SAG_MUTEX_DESTROY(m) pthread_mutex_destroy(&m) | 
| Destroy a mutex.  More... | |
| #define | SAG_MUTEX_T pthread_mutex_t | 
| The type of a mutex.  More... | |
| #define | SAG_SEMA_WAIT(s) {while (sem_wait(&s));} | 
| Wait on the given semaphore.  More... | |
| #define | SAG_SEMA_POST(s) sem_post(&s) | 
| Post the given semaphore.  More... | |
| #define | SAG_SEMA_INIT(s) sem_init(&s, 0, 0) | 
| Create a semaphore.  More... | |
| #define | SAG_SEMA_DESTROY(s) sem_destroy(&s) | 
| Destroy a semaphore.  More... | |
| #define | SAG_SEMA_T sem_t | 
| The type of a semaphore.  More... | |
| #define | SAG_THREAD_CREATE(id, func, params) pthread_create(& id, NULL, func, params) | 
| Create a thread which will call func with params. id will be written with the thread ID.  More... | |
| #define | SAG_THREAD_JOIN(id) pthread_join(id, NULL) | 
| Wait the given thread to terminate.  More... | |
| #define | SAG_THREAD_RETURN return NULL; | 
| The statement to return from a thread function.  More... | |
| #define | SAG_THREAD_T pthread_t | 
| The type of a thread.  More... | |
| #define | SAG_THREAD_RET_T void* | 
| The return type of a thread function.  More... | |
Provides macros for threading and concurrency primitives.
Note that you should only use these if your compiler is too old to support C++11 threading primitives. On modern compilers you should use std::thread.
These macros are defined for both windows and linux to allow creation of a cross-platform plugin. If you don't need your plugin to work on multiple platforms then you can use platform-specific threading mechanisms if easier.
This file defines three types:
There are functions to init and destroy mutexs and semaphore variables:
The mutex/semaphore-specific functions:
Threads are created with:
SAG_THREAD_T id; SAG_THREAD_CREATE(id, func, args)
func must match this type:
SAG_THREAD_RET_T func(void* args) { ... SAG_THREAD_RETURN; }
You can join a running thread with SAG_THREAD_JOIN(id);
| #define SAG_MUTEX_DESTROY | ( | m | ) | pthread_mutex_destroy(&m) | 
Destroy a mutex.
| #define SAG_MUTEX_INIT | ( | m | ) | pthread_mutex_init(&m, NULL) | 
Create a mutex.
| #define SAG_MUTEX_LOCK | ( | m | ) | pthread_mutex_lock(&m) | 
Lock the given mutex.
| #define SAG_MUTEX_T pthread_mutex_t | 
The type of a mutex.
| #define SAG_MUTEX_UNLOCK | ( | m | ) | pthread_mutex_unlock(&m) | 
Unlock the given mutex.
| #define SAG_SEMA_DESTROY | ( | s | ) | sem_destroy(&s) | 
Destroy a semaphore.
| #define SAG_SEMA_INIT | ( | s | ) | sem_init(&s, 0, 0) | 
Create a semaphore.
| #define SAG_SEMA_POST | ( | s | ) | sem_post(&s) | 
Post the given semaphore.
| #define SAG_SEMA_T sem_t | 
The type of a semaphore.
| #define SAG_SEMA_WAIT | ( | s | ) | {while (sem_wait(&s));} | 
Wait on the given semaphore.
| #define SAG_THREAD_CREATE | ( | id, | |
| func, | |||
| params | |||
| ) | pthread_create(& id, NULL, func, params) | 
Create a thread which will call func with params. id will be written with the thread ID.
| #define SAG_THREAD_JOIN | ( | id | ) | pthread_join(id, NULL) | 
Wait the given thread to terminate.
| #define SAG_THREAD_RET_T void* | 
The return type of a thread function.
| #define SAG_THREAD_RETURN return NULL; | 
The statement to return from a thread function.
| #define SAG_THREAD_T pthread_t | 
The type of a thread.
 1.8.8
 1.8.8