![]() |
librnr
1.14.5
RoadNarrows Robotics Common Library 1
|
Example of librnr support for shared memory. More...
#include <time.h>#include <stdio.h>#include <string.h>#include <libgen.h>#include <unistd.h>#include <stdlib.h>#include <pthread.h>#include "rnr/rnrconfig.h"#include "rnr/log.h"#include "rnr/opts.h"#include "rnr/shm.h"#include "version.h"Go to the source code of this file.
Macros | |
| #define | N_PROCS 2 |
| number of processes | |
| #define | N_THREADS 2 |
| number of threads/process | |
| #define | WHO_CHILD 0 |
| child process | |
| #define | WHO_PARENT 1 |
| parent process | |
| #define | RED_QUEEN 0 |
| red queen identifier | |
| #define | CHESHIRE_CAT 1 |
| cheshire cat identifier | |
| #define | WHITE_QUEEN 2 |
| white queen identifier | |
| #define | MARCH_HARE 3 |
| march hare identifier | |
| #define | N_AINW_CHARS 4 |
| number of Alice in Wonderland characters | |
| #define | COLOR_RED_QUEEN LOG_COLOR_PRE LOG_COLOR_LIGHT_RED |
| red queen text color | |
| #define | COLOR_CHESHIRE_CAT LOG_COLOR_PRE LOG_COLOR_LIGHT_YELLOW |
| cheshire cat text color | |
| #define | COLOR_WHITE_QUEEN LOG_COLOR_PRE "1;37m" |
| white queen text color | |
| #define | COLOR_MARCH_HARE LOG_COLOR_PRE LOG_COLOR_LIGHT_BLUE |
| march hare text color | |
| #define | COLOR_POST LOG_COLOR_POST |
| post color string | |
Functions | |
| static int | init (int argc, char *argv[]) |
| Main initialization. More... | |
| static void | randseed () |
| Seed random number generator. | |
| static void | randusleep (uint_t max) |
| Sleep thread for a random time. More... | |
| static void | lock () |
| Lock mutex. | |
| static void | unlock () |
| Unlock mutex. | |
| static void * | threadmain (void *pArg) |
| Thread main. More... | |
| static int | createThreads () |
| Create all threads for process. More... | |
| static void | killThreads () |
| Kill all threads in process. | |
| static void | runExample (int who) |
| Run example for a process. | |
| int | main (int argc, char *argv[]) |
| Example main. More... | |
Variables | |
| static char * | Argv0 |
| the command | |
| static bool_t | OptsNoMutex = false |
| do [not] disable mutex | |
| static bool_t | OptsNoColor = false |
| do [not] disable color esc sequence | |
| static OptsPgmInfo_T | PgmInfo |
| Program information. More... | |
| static OptsInfo_T | OptsInfo [] |
| Command line options information. More... | |
| key_t | ShmKey = 0xdead4 |
| share memory key | |
| shm_mutex_t | ShmMutex |
| share memory mutex | |
| uint_t | Seed |
| random generator seed | |
| int | Who |
| who: child or parent process | |
| pthread_t | Thread [2] |
| thread | |
| int | ThreadState [2] |
| thread run/die state | |
| char * | WhoName [2] = {" child", "parent"} |
| process name | |
| int | AinWCharId [2][2] |
| Alice in Wonderland character ids. More... | |
| char * | AinWCharName [4] |
| Alice in Wonderland character names. More... | |
| char * | Color [4] |
| Alice in Wonderland character text colors. More... | |
| char * | Say [4] |
| Alice in Wonderland character text. More... | |
Example of librnr support for shared memory.
Definition in file example_shm.c.
|
static |
Create all threads for process.
Definition at line 312 of file example_shm.c.
References AinWCharId, LOGSYSERROR, N_THREADS, NULL, Thread, threadmain(), ThreadState, Who, and WhoName.
Referenced by runExample().
|
static |
Main initialization.
| argc | Command-line argument count. |
| argv | Command-line argument list. |
Definition at line 121 of file example_shm.c.
References Argv0, OptsGet(), and PkgInfo.
Referenced by main().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Example main.
| argc | Command-line argument count. |
| argv | Command-line argument list. |
Definition at line 398 of file example_shm.c.
References init(), LOGERROR, runExample(), WHO_CHILD, and WHO_PARENT.
|
static |
Sleep thread for a random time.
Actual sleep time will be between [0, max].
| max | Maximum time to sleep (usec). |
Definition at line 222 of file example_shm.c.
References Seed.
Referenced by runExample(), and threadmain().
|
static |
Thread main.
| pArg | Pointer to character's id. |
Definition at line 263 of file example_shm.c.
References AinWCharName, Color, COLOR_POST, lock(), LOGDIAG1, N_THREADS, NULL, OptsNoColor, randusleep(), Say, ThreadState, unlock(), Who, and WhoName.
Referenced by createThreads().
| int AinWCharId[2][2] |
Alice in Wonderland character ids.
Definition at line 167 of file example_shm.c.
Referenced by createThreads().
| char* AinWCharName[4] |
Alice in Wonderland character names.
Definition at line 176 of file example_shm.c.
Referenced by threadmain().
| char* Color[4] |
Alice in Wonderland character text colors.
Definition at line 185 of file example_shm.c.
Referenced by threadmain().
|
static |
Command line options information.
Definition at line 82 of file example_shm.c.
|
static |
Program information.
Definition at line 69 of file example_shm.c.
| char* Say[4] |
Alice in Wonderland character text.
Definition at line 196 of file example_shm.c.
Referenced by threadmain().