diff --git a/3ano/1semestre/so/practice-exam/so+fso-1920-epnm-v2.pdf b/3ano/1semestre/so/practice-exam/so+fso-1920-epnm-v2.pdf new file mode 100644 index 0000000..812305c Binary files /dev/null and b/3ano/1semestre/so/practice-exam/so+fso-1920-epnm-v2.pdf differ diff --git a/3ano/1semestre/so/practice-exam/src/Makefile b/3ano/1semestre/so/practice-exam/src/Makefile new file mode 100644 index 0000000..f45931a --- /dev/null +++ b/3ano/1semestre/so/practice-exam/src/Makefile @@ -0,0 +1,21 @@ +CXX = g++ +CPPFLAGS=-Wall -Wfatal-errors -Wno-write-strings -Wno-unused-function -ggdb -pthread -Iinclude # -DEXCEPTION_POLICY or -DEXIT_POLICY +LDFLAGS = -Llib -lsoconcur + +OBJS=pfifo.o urgency.o + +TARGET = urgency + +.PHONY: all clean cleanall + +all: $(TARGET) + +urgency: $(OBJS) + $(CXX) $(CPPFLAGS) -o $@ $^ $(LDFLAGS) + +clean: + rm -fv *.o core + +cleanall: clean + rm -f $(TARGET) + diff --git a/3ano/1semestre/so/practice-exam/src/doc/html/bc_s.png b/3ano/1semestre/so/practice-exam/src/doc/html/bc_s.png new file mode 100644 index 0000000..224b29a Binary files /dev/null and b/3ano/1semestre/so/practice-exam/src/doc/html/bc_s.png differ diff --git a/3ano/1semestre/so/practice-exam/src/doc/html/bdwn.png b/3ano/1semestre/so/practice-exam/src/doc/html/bdwn.png new file mode 100644 index 0000000..940a0b9 Binary files /dev/null and b/3ano/1semestre/so/practice-exam/src/doc/html/bdwn.png differ diff --git a/3ano/1semestre/so/practice-exam/src/doc/html/closed.png b/3ano/1semestre/so/practice-exam/src/doc/html/closed.png new file mode 100644 index 0000000..98cc2c9 Binary files /dev/null and b/3ano/1semestre/so/practice-exam/src/doc/html/closed.png differ diff --git a/3ano/1semestre/so/practice-exam/src/doc/html/dbc_8h.html b/3ano/1semestre/so/practice-exam/src/doc/html/dbc_8h.html new file mode 100644 index 0000000..f8495c8 --- /dev/null +++ b/3ano/1semestre/so/practice-exam/src/doc/html/dbc_8h.html @@ -0,0 +1,108 @@ + + +
+ + + + +
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
Design-by-Contract module. +More...
+ +Go to the source code of this file.
++Macros | |
#define | check(condition, message) |
Checks the verification of an general algorithm assertion. More... | |
#define | require(condition, message) |
Checks the verification of a precondition. More... | |
#define | ensure(condition, message) |
Checks the verification of a postcondition. More... | |
#define | invariant(condition, message) |
Checks the verification of an invariant. More... | |
Design-by-Contract module.
+
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
Design-by-Contract module. +More...
++Files | |
file | dbc.h |
Design-by-Contract module. | |
+Macros | |
#define | check(condition, message) |
Checks the verification of an general algorithm assertion. More... | |
#define | require(condition, message) |
Checks the verification of a precondition. More... | |
#define | ensure(condition, message) |
Checks the verification of a postcondition. More... | |
#define | invariant(condition, message) |
Checks the verification of an invariant. More... | |
Design-by-Contract module.
+This module gives a better support for DbC in C++.
+When compared with assert.h
this module offers the following functionalities:
stderr
(with the identification and the precise location of the assertion), generates a segmentation fault (enabling a stack trace within a debugger like gdb
), and exits program execution;char*
exception with the description of the failed assertion.Debug settings:
assert.h
, this module accepts NDEBUG
macro definition to disable all assertion run-time verification.NDEBUG_CHECKS
, NDEBUG_PRECONDITIONS
, NDEBUG_POSTCONDITIONS
, and NDEBUG_INVARIANTS
.DEBUG_ONLY_PRECONDITIONS
ensures that only precondition debugging remains active (regardless of other debug definitions).#define check | +( | ++ | condition, | +
+ | + | + | message | +
+ | ) | ++ |
Checks the verification of an general algorithm assertion.
+This assertion verification can be disabled at compile time by defining the macro NDEBUG_CHECKS
.
[in] | condition | expression to assert its truthness |
[in] | message | text to be presented with error information when the assertion fails |
#define require | +( | ++ | condition, | +
+ | + | + | message | +
+ | ) | ++ |
Checks the verification of a precondition.
+This assertion verification can be disabled at compile time by defining the macro NDEBUG_PRECONDITIONS
.
[in] | condition | expression to assert its truthness |
[in] | message | text to be presented with error information when the assertion fails |
#define ensure | +( | ++ | condition, | +
+ | + | + | message | +
+ | ) | ++ |
Checks the verification of a postcondition.
+This assertion verification can be disabled at compile time by defining the macro NDEBUG_POSTCONDITIONS
.
[in] | condition | expression to assert its truthness |
[in] | message | text to be presented with error information when the assertion fails |
#define invariant | +( | ++ | condition, | +
+ | + | + | message | +
+ | ) | ++ |
Checks the verification of an invariant.
+This assertion verification can be disabled at compile time by defining the macro NDEBUG_INVARIANTS
.
[in] | condition | expression to assert its truthness |
[in] | message | text to be presented with error information when the assertion fails |
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
Process, System-V, and POSIX libraries wrapper module. +More...
++Files | |
file | process.h |
Process, System-V, and POSIX libraries wrapper module. | |
+Process handling | |
+ | |
pid_t | pfork (void) |
fork wrapper function. More... | |
pid_t | pwait (int *status) |
wait wrapper function. More... | |
pid_t | pwaitpid (pid_t pid, int *status, int options) |
waitpid wrapper function. More... | |
void | pkill (pid_t pid, int sig) |
kill wrapper function. More... | |
void | pexecl (const char *pathname, const char *arg,...) |
execl wrapper function. More... | |
void | psigaction (int signum, const struct sigaction *act, struct sigaction *oldact) |
sigaction wrapper function. More... | |
+System V - shared memory | |
| |
int | pshmget (key_t key, size_t size, int shmflg) |
shmget wrapper function. More... | |
int | pshmctl (int shmid, int cmd, struct shmid_ds *buf) |
shmctl wrapper function. More... | |
void * | pshmat (int shmid, const void *shmaddr, int shmflg) |
shmat wrapper function. More... | |
void | pshmdt (const void *shmaddr) |
shmdt wrapper function. More... | |
+System V - semaphores | |
| |
int | psemget (key_t key, int nsems, int semflg) |
semget wrapper function. More... | |
int | psemctl (int semid, int semnum, int cmd) |
semctl wrapper function. More... | |
+int | psemctl (int semid, int semnum, int cmd, void *u) |
void | psemop (int semid, struct sembuf *sops, size_t nsops) |
semop wrapper function. More... | |
+void | psem_up (int semid, short unsigned int index) |
Increment a semaphore (uses psemop()). | |
+void | psem_down (int semid, short unsigned int index) |
Decrements a semaphore (uses psemop()). | |
+void | psem_down2 (int semid, short unsigned int index1, unsigned int index2) |
Decrements atomically two semaphores in a System V semaphore array (uses psemop()). | |
+System V - message queues | |
| |
int | pmsgget (key_t key, int msgflg) |
msgget wrapper function. More... | |
int | pmsgctl (int msqid, int cmd, struct msqid_ds *buf) |
msgctl wrapper function. More... | |
void | pmsgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg) |
msgsnd wrapper function. More... | |
size_t | pmsgrcv (int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) |
msgrcv wrapper function. More... | |
+POSIX semaphores | |
+ | |
sem_t * | psem_open (const char *name, int oflag) |
sem_open wrapper function. More... | |
+sem_t * | psem_open (const char *name, int oflag, mode_t mode, unsigned int value) |
void | psem_close (sem_t *sem) |
sem_close wrapper function. More... | |
void | psem_unlink (const char *name) |
sem_unlink wrapper function. More... | |
void | psem_init (sem_t *sem, int pshared, unsigned int value) |
sem_init wrapper function. More... | |
void | psem_destroy (sem_t *sem) |
sem_destroy wrapper function. More... | |
void | psem_wait (sem_t *sem) |
sem_wait wrapper function. More... | |
int | psem_trywait (sem_t *sem) |
sem_trywait wrapper function. More... | |
int | psem_timedwait (sem_t *sem, const struct timespec *abs_timeout) |
sem_timedwait wrapper function. More... | |
void | psem_post (sem_t *sem) |
sem_post wrapper function. More... | |
+UNIX pipes | |
+ | |
void | ppipe (int pipefd[2]) |
pipe wrapper function. More... | |
FILE * | ppopen (const char *command, const char *type) |
popen wrapper function. More... | |
void | ppclose (FILE *stream) |
pclose wrapper function. More... | |
Process, System-V, and POSIX libraries wrapper module.
+This module removes defensive programming approach of native libraries.
+All implemented functions, have exactly the same arguments and/or result of the original function, with the exception of returning an error indication.
+Errors are handled by the implementation of two policies:
stderr
(with the identification of the errno error, and the precise location the call), generates a segmentation fault (enabling a stack trace within a debugger like gdb
), and exits program execution;int
exception with the (errno) status error returned by the original function.System V group of IPC mechanisms
+There are three resources for IPC: shared memory, semaphores, and message queues.
+Common to all, is resource handling through a non-negative integer identifier. After proper creation and initialization, different processes can establish communication using the same integer identifier.
+A key (key_t
) is used to establish this common identifier. There are three possibilities to define a key:
IPC_PRIVATE
: In this case an alternative channel to communicate the identifier between processes is necessary (parent/child fork, file system, ...).ftok
function to generate a key from a path and a byte integer.Usage:
+msgget
/semget
/shmget
with a key and IPC_CREAT
and IPC_EXCL
flagsmsgget
/semget
/shmget
with a key and other arguments as zeropid_t pfork | +( | +void | +) | ++ |
pid_t pwait | +( | +int * | +status | ) | ++ |
pid_t pwaitpid | +( | +pid_t | +pid, | +
+ | + | int * | +status, | +
+ | + | int | +options | +
+ | ) | ++ |
waitpid
wrapper function.
Other documentation in
man 2 waitpid
void pkill | +( | +pid_t | +pid, | +
+ | + | int | +sig | +
+ | ) | ++ |
void pexecl | +( | +const char * | +pathname, | +
+ | + | const char * | +arg, | +
+ | + | + | ... | +
+ | ) | ++ |
void psigaction | +( | +int | +signum, | +
+ | + | const struct sigaction * | +act, | +
+ | + | struct sigaction * | +oldact | +
+ | ) | ++ |
sigaction
wrapper function.
Other documentation in
man 2 sigaction
int pshmget | +( | +key_t | +key, | +
+ | + | size_t | +size, | +
+ | + | int | +shmflg | +
+ | ) | ++ |
shmget
wrapper function.
Other documentation in
man 2 shmget
int pshmctl | +( | +int | +shmid, | +
+ | + | int | +cmd, | +
+ | + | struct shmid_ds * | +buf | +
+ | ) | ++ |
shmctl
wrapper function.
Other documentation in
man 2 shmctl
void* pshmat | +( | +int | +shmid, | +
+ | + | const void * | +shmaddr, | +
+ | + | int | +shmflg | +
+ | ) | ++ |
void pshmdt | +( | +const void * | +shmaddr | ) | ++ |
int psemget | +( | +key_t | +key, | +
+ | + | int | +nsems, | +
+ | + | int | +semflg | +
+ | ) | ++ |
semget
wrapper function.
nsems > 0
Other documentation in
man 2 semget
int psemctl | +( | +int | +semid, | +
+ | + | int | +semnum, | +
+ | + | int | +cmd | +
+ | ) | ++ |
semctl
wrapper function.
Other documentation in
man 2 semctl
void psemop | +( | +int | +semid, | +
+ | + | struct sembuf * | +sops, | +
+ | + | size_t | +nsops | +
+ | ) | ++ |
int pmsgget | +( | +key_t | +key, | +
+ | + | int | +msgflg | +
+ | ) | ++ |
msgget
wrapper function.
Other documentation in
man 2 msgget
int pmsgctl | +( | +int | +msqid, | +
+ | + | int | +cmd, | +
+ | + | struct msqid_ds * | +buf | +
+ | ) | ++ |
msgctl
wrapper function.
Other documentation in
man 2 msgctl
void pmsgsnd | +( | +int | +msqid, | +
+ | + | const void * | +msgp, | +
+ | + | size_t | +msgsz, | +
+ | + | int | +msgflg | +
+ | ) | ++ |
msgsnd
wrapper function.
Other documentation in
man 2 msgsnd
size_t pmsgrcv | +( | +int | +msqid, | +
+ | + | void * | +msgp, | +
+ | + | size_t | +msgsz, | +
+ | + | long | +msgtyp, | +
+ | + | int | +msgflg | +
+ | ) | ++ |
msgrcv
wrapper function.
Other documentation in
man 2 msgrcv
sem_t* psem_open | +( | +const char * | +name, | +
+ | + | int | +oflag | +
+ | ) | ++ |
sem_open
wrapper function.
Other documentation in
man 3 sem_open
void psem_close | +( | +sem_t * | +sem | ) | ++ |
sem_close
wrapper function.
sem != NULL
Other documentation in
man 3 sem_close
void psem_unlink | +( | +const char * | +name | ) | ++ |
sem_unlink
wrapper function.
Other documentation in
man 3 sem_unlink
void psem_init | +( | +sem_t * | +sem, | +
+ | + | int | +pshared, | +
+ | + | unsigned int | +value | +
+ | ) | ++ |
sem_init
wrapper function.
sem != NULL
Other documentation in
man 3 sem_init
void psem_destroy | +( | +sem_t * | +sem | ) | ++ |
sem_destroy
wrapper function.
sem != NULL
Other documentation in
man 3 sem_destroy
void psem_wait | +( | +sem_t * | +sem | ) | ++ |
sem_wait
wrapper function.
sem != NULL
Other documentation in
man 3 sem_wait
int psem_trywait | +( | +sem_t * | +sem | ) | ++ |
sem_trywait
wrapper function.
sem != NULL
Other documentation in
man 3 sem_trywait
!=0
) on success, false (0
) if semaphore is zero int psem_timedwait | +( | +sem_t * | +sem, | +
+ | + | const struct timespec * | +abs_timeout | +
+ | ) | ++ |
sem_timedwait
wrapper function.
sem != NULL
Other documentation in
man 3 sem_timedwait
!=0
) on success, false (0
) if timeout has expired before being able to decrement the semaphore void psem_post | +( | +sem_t * | +sem | ) | ++ |
sem_post
wrapper function.
sem != NULL
Other documentation in
man 3 sem_post
void ppipe | +( | +int | +pipefd[2] | ) | ++ |
FILE* ppopen | +( | +const char * | +command, | +
+ | + | const char * | +type | +
+ | ) | ++ |
popen
wrapper function.
command != NULL
type != NULL
Other documentation in
man 3 popen
void ppclose | +( | +FILE * | +stream | ) | ++ |
pclose
wrapper function.
stream != NULL
Other documentation in
man 3 pclose
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
POSIX threads library wrapper module. +More...
++Files | |
file | thread.h |
POSIX threads library wrapper module. | |
+Thread handling | |
+ + | |
int | thread_equal (pthread_t t1, pthread_t t2) |
pthread_equal wrapper function. More... | |
void | thread_create (pthread_t *t, pthread_attr_t *attr, void *(*thread_main)(void *), void *arg) |
pthread_create wrapper function. More... | |
pthread_t | thread_self () |
pthread_self wrapper function. More... | |
void | thread_sched_yield (void) |
sched_yield wrapper function. More... | |
void | thread_exit (void *retval) |
pthread_exit wrapper function. More... | |
void | thread_detach (pthread_t thread) |
pthread_detach wrapper function. More... | |
void | thread_join (pthread_t t, void **result) |
pthread_join wrapper function. More... | |
+Mutexes | |
Variable type: Initialization of mutexes can be static or dynamic. +In static initialization the following initialization macros are suggested:
Dynamic initialization is done by mutex_init() and mutex_destroy(). + + | |
void | mutex_init (pthread_mutex_t *pmtx, pthread_mutexattr_t *attr) |
pthread_mutex_init wrapper function. More... | |
void | mutex_destroy (pthread_mutex_t *pmtx) |
pthread_mutex_destroy wrapper function. More... | |
void | mutex_lock (pthread_mutex_t *pmtx) |
pthread_mutex_lock wrapper function. More... | |
int | mutex_trylock (pthread_mutex_t *pmtx) |
pthread_mutex_trylock wrapper function. More... | |
void | mutex_unlock (pthread_mutex_t *pmtx) |
pthread_mutex_unlock wrapper function. More... | |
+Condition variables | |
+ Initialization of condition variables can be static or dynamic. +In static initialization the following initialization macros should be used:
Dynamic initialization is done by cond_init() and cond_destroy(). + + | |
void | cond_init (pthread_cond_t *pcvar, pthread_condattr_t *attr) |
pthread_cond_init wrapper function. More... | |
void | cond_destroy (pthread_cond_t *pcvar) |
pthread_cond_destroy wrapper function. More... | |
void | cond_wait (pthread_cond_t *pcvar, pthread_mutex_t *pmtx) |
pthread_cond_wait wrapper function. More... | |
int | cond_timedwait (pthread_cond_t *pcvar, pthread_mutex_t *pmtx, const struct timespec *abstime) |
pthread_cond_timedwait wrapper function. More... | |
int | cond_timedwait (pthread_cond_t *pcvar, pthread_mutex_t *pmtx, long relative_time_us) |
pthread_cond_timedwait wrapper function accepting relative time (in microseconds) instead of absolute time. More... | |
void | cond_signal (pthread_cond_t *pcvar) |
pthread_cond_signal wrapper function. More... | |
void | cond_broadcast (pthread_cond_t *pcvar) |
pthread_cond_broadcast wrapper function. More... | |
+One-time initialization | |
+ POSIX thread library support a mechanism that ensures a one-time execution of a function. It does it through
| |
void | thread_once (pthread_once_t *once_control, void(*init_routine)(void)) |
pthread_once wrapper function. More... | |
+Thread-specific data | |
+ Thread-specific data allows the definition of variable whose scope is limited to each thread. In practice, we will have a common variable, with a common access, but with different values for each thread. + + | |
void | thread_key_create (pthread_key_t *key, void(*destr_function)(void *)) |
pthread_key_create wrapper function. More... | |
void | thread_key_delete (pthread_key_t key) |
pthread_key_delete wrapper function. More... | |
void | thread_setspecific (pthread_key_t key, void *pointer) |
pthread_setspecific wrapper function. More... | |
void * | thread_getspecific (pthread_key_t key) |
pthread_getspecific wrapper function. More... | |
+Mutex attributes | |
+ + | |
void | mutexattr_init (pthread_mutexattr_t *attr) |
pthread_mutexattr_init wrapper function. More... | |
void | mutexattr_destroy (pthread_mutexattr_t *attr) |
pthread_mutexattr_destroy wrapper function. More... | |
void | mutexattr_settype (pthread_mutexattr_t *attr, int type) |
pthread_mutexattr_settype wrapper function. More... | |
void | mutexattr_gettype (const pthread_mutexattr_t *attr, int *kind) |
pthread_mutexattr_gettype wrapper function. More... | |
+Condition variables attributes | |
+ + | |
void | condattr_init (pthread_condattr_t *attr) |
pthread_condattr_init wrapper function. More... | |
void | condattr_destroy (pthread_condattr_t *attr) |
pthread_condattr_destroy wrapper function. More... | |
+Thread attributes | |
+ + | |
void | thread_attr_init (pthread_attr_t *attr) |
pthread_attr_init wrapper function. More... | |
void | thread_attr_destroy (pthread_attr_t *attr) |
pthread_attr_destroy wrapper function. More... | |
void | thread_attr_setdetachstate (pthread_attr_t *attr, int detachstate) |
pthread_attr_setdetachstate wrapper function. More... | |
void | thread_attr_getdetachstate (const pthread_attr_t *attr, int *pdetachstate) |
pthread_attr_getdetachstate wrapper function. More... | |
+Cancellation | |
+ | |
void | thread_cancel (pthread_t thread) |
pthread_cancel wrapper function. More... | |
void | thread_setcancelstate (int state, int *oldstate) |
pthread_setcancelstate wrapper function. More... | |
void | thread_setcanceltype (int type, int *oldtype) |
pthread_setcanceltype wrapper function. More... | |
void | thread_testcancel (void) |
pthread_testcancel wrapper function. More... | |
POSIX threads library wrapper module.
+This module removes defensive programming approach of native POSIX threads library.
+All implemented functions, have exactly the same arguments and/or result of the original function, with the exception of returning an error indication.
+Errors are handled by the implementation of two policies:
stderr
(with the identification of the errno error, and the precise location the call), generates a segmentation fault (enabling a stack trace within a debugger like gdb
), and exits program execution;int
exception with the (errno) status error returned by the original function.int thread_equal | +( | +pthread_t | +t1, | +
+ | + | pthread_t | +t2 | +
+ | ) | ++ |
pthread_equal
wrapper function.
Other documentation in
man 3 pthread_equal
void thread_create | +( | +pthread_t * | +t, | +
+ | + | pthread_attr_t * | +attr, | +
+ | + | void *(*)(void *) | +thread_main, | +
+ | + | void * | +arg | +
+ | ) | ++ |
pthread_create
wrapper function.
t != NULL
thread_main != NULL
Other documentation in
man 3 pthread_create
pthread_t thread_self | +( | +) | ++ |
pthread_self
wrapper function.
Other documentation in
man 3 pthread_self
void thread_sched_yield | +( | +void | +) | ++ |
sched_yield
wrapper function.
Other documentation in
man 3 sched_yield
void thread_exit | +( | +void * | +retval | ) | ++ |
pthread_exit
wrapper function.
Other documentation in
man 3 pthread_exit
void thread_detach | +( | +pthread_t | +thread | ) | ++ |
pthread_detach
wrapper function.
Other documentation in
man 3 pthread_detach
void thread_join | +( | +pthread_t | +t, | +
+ | + | void ** | +result | +
+ | ) | ++ |
pthread_join
wrapper function.
Other documentation in
man 3 pthread_join
void mutex_init | +( | +pthread_mutex_t * | +pmtx, | +
+ | + | pthread_mutexattr_t * | +attr | +
+ | ) | ++ |
pthread_mutex_init
wrapper function.
pmtx != NULL
Other documentation in
man 3 pthread_mutex_init+ +
void mutex_destroy | +( | +pthread_mutex_t * | +pmtx | ) | ++ |
pthread_mutex_destroy
wrapper function.
pmtx != NULL
Other documentation in
man 3 pthread_mutex_destroy+ +
void mutex_lock | +( | +pthread_mutex_t * | +pmtx | ) | ++ |
pthread_mutex_lock
wrapper function.
pmtx != NULL
Other documentation in
man 3 pthread_mutex_lock+ +
int mutex_trylock | +( | +pthread_mutex_t * | +pmtx | ) | ++ |
pthread_mutex_trylock
wrapper function.
pmtx != NULL
Other documentation in
man 3 pthread_mutex_trylock+
!=0
) if lock succeeds, false (0
) otherwise void mutex_unlock | +( | +pthread_mutex_t * | +pmtx | ) | ++ |
pthread_mutex_unlock
wrapper function.
pmtx != NULL
Other documentation in
man 3 pthread_mutex_unlock+ +
void cond_init | +( | +pthread_cond_t * | +pcvar, | +
+ | + | pthread_condattr_t * | +attr | +
+ | ) | ++ |
pthread_cond_init
wrapper function.
pcvar != NULL
Other documentation in
man 3 pthread_cond_init+ +
void cond_destroy | +( | +pthread_cond_t * | +pcvar | ) | ++ |
pthread_cond_destroy
wrapper function.
pcvar != NULL
Other documentation in
man 3 pthread_cond_destroy+ +
void cond_wait | +( | +pthread_cond_t * | +pcvar, | +
+ | + | pthread_mutex_t * | +pmtx | +
+ | ) | ++ |
pthread_cond_wait
wrapper function.
pcvar != NULL
pmtx != NULL
Other documentation in
man 3 pthread_cond_wait+ +
int cond_timedwait | +( | +pthread_cond_t * | +pcvar, | +
+ | + | pthread_mutex_t * | +pmtx, | +
+ | + | const struct timespec * | +abstime | +
+ | ) | ++ |
pthread_cond_timedwait
wrapper function.
pcvar != NULL
pmtx != NULL
abstime != NULL
!=0
) if condition variable was signaled, false (0
) it time out has expired.Other documentation in
man 3 pthread_cond_timedwait+ +
int cond_timedwait | +( | +pthread_cond_t * | +pcvar, | +
+ | + | pthread_mutex_t * | +pmtx, | +
+ | + | long | +relative_time_us | +
+ | ) | ++ |
pthread_cond_timedwait
wrapper function accepting relative time (in microseconds) instead of absolute time.
pcvar != NULL
pmtx != NULL
relative_time_us > 0L
!=0
) if condition variable was signaled, false (0
) it time out has expired.Documentation in
man 3 pthread_cond_timedwait+ +
void cond_signal | +( | +pthread_cond_t * | +pcvar | ) | ++ |
pthread_cond_signal
wrapper function.
pcvar != NULL
Other documentation in
man 3 pthread_cond_signal+ +
void cond_broadcast | +( | +pthread_cond_t * | +pcvar | ) | ++ |
pthread_cond_broadcast
wrapper function.
pcvar != NULL
Other documentation in
man 3 pthread_cond_broadcast+ +
void thread_once | +( | +pthread_once_t * | +once_control, | +
+ | + | void(*)(void) | +init_routine | +
+ | ) | ++ |
pthread_once
wrapper function.
once_control != NULL
init_routine != NULL
Other documentation in
man 3 pthread_once
void thread_key_create | +( | +pthread_key_t * | +key, | +
+ | + | void(*)(void *) | +destr_function | +
+ | ) | ++ |
pthread_key_create
wrapper function.
This function should be executed once for each key (use thread_once()).
+key != NULL
Other documentation in
man 3 pthread_key_create+ +
void thread_key_delete | +( | +pthread_key_t | +key | ) | ++ |
pthread_key_delete
wrapper function.
This function should be executed once for each key (use thread_once()).
+key != NULL
Other documentation in
man 3 pthread_key_delete+ +
void thread_setspecific | +( | +pthread_key_t | +key, | +
+ | + | void * | +pointer | +
+ | ) | ++ |
pthread_setspecific
wrapper function.
pointer != NULL
Other documentation in
man 3 pthread_setspecific+ +
void* thread_getspecific | +( | +pthread_key_t | +key | ) | ++ |
pthread_getspecific
wrapper function.
key != NULL
Other documentation in
man 3 pthread_getspecific+ +
void mutexattr_init | +( | +pthread_mutexattr_t * | +attr | ) | ++ |
pthread_mutexattr_init
wrapper function.
attr != NULL
Other documentation in
man 3 pthread_mutexattr_init+ +
void mutexattr_destroy | +( | +pthread_mutexattr_t * | +attr | ) | ++ |
pthread_mutexattr_destroy
wrapper function.
attr != NULL
Other documentation in
man 3 pthread_mutexattr_destroy+ +
void mutexattr_settype | +( | +pthread_mutexattr_t * | +attr, | +
+ | + | int | +type | +
+ | ) | ++ |
pthread_mutexattr_settype
wrapper function.
attr != NULL
Other documentation in
man 3 pthread_mutexattr_settype+ +
void mutexattr_gettype | +( | +const pthread_mutexattr_t * | +attr, | +
+ | + | int * | +kind | +
+ | ) | ++ |
pthread_mutexattr_gettype
wrapper function.
attr != NULL
kind != NULL
Other documentation in
man 3 pthread_mutexattr_gettype+ +
void condattr_init | +( | +pthread_condattr_t * | +attr | ) | ++ |
pthread_condattr_init
wrapper function.
attr != NULL
Other documentation in
man 3 pthread_condattr_init+ +
void condattr_destroy | +( | +pthread_condattr_t * | +attr | ) | ++ |
pthread_condattr_destroy
wrapper function.
attr != NULL
Other documentation in
man 3 pthread_condattr_destroy+ +
void thread_attr_init | +( | +pthread_attr_t * | +attr | ) | ++ |
pthread_attr_init
wrapper function.
attr != NULL
Other documentation in
man 3 pthread_attr_init+ +
void thread_attr_destroy | +( | +pthread_attr_t * | +attr | ) | ++ |
pthread_attr_destroy
wrapper function.
attr != NULL
Other documentation in
man 3 pthread_attr_destroy+ +
void thread_attr_setdetachstate | +( | +pthread_attr_t * | +attr, | +
+ | + | int | +detachstate | +
+ | ) | ++ |
pthread_attr_setdetachstate
wrapper function.
attr != NULL
detachstate == PTHREAD_CREATE_DETACHED || detachstate == PTHREAD_CREATE_JOINABLE
Other documentation in
man 3 pthread_attr_setdetachstate+ +
void thread_attr_getdetachstate | +( | +const pthread_attr_t * | +attr, | +
+ | + | int * | +pdetachstate | +
+ | ) | ++ |
pthread_attr_getdetachstate
wrapper function.
attr != NULL
pdetachstate != NULL
Other documentation in
man 3 pthread_attr_getdetachstate+ +
void thread_cancel | +( | +pthread_t | +thread | ) | ++ |
pthread_cancel
wrapper function.
Other documentation in
man 3 pthread_cancel
void thread_setcancelstate | +( | +int | +state, | +
+ | + | int * | +oldstate | +
+ | ) | ++ |
pthread_setcancelstate
wrapper function.
state == PTHREAD_CANCEL_ENABLE || state == PTHREAD_CANCEL_DISABLE
oldstate != NULL
Other documentation in
man 3 pthread_setcancelstate+ +
void thread_setcanceltype | +( | +int | +type, | +
+ | + | int * | +oldtype | +
+ | ) | ++ |
pthread_setcanceltype
wrapper function.
type == PTHREAD_CANCEL_DEFERRED || type == PTHREAD_CANCEL_ASYNCHRONOUS
oldtype != NULL
Other documentation in
man 3 pthread_setcanceltype+ +
void thread_testcancel | +( | +void | +) | ++ |
pthread_testcancel
wrapper function.
Other documentation in
man 3 pthread_testcancel+ +
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
Useful common functions and macros. +More...
++Files | |
file | utils.h |
Useful common functions and macros. | |
+Macros | |
#define | int2str(num) |
Converts an int value to a stack allocated string. More... | |
#define | int2nstr(num, len) |
Converts an int value to a stack allocated string. More... | |
#define | long2str(num) |
Converts an long value to a stack allocated string. More... | |
#define | long2nstr(num, len) |
Converts an long value to a stack allocated string. More... | |
#define | perc2str(percentage) |
Converts an int percentage to a stack allocated string. More... | |
#define | length_vargs_string_list(first) |
Determines the length of all strings passed as a NULL terminated variable list of arguments (vargs). More... | |
#define | not_null(pnt) |
Checks if address is not NULL , before its application. More... | |
+Functions | |
void * | mem_alloc (int size) |
A replacement for malloc function. More... | |
void | mem_free (void *pnt) |
A replacement for free function. More... | |
char * | string_clone (char *str) |
Replicates a string. More... | |
int | string_num_lines (char *text) |
Number of lines of a string. More... | |
int | string_num_columns (char *text) |
Maximum number of columns of a string (not counting character ‘’\n'`). More... | |
int | string_count_char (char *text, char *ch) |
Counts the number of occurrences of an UTF8 character in a text. More... | |
int | string_starts_with (char *text, char *prefix) |
Tests if a string starts with a prefix. More... | |
int | string_ends_with (char *text, char *suffix) |
Tests if a string ends with a suffix. More... | |
char * | string_concat (char *res, int max_length, char *text,...) |
Concatenates a NULL terminated list of string arguments. More... | |
int | random_boolean (int trueProb) |
Generates a random boolean value. More... | |
int | random_int (int min, int max) |
Generates a random integer value within a given interval. More... | |
char * | random_string (char **list, int *used, int length) |
Returns a random string from a given string list. More... | |
+void | clear_console () |
Clears the terminal. | |
void | move_cursor (int line, int column) |
Moves the cursor to a position in terminal. More... | |
+void | hide_cursor () |
Hides the terminal cursor. | |
+void | show_cursor () |
Shows the terminal cursor. | |
int | string_list_length (char **list) |
Number of elements of a NULL terminated list of strings. More... | |
char ** | string_list_clone (char **list) |
Replicates a NULL terminated list of strings. More... | |
char ** | string_list_free (char **list) |
Frees the memory allocated to a NULL terminated list of strings. More... | |
char * | int2nstring (char *res, int num, int len) |
Converts an int value to a string. More... | |
char * | percentage2string (char *res, int percentage) |
Converts an int percentage to a string. More... | |
+String concatenation in stack memory | |
+ | |
#define | concat_2str(str1, str2) |
Concatenates two strings in the stack memory (thus it cannot be implemented in a function). More... | |
#define | concat_3str(str1, str2, str3) |
Concatenates three strings in the stack memory (thus it cannot be implemented in a function). More... | |
#define | concat_4str(str1, str2, str3, str4) |
Concatenates four strings in the stack memory (thus it cannot be implemented in a function). More... | |
#define | concat_5str(str1, str2, str3, str4, str5) |
Concatenates five strings in the stack memory (thus it cannot be implemented in a function). More... | |
#define | concat_6str(str1, str2, str3, str4, str5, str6) |
Concatenates six strings in the stack memory (thus it cannot be implemented in a function). More... | |
#define | concat_7str(str1, str2, str3, str4, str5, str6, str7) |
Concatenates seven strings in the stack memory (thus it cannot be implemented in a function). More... | |
Useful common functions and macros.
+ +#define concat_2str | +( | ++ | str1, | +
+ | + | + | str2 | +
+ | ) | ++ |
Concatenates two strings in the stack memory (thus it cannot be implemented in a function).
+A NULL
reference is treated as an empty string.
[in] | str1 | string 1 |
[in] | str2 | string 2 |
#define concat_3str | +( | ++ | str1, | +
+ | + | + | str2, | +
+ | + | + | str3 | +
+ | ) | ++ |
Concatenates three strings in the stack memory (thus it cannot be implemented in a function).
+A NULL
reference is treated as an empty string.
[in] | str1 | string 1 |
[in] | str2 | string 2 |
[in] | str3 | string 3 |
#define concat_4str | +( | ++ | str1, | +
+ | + | + | str2, | +
+ | + | + | str3, | +
+ | + | + | str4 | +
+ | ) | ++ |
Concatenates four strings in the stack memory (thus it cannot be implemented in a function).
+A NULL
reference is treated as an empty string.
[in] | str1 | string 1 |
[in] | str2 | string 2 |
[in] | str3 | string 3 |
[in] | str4 | string 4 |
#define concat_5str | +( | ++ | str1, | +
+ | + | + | str2, | +
+ | + | + | str3, | +
+ | + | + | str4, | +
+ | + | + | str5 | +
+ | ) | ++ |
Concatenates five strings in the stack memory (thus it cannot be implemented in a function).
+A NULL
reference is treated as an empty string.
[in] | str1 | string 1 |
[in] | str2 | string 2 |
[in] | str3 | string 3 |
[in] | str4 | string 4 |
[in] | str5 | string 5 |
#define concat_6str | +( | ++ | str1, | +
+ | + | + | str2, | +
+ | + | + | str3, | +
+ | + | + | str4, | +
+ | + | + | str5, | +
+ | + | + | str6 | +
+ | ) | ++ |
Concatenates six strings in the stack memory (thus it cannot be implemented in a function).
+A NULL
reference is treated as an empty string.
[in] | str1 | string 1 |
[in] | str2 | string 2 |
[in] | str3 | string 3 |
[in] | str4 | string 4 |
[in] | str5 | string 5 |
[in] | str6 | string 6 |
#define concat_7str | +( | ++ | str1, | +
+ | + | + | str2, | +
+ | + | + | str3, | +
+ | + | + | str4, | +
+ | + | + | str5, | +
+ | + | + | str6, | +
+ | + | + | str7 | +
+ | ) | ++ |
Concatenates seven strings in the stack memory (thus it cannot be implemented in a function).
+A NULL
reference is treated as an empty string.
[in] | str1 | string 1 |
[in] | str2 | string 2 |
[in] | str3 | string 3 |
[in] | str4 | string 4 |
[in] | str5 | string 5 |
[in] | str6 | string 6 |
[in] | str7 | string 7 |
#define int2str | +( | ++ | num | ) | ++ |
Converts an int
value to a stack allocated string.
[in] | num | integer number |
#define int2nstr | +( | ++ | num, | +
+ | + | + | len | +
+ | ) | ++ |
Converts an int
value to a stack allocated string.
If necessary, fills the result string with left zeros.
+[in] | num | integer number |
[in] | len | minimum length of result string |
len > 0
#define long2str | +( | ++ | num | ) | ++ |
Converts an long
value to a stack allocated string.
[in] | num | long integer number |
#define long2nstr | +( | ++ | num, | +
+ | + | + | len | +
+ | ) | ++ |
Converts an long
value to a stack allocated string.
If necessary, fills the result string with left zeros.
+[in] | num | long integer number |
[in] | len | minimum length of result string |
len > 0
#define perc2str | +( | ++ | percentage | ) | ++ |
Converts an int
percentage to a stack allocated string.
[in] | percentage | an integer number with a percentage value |
percentage >= 0 && percentage <= 100
#define length_vargs_string_list | +( | ++ | first | ) | ++ |
Determines the length of all strings passed as a NULL terminated variable list of arguments (vargs).
+[in] | first | the argument that precedes the vargs argument list. |
#define not_null | +( | ++ | pnt | ) | ++ |
Checks if address is not NULL
, before its application.
This macro is a non-defensive implementation of a null pointer verification. It implements two error handling policies:
stderr
(with the identification and the precise location of the failure), generates a segmentation fault (enabling a stack trace within a debugger like gdb
), and exits program execution;char*
exception with the description of the failure.[in] | pnt | memory address |
void* mem_alloc | +( | +int | +size | ) | ++ |
A replacement for malloc
function.
This function is a non-defensive implementation of malloc
error verification. It implements two error handling policies:
stderr
(with the identification and the precise location of the failure), generates a segmentation fault (enabling a stack trace within a debugger like gdb
), and exits program execution;char*
exception with the description of the failure.[in] | size | number of bytes to be allocated |
size >= 0
void mem_free | +( | +void * | +pnt | ) | ++ |
A replacement for free
function.
[in] | pnt | memory address to be freed |
pnt != NULL
char* string_clone | +( | +char * | +str | ) | ++ |
Replicates a string.
+The memory is allocated in the heap (using mem_alloc()).
+[in] | str | string to be replicated |
str != NULL
int string_num_lines | +( | +char * | +text | ) | ++ |
Number of lines of a string.
+[in] | text | string text to process |
text != NULL
int string_num_columns | +( | +char * | +text | ) | ++ |
Maximum number of columns of a string (not counting character ‘’\n'`).
+[in] | text | string text to process |
text != NULL
int string_count_char | +( | +char * | +text, | +
+ | + | char * | +ch | +
+ | ) | ++ |
Counts the number of occurrences of an UTF8 character in a text.
+[in] | text | string text to process |
[in] | ch | string containing the sequence of bytes (one or more) of an UTF8 single character |
text != NULL
ch != NULL && num_chars_utf8(ch) == 1
int string_starts_with | +( | +char * | +text, | +
+ | + | char * | +prefix | +
+ | ) | ++ |
Tests if a string starts with a prefix.
+[in] | text | string text to process |
[in] | prefix | string to test if is a prefix |
text != NULL
prefix != NULL
!=0
) if prefix starts text, false (0
) otherwise int string_ends_with | +( | +char * | +text, | +
+ | + | char * | +suffix | +
+ | ) | ++ |
Tests if a string ends with a suffix.
+[in] | text | string text to process |
[in] | suffix | string to test if is a suffix |
text != NULL
suffix != NULL
!=0
) if suffix ends text, false (0
) otherwise char* string_concat | +( | +char * | +res, | +
+ | + | int | +max_length, | +
+ | + | char * | +text, | +
+ | + | + | ... | +
+ | ) | ++ |
Concatenates a NULL
terminated list of string arguments.
This function treats all vargs arguments as strings (char*
), and requires that the list is terminated with a NULL argument.
It allocates memory in heap (using mem_alloc()) if NULL
is passed in the res
argument.
[in,out] | res | address of result string (if not NULL ) |
[in] | max_length | res input argument maximum length (not counting terminator ‘’\0'), only applies if (res != NULL)` |
[in] | text | the first string to be used in concatenation |
text != NULL
res == NULL || (max_length > 0 && length_vargs_string_list(text) <= max_length)
int random_boolean | +( | +int | +trueProb | ) | ++ |
Generates a random boolean value.
+This function generates boolean values with defined probabilities for true (!=0
) and false (0
) values.
[in] | trueProb | probability (in interval [0;100] ). |
trueProb >= 0 && trueProb <= 100
int random_int | +( | +int | +min, | +
+ | + | int | +max | +
+ | ) | ++ |
Generates a random integer value within a given interval.
+This function generates integer values in the interval [min;max]
with an uniform distribution for all values.
[in] | min | lower value of interval |
[in] | max | higher value of interval |
max >= min
char* random_string | +( | +char ** | +list, | +
+ | + | int * | +used, | +
+ | + | int | +length | +
+ | ) | ++ |
Returns a random string from a given string list.
+This function stores the previous randomly selected string's (using the integer indexes of the string list) to disallow its repeated generation.
+[in] | list | list of strings to be selected (NULL terminated) |
[in,out] | used | indexes of strings already selected |
[in] | length | number of elements of lists list (not counting NULL entry) and used |
list != NULL
used != NULL
void move_cursor | +( | +int | +line, | +
+ | + | int | +column | +
+ | ) | ++ |
Moves the cursor to a position in terminal.
+[in] | line | position in the terminal |
[in] | column | position in the terminal |
line >= 0 && column >= 0
int string_list_length | +( | +char ** | +list | ) | ++ |
Number of elements of a NULL
terminated list of strings.
[in] | list | NULL terminated array of strings |
list != NULL
NULL
) char** string_list_clone | +( | +char ** | +list | ) | ++ |
Replicates a NULL
terminated list of strings.
The memory is allocated in the heap (using mem_alloc()).
+[in] | list | NULL terminated array of strings |
list != NULL
char** string_list_free | +( | +char ** | +list | ) | ++ |
Frees the memory allocated to a NULL
terminated list of strings.
This function is totally compatible with string_list_clone(), and always returns NULL
.
[in] | list | NULL terminated array of strings |
list != NULL
NULL
char* int2nstring | +( | +char * | +res, | +
+ | + | int | +num, | +
+ | + | int | +len | +
+ | ) | ++ |
Converts an int
value to a string.
If necessary, fills the result string with left zeros. It allocates memory in heap (using mem_alloc()) if NULL
is passed in the res
argument.
[in,out] | res | address of result string (if not NULL ) |
[in] | num | integer number |
[in] | len | minimum length of result string (not counting terminator ‘’\0'`) |
len >= numDigits(num)
char* percentage2string | +( | +char * | +res, | +
+ | + | int | +percentage | +
+ | ) | ++ |
Converts an int
percentage to a string.
It allocates memory in heap (using mem_alloc()) if NULL
is passed in the res
argument.
[in,out] | res | address of result string (if not NULL ) |
[in] | percentage | an integer number with a percentage value |
percentage >= 0 && percentage <= 100
NULL
, it returns res
)
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+
+ C++ Library, mos@ua
+ 0.9
+
+ cpplib-mos
+ |
+