grep.h File Reference
Multi-Threaded Grep Implementation.
More...
Go to the source code of this file.
|
Functions |
| int | grep_init (const char *searchString, unsigned int numThreads, unsigned int bufsize) |
| | Initializes the grep module.
|
| int | grep_addJob (const char *filename) |
| | Add a new job to the bounded buffer.
|
| int | grep_destroy () |
| | Terminates threads and frees used resources.
|
Detailed Description
Multi-Threaded Grep Implementation.
This module implements a multi-threaded line-oriented grep. The module spawns a fixed number of worker threads upon initialization. The threads will take jobs (a job is a filename and the FILE handle of the opened file) from a bounded buffer. For each job, the corresponding file is linewise searched for the given searchString (like grep). The worker threads for each match prints the filename, linenumber of the match and the line itself to standard output. The worker threads ensure that the output of different threads is not mixed up in one line. After having completed the search in a particular file, the thread closes the file and frees the saved filename.
Function Documentation
| int grep_addJob |
( |
const char * |
filename |
) |
|
Add a new job to the bounded buffer.
The grep_addJob function adds a new job to the bounded buffer.
- Parameters:
-
| filename | name of the opened file, will be copied to an internal buffer |
- Returns:
- 0 on success, -1 on error.
Terminates threads and frees used resources.
This function signals all threads the end of the processing and waits for the threads to finish. The remaining jobs in the buffer must be completed before the threads terminate. After all threads have terminated, the used resources (buffer, dynamically allocated data, ...) is freed. The function returns after all threads have terminated and all occupied resources have been freed.
| int grep_init |
( |
const char * |
searchString, |
|
|
unsigned int |
numThreads, |
|
|
unsigned int |
bufsize | |
|
) |
| | |
Initializes the grep module.
The module is initialized with the search string to be used. A bounded buffer of the given size is created and the specified number of threads is spawned. The threads take jobs from the bounded buffer and will initially block on bb_get() until jobs become available.
- Parameters:
-
| searchString | The search string to be used. The string will be copied to an internal buffer. |
| numThreads | The number of worker threads to be spawned. |
| bufsize | The number of slots in the bounded buffer that is created. |
- Returns:
- This function returns 0 on success, -1 on error.