X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_writer_local.hpp;h=cc5dda0115eb425e462d12203bbb2c2bc4e65cd1;hb=7a9fb5103e052150232b64cb5d99374cda3f1234;hp=7c705801b716de4fb7d56d73a5c1cef63df3476d;hpb=a0e612d13d479d1b0e65d11037060b473c9d722f;p=apitrace diff --git a/common/trace_writer_local.hpp b/common/trace_writer_local.hpp index 7c70580..cc5dda0 100644 --- a/common/trace_writer_local.hpp +++ b/common/trace_writer_local.hpp @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2007-2010 VMware, Inc. + * Copyright 2007-2013 VMware, Inc. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -24,13 +24,16 @@ **************************************************************************/ /* - * Trace writing functions. + * Trace writing functions, used to trace calls in the current process. */ #ifndef _TRACE_WRITER_LOCAL_HPP_ #define _TRACE_WRITER_LOCAL_HPP_ +#include + +#include "os_thread.hpp" #include "trace_writer.hpp" @@ -52,21 +55,49 @@ namespace trace { */ class LocalWriter : public Writer { protected: + /** + * This mutex guarantees that only one thread writes to the trace file + * at one given instance. + * + * We need a recursive mutex so that we dont't dead lock in the event + * of a segfault happens while the mutex is held. + * + * To prevent deadlocks, the call for the real function (the one being + * traced) should not be done with the mutex held. That is, it should + * be done outside the beginEnter/endEnter and beginLeave/endLeave + * pairs. Preferably between these two pairs. + */ + os::recursive_mutex mutex; int acquired; public: /** - * Should never called directly -- use localWriter singleton below instead. + * Should never called directly -- use localWriter singleton below + * instead. */ LocalWriter(); ~LocalWriter(); void open(void); + /** + * It will acquire the mutex. + */ unsigned beginEnter(const FunctionSig *sig); + + /** + * It will release the mutex. + */ void endEnter(void); + /** + * It will acquire the mutex. + */ void beginLeave(unsigned call); + + /** + * It will release the mutex. + */ void endLeave(void); void flush(void);