Created
July 21, 2010 17:15
-
-
Save blabos-zz/484785 to your computer and use it in GitHub Desktop.
Mutex Initialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Inicialização de um mutex conforme manda o figurino | |
*/ | |
{ | |
int status = 0; | |
char buffer[80]; | |
pthread_mutexattr_t attr; | |
status = pthread_mutexattr_init(&attr); | |
if (status != 0) { | |
snprintf(buffer, 80, | |
"logger::logger(): Error initializing mutex attr (%d)", | |
status); | |
throw buffer; | |
} | |
status = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); | |
if (status != 0) { | |
snprintf(buffer, 80, | |
"logger::logger(): Error setting the type of mutex attr (%d)", | |
status); | |
throw buffer; | |
} | |
status = pthread_mutex_init(&_mutex, &attr); | |
if (status != 0) { | |
snprintf(buffer, 80, | |
"logger::logger(): Error initializing mutex (%d)", | |
status); | |
throw buffer; | |
} | |
status = pthread_mutexattr_destroy(&attr); | |
if (status != 0) { | |
snprintf(buffer, 80, | |
"logger::logger(): Error destroying mutex attr (%d)", | |
status); | |
throw buffer; | |
} | |
} | |
/** | |
* Inicialização POG de mutex se aproveitando da cópia membro a | |
* membro das structs, unions e família, e sabendo que não há | |
* ponteiros aí dentro. | |
* | |
* @TODO: fazer algo menos porco. | |
*/ | |
{ | |
pthread_mutex_t m = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; | |
_mutex = m; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment