John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 1 | // 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 |
|
| 17 | namespace 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 Capens | 53fae3e | 2014-12-03 11:09:40 -0500 | [diff] [blame] | 30 | Resource(size_t bytes);
|
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 31 |
|
| 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 Capens | 53fae3e | 2014-12-03 11:09:40 -0500 | [diff] [blame] | 39 | const void *data() const;
|
| 40 | const size_t size;
|
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 41 |
|
| 42 | private:
|
| 43 | ~Resource(); // Always call destruct() instead
|
| 44 |
|
| 45 | BackoffLock criticalSection;
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 46 | Event unblock;
|
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 47 | 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
|