VirtualBox

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

Last change on this file since 28863 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1/* $Id: tls-win.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT - Thread Local Storage (TLS), Win32.
4 */
5
6/*
7 * Copyright (C) 2008 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(iTls))
72 return VINF_SUCCESS;
73 return RTErrConvertFromWin32(GetLastError());
74
75}
76
77
78RTR3DECL(void *) RTTlsGet(RTTLS iTls)
79{
80 return TlsGetValue(iTls);
81}
82
83
84RTR3DECL(int) RTTlsGetEx(RTTLS iTls, void **ppvValue)
85{
86 void *pv = TlsGetValue(iTls);
87 if (pv)
88 {
89 *ppvValue = pv;
90 return VINF_SUCCESS;
91 }
92
93 /* TlsGetValue always updates last error */
94 *ppvValue = NULL;
95 return RTErrConvertFromWin32(GetLastError());
96}
97
98
99RTR3DECL(int) RTTlsSet(RTTLS iTls, void *pvValue)
100{
101 if (TlsSetValue(iTls, pvValue))
102 return VINF_SUCCESS;
103 return RTErrConvertFromWin32(GetLastError());
104}
105
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