VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/tls-win.cpp@ 45733

Last change on this file since 45733 was 44529, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1/* $Id: tls-win.cpp 44529 2013-02-04 15:54:15Z vboxsync $ */
2/** @file
3 * IPRT - Thread Local Storage (TLS), Win32.
4 */
5
6/*
7 * Copyright (C) 2008-2010 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#define LOG_GROUP RTLOGGROUP_THREAD
32#include <Windows.h>
33
34#include <iprt/thread.h>
35#include <iprt/log.h>
36#include <iprt/assert.h>
37#include <iprt/err.h>
38#include "internal/thread.h"
39
40
41AssertCompile(sizeof(RTTLS) >= sizeof(DWORD));
42
43
44RTR3DECL(RTTLS) RTTlsAlloc(void)
45{
46 DWORD iTls = TlsAlloc();
47 return iTls != TLS_OUT_OF_INDEXES ? (RTTLS)iTls : NIL_RTTLS;
48}
49
50
51RTR3DECL(int) RTTlsAllocEx(PRTTLS piTls, PFNRTTLSDTOR pfnDestructor)
52{
53 AssertReturn(!pfnDestructor, VERR_NOT_SUPPORTED);
54 DWORD iTls = TlsAlloc();
55 if (iTls != TLS_OUT_OF_INDEXES)
56 {
57 Assert((RTTLS)iTls != NIL_RTTLS);
58 *piTls = (RTTLS)iTls;
59 Assert((DWORD)*piTls == iTls);
60 return VINF_SUCCESS;
61 }
62
63 return VERR_NO_MEMORY;
64}
65
66
67RTR3DECL(int) RTTlsFree(RTTLS iTls)
68{
69 if (iTls == NIL_RTTLS)
70 return VINF_SUCCESS;
71 if (TlsFree((DWORD)iTls))
72 return VINF_SUCCESS;
73 return RTErrConvertFromWin32(GetLastError());
74}
75
76
77RTR3DECL(void *) RTTlsGet(RTTLS iTls)
78{
79 return TlsGetValue((DWORD)iTls);
80}
81
82
83RTR3DECL(int) RTTlsGetEx(RTTLS iTls, void **ppvValue)
84{
85 void *pv = TlsGetValue((DWORD)iTls);
86 if (pv)
87 {
88 *ppvValue = pv;
89 return VINF_SUCCESS;
90 }
91
92 /* TlsGetValue always updates last error */
93 *ppvValue = NULL;
94 return RTErrConvertFromWin32(GetLastError());
95}
96
97
98RTR3DECL(int) RTTlsSet(RTTLS iTls, void *pvValue)
99{
100 if (TlsSetValue((DWORD)iTls, pvValue))
101 return VINF_SUCCESS;
102 return RTErrConvertFromWin32(GetLastError());
103}
104
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