blob: 6a275f1d0de05b9e668f4e7eb2eb16ca2786d2eb [file] [log] [blame]
John Bauman89401822014-05-06 15:04:28 -04001// SwiftShader Software Renderer
2//
3// Copyright(c) 2005-2011 TransGaming Inc.
4//
5// All rights reserved. No part of this software may be copied, distributed, transmitted,
6// transcribed, stored in a retrieval system, translated into any human or computer
7// language by any means, or disclosed to third parties without the explicit written
8// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9// or implied, including but not limited to any patent rights, are granted to you.
10//
11
12#ifndef sw_Resource_hpp
13#define sw_Resource_hpp
14
15#include "MutexLock.hpp"
16
17namespace sw
18{
19 enum Accessor
20 {
21 PUBLIC, // Application/API access
22 PRIVATE, // Renderer access, shared by multiple threads if read-only
23 MANAGED, // Renderer access, shared read/write access if partitioned
24 DESTRUCT
25 };
26
27 class Resource
28 {
29 public:
Nicolas Capens53fae3e2014-12-03 11:09:40 -050030 Resource(size_t bytes);
John Bauman89401822014-05-06 15:04:28 -040031
32 void destruct(); // Asynchronous destructor
33
34 void *lock(Accessor claimer);
35 void *lock(Accessor relinquisher, Accessor claimer);
36 void unlock();
37 void unlock(Accessor relinquisher);
38
Nicolas Capens53fae3e2014-12-03 11:09:40 -050039 const void *data() const;
40 const size_t size;
John Bauman89401822014-05-06 15:04:28 -040041
42 private:
43 ~Resource(); // Always call destruct() instead
44
45 BackoffLock criticalSection;
John Bauman66b8ab22014-05-06 15:57:45 -040046 Event unblock;
John Bauman89401822014-05-06 15:04:28 -040047 volatile int blocked;
48
49 volatile Accessor accessor;
50 volatile int count;
51 bool orphaned;
52
53 void *buffer;
54 };
55}
56
57#endif // sw_Resource_hpp