VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/log/tracedefault.cpp@ 56290

Last change on this file since 56290 was 55401, checked in by vboxsync, 10 years ago

added a couple of missing Id headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1/* $Id: tracedefault.cpp 55401 2015-04-23 10:03:17Z vboxsync $ */
2/** @file
3 * IPRT - Tracebuffer common functions.
4 */
5
6/*
7 * Copyright (C) 2011-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include "internal/iprt.h"
32#include <iprt/trace.h>
33
34#include <iprt/asm.h>
35#include <iprt/err.h>
36#include <iprt/thread.h>
37
38
39/*******************************************************************************
40* Global Variables *
41*******************************************************************************/
42/** The default trace buffer handle. */
43static RTTRACEBUF g_hDefaultTraceBuf = NIL_RTTRACEBUF;
44
45
46
47RTDECL(int) RTTraceSetDefaultBuf(RTTRACEBUF hTraceBuf)
48{
49 /* Retain the new buffer. */
50 if (hTraceBuf != NIL_RTTRACEBUF)
51 {
52 uint32_t cRefs = RTTraceBufRetain(hTraceBuf);
53 if (cRefs >= _1M)
54 return VERR_INVALID_HANDLE;
55 }
56
57 RTTRACEBUF hOldTraceBuf;
58#ifdef IN_RC
59 hOldTraceBuf = (RTTRACEBUF)ASMAtomicXchgPtr((void **)&g_hDefaultTraceBuf, hTraceBuf);
60#else
61 ASMAtomicXchgHandle(&g_hDefaultTraceBuf, hTraceBuf, &hOldTraceBuf);
62#endif
63
64 if ( hOldTraceBuf != NIL_RTTRACEBUF
65 && hOldTraceBuf != hTraceBuf)
66 {
67 /* Race prevention kludge. */
68#ifndef IN_RC
69 RTThreadSleep(33);
70#endif
71 RTTraceBufRelease(hOldTraceBuf);
72 }
73
74 return VINF_SUCCESS;
75}
76
77
78RTDECL(RTTRACEBUF) RTTraceGetDefaultBuf(void)
79{
80 return g_hDefaultTraceBuf;
81}
82
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette