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:
|
| 30 | Resource(int bytes);
|
| 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 |
|
| 39 | const void *getBuffer() const; // FIXME
|
| 40 |
|
| 41 | private:
|
| 42 | ~Resource(); // Always call destruct() instead
|
| 43 |
|
| 44 | BackoffLock criticalSection;
|
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 45 | Event unblock;
|
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 46 | volatile int blocked;
|
| 47 |
|
| 48 | volatile Accessor accessor;
|
| 49 | volatile int count;
|
| 50 | bool orphaned;
|
| 51 |
|
| 52 | void *buffer;
|
| 53 | };
|
| 54 | }
|
| 55 |
|
| 56 | #endif // sw_Resource_hpp
|