- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
// Lock the write mutex, to provide consistency of data
#define LOCK \
if (_ugb) { \
if (pthread_mutex_lock(&_write_mutex) == EINVAL) \
ASSERT(0); \
}
// Unlock write mutex when data sent
#define UNLOCK \
if (_ugb) { \
if (pthread_mutex_unlock(&_write_mutex) == EINVAL) \
ASSERT(0); \
}
// Пример использования
void socket::add_var(uint16_t code, const void *buffer, uint32_t length)
{
LOCK
try
{
DEBUG_I(Vblock, "Sending code 0x%X of size 0x%X\n", code, length);
send(&code, sizeof(code));
send(&length, sizeof(length));
send(buffer, length);
}
catch (const error & ve)
{
UNLOCK
DEBUG_E(Vblock, "Caught an exception!\n");
throw;
}
catch (...)
{
UNLOCK
}
UNLOCK
}