mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 04:20:23 +00:00
Move Mutex class from Vaca to src/base.
This commit is contained in:
parent
803167c06f
commit
51fbcae936
@ -3,4 +3,5 @@
|
||||
|
||||
add_library(base-lib
|
||||
errno_string.cpp
|
||||
mem_utils.cpp)
|
||||
mem_utils.cpp
|
||||
mutex.cpp)
|
||||
|
14
src/base/disable_copying.h
Normal file
14
src/base/disable_copying.h
Normal file
@ -0,0 +1,14 @@
|
||||
// ASE base library
|
||||
// Copyright (C) 2001-2010 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef BASE_DISABLE_COPYING_H_INCLUDED
|
||||
#define BASE_DISABLE_COPYING_H_INCLUDED
|
||||
|
||||
#define DISABLE_COPYING(ClassName) \
|
||||
ClassName(const ClassName&); \
|
||||
ClassName& operator=(const ClassName&);
|
||||
|
||||
#endif
|
40
src/base/mutex.cpp
Normal file
40
src/base/mutex.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// ASE base library
|
||||
// Copyright (C) 2001-2010 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "base/mutex.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include "base/mutex_win32.h"
|
||||
#else
|
||||
#include "base/mutex_pthread.h"
|
||||
#endif
|
||||
|
||||
Mutex::Mutex()
|
||||
: m_impl(new MutexImpl)
|
||||
{
|
||||
}
|
||||
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
delete m_impl;
|
||||
}
|
||||
|
||||
void Mutex::lock()
|
||||
{
|
||||
return m_impl->lock();
|
||||
}
|
||||
|
||||
bool Mutex::tryLock()
|
||||
{
|
||||
return m_impl->tryLock();
|
||||
}
|
||||
|
||||
void Mutex::unlock()
|
||||
{
|
||||
return m_impl->unlock();
|
||||
}
|
30
src/base/mutex.h
Normal file
30
src/base/mutex.h
Normal file
@ -0,0 +1,30 @@
|
||||
// ASE base library
|
||||
// Copyright (C) 2001-2010 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef BASE_MUTEX_H_INCLUDED
|
||||
#define BASE_MUTEX_H_INCLUDED
|
||||
|
||||
#include "base/disable_copying.h"
|
||||
|
||||
class Mutex
|
||||
{
|
||||
public:
|
||||
Mutex();
|
||||
~Mutex();
|
||||
|
||||
void lock();
|
||||
bool tryLock();
|
||||
void unlock();
|
||||
|
||||
private:
|
||||
class MutexImpl;
|
||||
MutexImpl* m_impl;
|
||||
|
||||
DISABLE_COPYING(Mutex);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
43
src/base/mutex_pthread.h
Normal file
43
src/base/mutex_pthread.h
Normal file
@ -0,0 +1,43 @@
|
||||
// ASE base library
|
||||
// Copyright (C) 2001-2010 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef BASE_MUTEX_PTHREAD_H_INCLUDED
|
||||
#define BASE_MUTEX_PTHREAD_H_INCLUDED
|
||||
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
class Mutex::MutexImpl
|
||||
{
|
||||
public:
|
||||
|
||||
MutexImpl() {
|
||||
pthread_mutex_init(&m_handle, NULL);
|
||||
}
|
||||
|
||||
~MutexImpl() {
|
||||
pthread_mutex_destroy(&m_handle);
|
||||
}
|
||||
|
||||
void lock() {
|
||||
pthread_mutex_lock(&m_handle);
|
||||
}
|
||||
|
||||
bool tryLock() {
|
||||
return pthread_mutex_trylock(&m_handle) != EBUSY;
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
pthread_mutex_unlock(&m_handle);
|
||||
}
|
||||
|
||||
private:
|
||||
pthread_mutex_t m_handle;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
45
src/base/mutex_win32.h
Normal file
45
src/base/mutex_win32.h
Normal file
@ -0,0 +1,45 @@
|
||||
// ASE base library
|
||||
// Copyright (C) 2001-2010 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef BASE_MUTEX_WIN32_H_INCLUDED
|
||||
#define BASE_MUTEX_WIN32_H_INCLUDED
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
class Mutex::MutexImpl
|
||||
{
|
||||
public:
|
||||
|
||||
MutexImpl() {
|
||||
InitializeCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
~MutexImpl() {
|
||||
DeleteCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
void lock() {
|
||||
EnterCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
bool tryLock() {
|
||||
#if(_WIN32_WINNT >= 0x0400)
|
||||
return TryEnterCriticalSection(&m_handle) ? true: false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
LeaveCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
private:
|
||||
CRITICAL_SECTION m_handle;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
43
src/base/scoped_lock.h
Normal file
43
src/base/scoped_lock.h
Normal file
@ -0,0 +1,43 @@
|
||||
// ASE base library
|
||||
// Copyright (C) 2001-2010 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef BASE_SCOPED_LOCK_H_INCLUDED
|
||||
#define BASE_SCOPED_LOCK_H_INCLUDED
|
||||
|
||||
#include "base/disable_copying.h"
|
||||
|
||||
// An object to safely lock and unlock mutexes.
|
||||
//
|
||||
// The constructor of ScopedLock locks the mutex, and the destructor
|
||||
// unlocks the mutex. In this way you can safely use ScopedLock inside
|
||||
// a try/catch block without worrying about the lock state of the
|
||||
// mutex if some exception is thrown.
|
||||
class ScopedLock
|
||||
{
|
||||
public:
|
||||
|
||||
ScopedLock(Mutex& mutex) : m_mutex(mutex) {
|
||||
m_mutex.lock();
|
||||
}
|
||||
|
||||
~ScopedLock() {
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
||||
Mutex& getMutex() const {
|
||||
return m_mutex;
|
||||
}
|
||||
|
||||
private:
|
||||
Mutex& m_mutex;
|
||||
|
||||
// Undefined constructors.
|
||||
ScopedLock();
|
||||
DISABLE_COPYING(ScopedLock);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -22,10 +22,10 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "base/mutex.h"
|
||||
#include "base/scoped_lock.h"
|
||||
#include "core/cfg.h"
|
||||
#include "effect/effect.h"
|
||||
#include "modules/editors.h"
|
||||
@ -34,9 +34,6 @@
|
||||
#include "widgets/editor.h"
|
||||
#include "widgets/statebar.h"
|
||||
|
||||
using Vaca::Mutex;
|
||||
using Vaca::ScopedLock;
|
||||
|
||||
/**********************************************************************
|
||||
Apply effect in two threads: bg-thread to modify the sprite, and the
|
||||
main thread to monitoring the progress.
|
||||
|
@ -23,12 +23,12 @@
|
||||
|
||||
#include "jinete/jstring.h"
|
||||
#include "jinete/jwindow.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "base/mutex.h"
|
||||
#include "base/scoped_lock.h"
|
||||
#include "commands/commands.h"
|
||||
#include "commands/params.h"
|
||||
#include "app.h"
|
||||
#include "ui_context.h"
|
||||
|
||||
#ifdef ALLEGRO_WINDOWS
|
||||
@ -37,9 +37,6 @@
|
||||
|
||||
#ifdef ALLEGRO_WINDOWS
|
||||
|
||||
using Vaca::Mutex;
|
||||
using Vaca::ScopedLock;
|
||||
|
||||
static WNDPROC base_wnd_proc = NULL;
|
||||
static std::vector<jstring>* dropped_files;
|
||||
static Mutex* dropped_files_mutex = NULL;
|
||||
|
@ -18,16 +18,16 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <allegro.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jinete/jalert.h"
|
||||
#include "jinete/jlist.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "console.h"
|
||||
#include "app.h"
|
||||
#include "base/mutex.h"
|
||||
#include "base/scoped_lock.h"
|
||||
#include "console.h"
|
||||
#include "file/file.h"
|
||||
#include "file/format_options.h"
|
||||
#include "modules/gui.h"
|
||||
@ -36,9 +36,6 @@
|
||||
#include "util/quantize.h"
|
||||
#include "widgets/statebar.h"
|
||||
|
||||
using Vaca::Mutex;
|
||||
using Vaca::ScopedLock;
|
||||
|
||||
extern FileFormat format_ase;
|
||||
extern FileFormat format_bmp;
|
||||
extern FileFormat format_fli;
|
||||
|
@ -39,12 +39,11 @@
|
||||
#define FILE_LOAD_SEQUENCE_YES (1<<2)
|
||||
#define FILE_LOAD_ONE_FRAME (1<<3)
|
||||
|
||||
namespace Vaca { class Mutex; }
|
||||
|
||||
class Cel;
|
||||
class Image;
|
||||
class Layer;
|
||||
class LayerImage;
|
||||
class Mutex;
|
||||
class Palette;
|
||||
class Sprite;
|
||||
|
||||
@ -81,7 +80,7 @@ struct FileOp
|
||||
char* filename; /* file-name to load/save */
|
||||
|
||||
/* shared fields between threads */
|
||||
Vaca::Mutex* mutex; /* mutex to access to the next two fields */
|
||||
Mutex* mutex; /* mutex to access to the next two fields */
|
||||
float progress; /* progress (1.0 is ready) */
|
||||
char* error; /* error string */
|
||||
bool done : 1; /* true if the operation finished */
|
||||
|
@ -36,8 +36,8 @@
|
||||
#include <string.h>
|
||||
#include <allegro/unicode.h>
|
||||
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
#include "base/mutex.h"
|
||||
#include "base/scoped_lock.h"
|
||||
|
||||
#if !defined MEMLEAK
|
||||
|
||||
@ -132,9 +132,6 @@ typedef struct slot_t
|
||||
struct slot_t* next;
|
||||
} slot_t;
|
||||
|
||||
using Vaca::Mutex;
|
||||
using Vaca::ScopedLock;
|
||||
|
||||
static bool memleak_status = false;
|
||||
static slot_t* headslot;
|
||||
static Mutex mutex;
|
||||
|
@ -22,17 +22,14 @@
|
||||
#include "jinete/jthread.h"
|
||||
#include "jinete/jwidget.h"
|
||||
#include "jinete/jwindow.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "base/mutex.h"
|
||||
#include "base/scoped_lock.h"
|
||||
#include "job.h"
|
||||
#include "modules/gui.h"
|
||||
#include "widgets/statebar.h"
|
||||
|
||||
using Vaca::Mutex;
|
||||
using Vaca::ScopedLock;
|
||||
|
||||
Job::Job(const char* job_name)
|
||||
{
|
||||
m_mutex = NULL;
|
||||
|
@ -21,11 +21,10 @@
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
|
||||
namespace Vaca { class Mutex; }
|
||||
|
||||
class Frame;
|
||||
struct Monitor;
|
||||
class Mutex;
|
||||
class Progress;
|
||||
struct Monitor;
|
||||
|
||||
class Job
|
||||
{
|
||||
@ -71,7 +70,7 @@ private:
|
||||
JThread m_thread;
|
||||
Monitor* m_monitor;
|
||||
Progress* m_progress;
|
||||
Vaca::Mutex* m_mutex;
|
||||
Mutex* m_mutex;
|
||||
Frame* m_alert_window;
|
||||
float m_last_progress;
|
||||
bool m_done_flag;
|
||||
|
@ -22,14 +22,10 @@
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "base/mutex.h"
|
||||
#include "base/scoped_lock.h"
|
||||
#include "raster/gfxobj.h"
|
||||
|
||||
using Vaca::Mutex;
|
||||
using Vaca::ScopedLock;
|
||||
|
||||
static Mutex* objects_mutex;
|
||||
static GfxObjId object_id = 0; // Last object ID created
|
||||
static std::map<GfxObjId, GfxObj*>* objects_map; // Graphics objects map
|
||||
|
@ -22,9 +22,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "jinete/jlist.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "base/mutex.h"
|
||||
#include "base/scoped_lock.h"
|
||||
#include "file/format_options.h"
|
||||
#include "raster/raster.h"
|
||||
#include "util/boundary.h"
|
||||
@ -33,9 +33,6 @@
|
||||
#pragma warning(disable: 4355)
|
||||
#endif
|
||||
|
||||
using Vaca::Mutex;
|
||||
using Vaca::ScopedLock;
|
||||
|
||||
static Layer* index2layer(const Layer* layer, int index, int* index_count);
|
||||
static int layer2index(const Layer* layer, const Layer* find_layer, int* index_count);
|
||||
|
||||
@ -429,7 +426,7 @@ private:
|
||||
Image* m_extraImage; // Image of the extra cel
|
||||
|
||||
// Mutex to modify the 'locked' flag.
|
||||
Vaca::Mutex* m_mutex;
|
||||
Mutex* m_mutex;
|
||||
|
||||
// True if some thread is writing the sprite.
|
||||
bool m_write_lock;
|
||||
|
3
third_party/vaca/CMakeLists.txt
vendored
3
third_party/vaca/CMakeLists.txt
vendored
@ -1,14 +1,13 @@
|
||||
# ASE - Allegro Sprite Editor
|
||||
# Copyright (C) 2001-2010 David Capello
|
||||
|
||||
include_directories(include)
|
||||
include_directories(include ../../src)
|
||||
|
||||
add_library(vaca
|
||||
src/Application.cpp
|
||||
src/Component.cpp
|
||||
src/Event.cpp
|
||||
src/Exception.cpp
|
||||
src/Mutex.cpp
|
||||
src/Point.cpp
|
||||
src/PreferredSizeEvent.cpp
|
||||
src/Property.cpp
|
||||
|
73
third_party/vaca/include/Vaca/Mutex.h
vendored
73
third_party/vaca/include/Vaca/Mutex.h
vendored
@ -1,73 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef VACA_MUTEX_H
|
||||
#define VACA_MUTEX_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
#include "Vaca/NonCopyable.h"
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
/**
|
||||
An object to synchronize threads using mutual exclusion of critical
|
||||
sections.
|
||||
|
||||
This kind of mutex can be used to synchronize multiple threads of
|
||||
the same process. No multiple processes!
|
||||
|
||||
@win32
|
||||
This is a @msdn{CRITICAL_SECTION} wrapper.
|
||||
@endwin32
|
||||
|
||||
@see ScopedLock, ConditionVariable, Thread,
|
||||
@wikipedia{Critical_section, Critical Section in Wikipedia}
|
||||
@wikipedia{Mutex, Mutex in Wikipedia}
|
||||
*/
|
||||
class VACA_DLL Mutex : private NonCopyable
|
||||
{
|
||||
class MutexImpl;
|
||||
MutexImpl* m_pimpl;
|
||||
|
||||
public:
|
||||
|
||||
Mutex();
|
||||
~Mutex();
|
||||
|
||||
void lock();
|
||||
bool tryLock();
|
||||
void unlock();
|
||||
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_MUTEX_H
|
104
third_party/vaca/include/Vaca/ScopedLock.h
vendored
104
third_party/vaca/include/Vaca/ScopedLock.h
vendored
@ -1,104 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef VACA_SCOPEDLOCK_H
|
||||
#define VACA_SCOPEDLOCK_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/NonCopyable.h"
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
/**
|
||||
An object to safely lock and unlock mutexes.
|
||||
|
||||
The constructor of ScopedLock locks the mutex, the destructor
|
||||
unlocks the mutex. In this way you can safely use ScopedLock
|
||||
inside a try/catch block without worrying about to the lock
|
||||
state of the mutex.
|
||||
|
||||
For example:
|
||||
@code
|
||||
try {
|
||||
ScopedLock hold(mutex);
|
||||
throw Exception();
|
||||
}
|
||||
catch (...) {
|
||||
// the mutex is unlocked here
|
||||
}
|
||||
// if you don't throw a exception, the mutex is unlocked here too
|
||||
@endcode
|
||||
|
||||
@see Mutex, ConditionVariable
|
||||
*/
|
||||
class ScopedLock : private NonCopyable
|
||||
{
|
||||
Mutex& m_mutex;
|
||||
|
||||
// not defined
|
||||
ScopedLock();
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
Creates the ScopedLock locking the specified mutex.
|
||||
|
||||
@param mutex
|
||||
Mutex to be hold by the ScopedLock's life-time.
|
||||
*/
|
||||
ScopedLock(Mutex& mutex)
|
||||
: m_mutex(mutex)
|
||||
{
|
||||
m_mutex.lock();
|
||||
}
|
||||
|
||||
/**
|
||||
Destroys the ScopedLock unlocking the held mutex.
|
||||
*/
|
||||
~ScopedLock()
|
||||
{
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
Returns which mutex is being held.
|
||||
*/
|
||||
Mutex& getMutex() const
|
||||
{
|
||||
return m_mutex;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_SCOPEDLOCK_H
|
2
third_party/vaca/include/Vaca/base.h
vendored
2
third_party/vaca/include/Vaca/base.h
vendored
@ -442,7 +442,6 @@ class MenuSeparator;
|
||||
class Message;
|
||||
class MouseEvent;
|
||||
class MsgBox;
|
||||
class Mutex;
|
||||
class Node;
|
||||
class NonCopyable;
|
||||
class OpenFileDialog;
|
||||
@ -465,7 +464,6 @@ class ResourceId;
|
||||
class SaveFileDialog;
|
||||
class SciEdit;
|
||||
class SciRegister;
|
||||
class ScopedLock;
|
||||
class ScreenGraphics;
|
||||
class ScrollEvent;
|
||||
class ScrollInfo;
|
||||
|
102
third_party/vaca/src/Mutex.cpp
vendored
102
third_party/vaca/src/Mutex.cpp
vendored
@ -1,102 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "Vaca/Mutex.h"
|
||||
|
||||
#if defined(VACA_ON_WINDOWS)
|
||||
#include "win32/MutexImpl.h"
|
||||
#elif defined(VACA_ON_UNIXLIKE)
|
||||
#include "unix/MutexImpl.h"
|
||||
#else
|
||||
#error Your platform does not support mutexes
|
||||
#endif
|
||||
|
||||
using namespace Vaca;
|
||||
|
||||
/**
|
||||
Creates a new mutex.
|
||||
|
||||
@win32
|
||||
It uses @msdn{InitializeCriticalSection}.
|
||||
@endwin32
|
||||
*/
|
||||
Mutex::Mutex()
|
||||
{
|
||||
m_pimpl = new MutexImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
Destroys the mutex.
|
||||
|
||||
@win32
|
||||
It uses @msdn{DeleteCriticalSection}.
|
||||
@endwin32
|
||||
*/
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
delete m_pimpl;
|
||||
}
|
||||
|
||||
/**
|
||||
Locks the mutex to enter in a critical section.
|
||||
|
||||
Locks the mutex if it is free (not locked by another thread) or
|
||||
waits the mutex to be unlocked.
|
||||
|
||||
@see unlock, ScopedLock, Thread
|
||||
|
||||
@win32
|
||||
It uses @msdn{EnterCriticalSection}.
|
||||
@endwin32
|
||||
*/
|
||||
void Mutex::lock()
|
||||
{
|
||||
return m_pimpl->lock();
|
||||
}
|
||||
|
||||
/**
|
||||
Tries to lock the mutex and returns true if it was locked.
|
||||
|
||||
@see lock
|
||||
|
||||
@win32
|
||||
It uses @msdn{TryEnterCriticalSection}.
|
||||
@endwin32
|
||||
*/
|
||||
bool Mutex::tryLock()
|
||||
{
|
||||
return m_pimpl->tryLock();
|
||||
}
|
||||
|
||||
void Mutex::unlock()
|
||||
{
|
||||
return m_pimpl->unlock();
|
||||
}
|
4
third_party/vaca/src/Referenceable.cpp
vendored
4
third_party/vaca/src/Referenceable.cpp
vendored
@ -32,8 +32,8 @@
|
||||
#include "Vaca/Referenceable.h"
|
||||
|
||||
#ifndef NDEBUG
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
#include "base/mutex.h"
|
||||
#include "base/scoped_lock.h"
|
||||
#include <vector>
|
||||
#include <typeinfo>
|
||||
#ifdef VACA_ON_WINDOWS
|
||||
|
67
third_party/vaca/src/unix/MutexImpl.h
vendored
67
third_party/vaca/src/unix/MutexImpl.h
vendored
@ -1,67 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
class Vaca::Mutex::MutexImpl
|
||||
{
|
||||
pthread_mutex_t m_handle;
|
||||
|
||||
public:
|
||||
|
||||
MutexImpl()
|
||||
{
|
||||
pthread_mutex_init(&m_handle, NULL);
|
||||
}
|
||||
|
||||
~MutexImpl()
|
||||
{
|
||||
pthread_mutex_destroy(&m_handle);
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
pthread_mutex_lock(&m_handle);
|
||||
}
|
||||
|
||||
bool tryLock()
|
||||
{
|
||||
return pthread_mutex_trylock(&m_handle) != EBUSY;
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
pthread_mutex_unlock(&m_handle);
|
||||
}
|
||||
|
||||
};
|
||||
|
73
third_party/vaca/src/win32/MutexImpl.h
vendored
73
third_party/vaca/src/win32/MutexImpl.h
vendored
@ -1,73 +0,0 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0400
|
||||
#endif
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
class Vaca::Mutex::MutexImpl
|
||||
{
|
||||
CRITICAL_SECTION m_handle;
|
||||
|
||||
public:
|
||||
|
||||
MutexImpl()
|
||||
{
|
||||
InitializeCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
~MutexImpl()
|
||||
{
|
||||
DeleteCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
EnterCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
bool tryLock()
|
||||
{
|
||||
#if(_WIN32_WINNT >= 0x0400)
|
||||
return TryEnterCriticalSection(&m_handle) ? true: false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
LeaveCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user