log: Make logging thread-safe

This commit is contained in:
Thiago de Arruda
2015-09-01 09:56:40 -03:00
parent 9ec240e03f
commit 2a0ff9f5cf
3 changed files with 26 additions and 2 deletions

View File

@@ -825,6 +825,7 @@ static void log_server_msg(uint64_t channel_id,
msgpack_unpack_next(&unpacked, packed->data, packed->size, NULL);
uint64_t type = unpacked.data.via.array.ptr[0].via.u64;
DLOGN("[msgpack-rpc] nvim -> client(%" PRIu64 ") ", channel_id);
log_lock();
FILE *f = open_log_file();
fprintf(f, type ? (type == 1 ? RES : NOT) : REQ);
log_msg_close(f, unpacked.data);
@@ -836,6 +837,7 @@ static void log_client_msg(uint64_t channel_id,
msgpack_object msg)
{
DLOGN("[msgpack-rpc] client(%" PRIu64 ") -> nvim ", channel_id);
log_lock();
FILE *f = open_log_file();
fprintf(f, is_request ? REQ : RES);
log_msg_close(f, msg);
@@ -847,6 +849,7 @@ static void log_msg_close(FILE *f, msgpack_object msg)
fputc('\n', f);
fflush(f);
fclose(f);
log_unlock();
}
#endif