Functions and Macros beginning with C and D
The following functions are discussed in this section:
CALLOC() Macro
The CALLOC macro is a platform-independent substitute for the C library routine calloc. It allocates size bytes from the request’s memory pool and initializes the memory to zeros. The memory can be explicitly freed by a call to FREE. If the memory is not explicitly freed, it is automatically freed after processing of the current request has been completed. If pooled memory has been disabled in the configuration file with the pool-init built-in SAF, PERM-CALLOC and CALLOC both obtain their memory from the system heap. However, because memory allocated by CALLOC is automatically freed, the memory should not be shared with threads.
| Syntax | Return Values | Parameters | Example |
|---|---|---|---|
void *CALLOC(int size)
|
A void pointer to a block of memory. | int size is the number of bytes to allocate. | char *name; name = (char *) CALLOC(100); |
See Also
cinfo_find() Function
The cinfo_find() function uses the MIME types information to find the type, encoding, or language based on the extensions of the Universal Resource Identifier (URI) or local file name. Use this information to send headers (rq->srvhdrs) to the client indicating the content-type, content-encoding, and content-language of the data the client will be receiving from the server.
The URI name used is everything after the last slash ( / ) or the whole string if no slash is found. File name extensions are not case sensitive. The name can contain multiple extensions separated by a period (.) to indicate type, encoding, or language. For example, the URI a/b/filename.jp.txt.zip represents a Japanese language, text/plain type, zip-encoded file.
| Syntax | Return Values | Parameters |
|---|---|---|
cinfo *cinfo_find(char *uri);
|
A pointer to a newly allocated cinfo structure if the find succeeds, or NULL if the find fails. The cinfo structure that is allocated and returned contains pointers to the content-type, content-encoding, and content-language, if found. Each structure points to static data in the types database, or NULL if not found. Do not free these pointers. You should free the cinfo structure after using it. |
char *uri is a Universal Resource Identifier (URI) or local file name. Multiple file name extensions should be separated by periods (.). |
condvar_init() Function
The condvar_init function is a critical-section function that initializes and returns a new condition variable associated with a specified critical-section variable. You can use the condition variable to prevent interference between two threads of execution.
| Syntax | Return Values | Parameters |
|---|---|---|
CONDVAR condvar_init(CRITICAL id); |
A newly allocated condition variable (CONDVAR). | CRITICAL id is a critical-section variable. |
See Also
- condvar_notify() Function
- condvar_terminate() Function
- condvar_wait() Function
- crit_init() Function
- crit_enter() Function
- crit_exit() Function
- crit_terminate() Function
condvar_notify() Function
The condvar_notify function is a critical-section function that awakens any threads that are blocked on the given critical-section variable. Use this function to awaken threads of execution of a given critical section. First, use crit_enter to gain ownership of the critical section. Then use the returned critical-section variable to call condvar_notify to awaken the threads. Finally, when condvar_notify returns, call crit_exit to surrender ownership of the critical section.
| Syntax | Return Values | Parameters |
|---|---|---|
| void condvar_notify(CONDVAR cv); | void | CONDVAR cv is a condition variable. |
See Also
- condvar_init() Function
- condvar_terminate() Function
- condvar_wait() Function
- crit_init() Function
- crit_enter() Function
- crit_exit() Function
- crit_terminate() Function
condvar_terminate() Function
The condvar_terminate function is a critical-section function that frees a condition variable. Use this function to free a previously allocated condition variable.
| Caution - Terminating a condition variable that is in use can lead to unpredictable results. |
| Syntax | Return Values | Parameters |
|---|---|---|
void condvar_terminate(CONDVAR cv); |
void | CONDVAR cv is a condition variable. |
See Also
- condvar_init() Function
- condvar_notify() Function
- condvar_wait() Function
- crit_init() Function
- crit_enter() Function
- crit_exit() Function
- crit_terminate() Function
condvar_wait() Function
The condvar_wait function is a critical-section function that blocks on a given condition variable. Use this function to wait for a critical section, specified by a condition variable argument to become available. The calling thread is blocked until another thread calls condvar_notify with the same condition variable argument. The caller must have entered the critical section associated with this condition variable before calling condvar_wait.
| Syntax | Return Values | Parameters |
|---|---|---|
void condvar_wait(CONDVAR cv); |
void | CONDVAR cv is a condition variable. |
See Also
- condvar_init() Function
- condvar_terminate() Function
- condvar_notify() Function
- crit_init() Function
- crit_enter() Function
- crit_exit() Function
- crit_terminate() Function
crit_enter() Function
The crit_enter function is a critical-section function that attempts to enter a critical section. Use this function to gain ownership of a critical section. If another thread already owns the section, the calling thread is blocked until the first thread surrenders ownership by calling crit_exit.
| Syntax | Return Values | Parameters |
|---|---|---|
void crit_enter(CRITICAL crvar); |
void | CRITICAL crvar is a critical-section variable. |
See Also
crit_exit() Function
The crit_exit function is a critical-section function that surrenders ownership of a critical section. Use this function to surrender ownership of a critical section. If another thread is blocked waiting for the section, the block is removed and the waiting thread is given ownership of the section.
| Syntax | Return Values | Parameters |
|---|---|---|
void crit_exit(CRITICAL crvar); |
void | CRITICAL crvar is a critical-section variable. |
See Also
crit_init() Function
The crit_init function is a critical-section function that creates and returns a new critical-section variable, a variable of type CRITICAL. Use this function to obtain a new instance of a variable of type CRITICAL, a critical-section variable. Use this variable to prevent interference between two threads of execution. At the time this variable is created, no thread owns the critical section.
| Caution - Threads must not own or be waiting for the critical section when crit_terminate is called. |
| Syntax | Return Values | Parameters |
|---|---|---|
CRITICAL crit_init(void); |
A newly allocated critical-section variable (CRITICAL). | none |
See Also
crit_terminate() Function
The crit_terminate function is a critical-section function that removes a previously allocated critical-section variable, a variable of type CRITICAL. Use this function to release a critical-section variable previously obtained by a call to crit_init.
| Syntax | Return Values | Parameters |
|---|---|---|
void crit_terminate(CRITICAL crvar); |
void | CRITICAL crvar is a critical-section variable. |
See Also
daemon_atrestart() Function
The daemon_atrestart function enables to you register a callback function named fn to be used when the server terminates. Use this function when you need a callback function to deallocate resources allocated by an initialization function. The daemon_atrestart function is a generalization of the magnus_atrestart function.
The magnus.conf directives TerminateTimeout and ChildRestartCallback also affect the callback of NSAPI functions.
| Syntax | Return Values | Parameters | Example |
|---|---|---|---|
void daemon_atrestart(void (*fn)(void *), void *data); |
void | void (* fn) (void *) is the callback function. void *data is the parameter passed to the callback function when the server is restarted. |
/* Register the log_close function, passing it NULL */
/* to close a log file when the server is */
/* restarted or shutdown. */
daemon_atrestart(log_close, NULL);
NSAPI_PUBLIC void log_close(void *parameter)
{system_fclose(global_logfd);}
|