2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkThread_DEFINED
|
|
|
|
#define SkThread_DEFINED
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
#include "SkThread_platform.h"
|
|
|
|
|
|
|
|
/****** SkThread_platform needs to define the following...
|
|
|
|
|
|
|
|
int32_t sk_atomic_inc(int32_t*);
|
2012-07-16 16:51:28 +00:00
|
|
|
int32_t sk_atomic_add(int32_t*, int32_t);
|
2008-12-17 15:59:43 +00:00
|
|
|
int32_t sk_atomic_dec(int32_t*);
|
2012-05-16 18:21:56 +00:00
|
|
|
int32_t sk_atomic_conditional_inc(int32_t*);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
class SkMutex {
|
|
|
|
public:
|
|
|
|
SkMutex();
|
|
|
|
~SkMutex();
|
|
|
|
|
|
|
|
void acquire();
|
|
|
|
void release();
|
|
|
|
};
|
|
|
|
|
|
|
|
****************/
|
|
|
|
|
|
|
|
class SkAutoMutexAcquire : SkNoncopyable {
|
|
|
|
public:
|
2012-04-23 16:04:22 +00:00
|
|
|
explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkASSERT(fMutex != NULL);
|
|
|
|
mutex.acquire();
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-04-23 16:04:22 +00:00
|
|
|
SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) {
|
|
|
|
if (mutex) {
|
|
|
|
mutex->acquire();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** If the mutex has not been release, release it now.
|
|
|
|
*/
|
2012-04-23 16:04:22 +00:00
|
|
|
~SkAutoMutexAcquire() {
|
|
|
|
if (fMutex) {
|
2008-12-17 15:59:43 +00:00
|
|
|
fMutex->release();
|
2012-04-23 16:04:22 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-04-23 16:04:22 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** If the mutex has not been release, release it now.
|
|
|
|
*/
|
2012-04-23 16:04:22 +00:00
|
|
|
void release() {
|
|
|
|
if (fMutex) {
|
2008-12-17 15:59:43 +00:00
|
|
|
fMutex->release();
|
|
|
|
fMutex = NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2012-01-26 21:26:40 +00:00
|
|
|
SkBaseMutex* fMutex;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|