mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-01 10:13:22 +00:00
Added Vaca::Mutex.
Now Vaca is compiled as a library (.lib/.a). Removed jmutex.cpp, jpoint.cpp, jsize.cpp.
This commit is contained in:
parent
d28b11e639
commit
2a27405173
10
makefile.gcc
10
makefile.gcc
@ -92,6 +92,10 @@ $(TINYXML_LIB): $(TINYXML_OBJS)
|
||||
-rm -f $@
|
||||
ar rs $@ $^
|
||||
|
||||
$(VACA_LIB): $(VACA_OBJS)
|
||||
-rm -f $@
|
||||
ar rs $@ $^
|
||||
|
||||
######################################################################
|
||||
# Rules to build objects and the application
|
||||
|
||||
@ -138,7 +142,8 @@ VPATH = src \
|
||||
$(LIBPNG_DIR) \
|
||||
$(ZLIB_DIR) \
|
||||
$(LOADPNG_DIR) \
|
||||
$(TINYXML_DIR)
|
||||
$(TINYXML_DIR) \
|
||||
$(VACA_DIR)/src
|
||||
|
||||
ASE_DEPS = $(ASE_OBJS) $(THIRD_PARTY_LIBS)
|
||||
|
||||
@ -175,6 +180,9 @@ $(OBJ_DIR)/loadpng.%$(OBJ): %.c
|
||||
$(OBJ_DIR)/tinyxml.%$(OBJ): %.cpp
|
||||
$(CPP) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
$(OBJ_DIR)/vaca.%$(OBJ): %.cpp
|
||||
$(CPP) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
######################################################################
|
||||
# Application
|
||||
|
||||
|
24
makefile.lst
24
makefile.lst
@ -143,16 +143,12 @@ COMMON_SOURCES = \
|
||||
src/jinete/jmem.cpp \
|
||||
src/jinete/jmenu.cpp \
|
||||
src/jinete/jmessage.cpp \
|
||||
src/jinete/jmutex.cpp \
|
||||
src/jinete/jpanel.cpp \
|
||||
src/jinete/jpoint.cpp \
|
||||
src/jinete/jpopup_window.cpp \
|
||||
src/jinete/jpoint.cpp \
|
||||
src/jinete/jquickmenu.cpp \
|
||||
src/jinete/jrect.cpp \
|
||||
src/jinete/jregion.cpp \
|
||||
src/jinete/jsep.cpp \
|
||||
src/jinete/jsize.cpp \
|
||||
src/jinete/jslider.cpp \
|
||||
src/jinete/jstream.cpp \
|
||||
src/jinete/jstring.cpp \
|
||||
@ -508,7 +504,21 @@ TINYXML_OBJS = $(addprefix $(OBJ_DIR)/tinyxml., \
|
||||
######################################################################
|
||||
# Vaca
|
||||
|
||||
VACA_LIB = $(OBJ_DIR)/libvaca$(LIB_EXT)
|
||||
VACA_DIR = src/jinete/vaca_fusion
|
||||
VACA_SOURCES = \
|
||||
$(VACA_DIR)/src/Component.cpp \
|
||||
$(VACA_DIR)/src/Debug.cpp \
|
||||
$(VACA_DIR)/src/Mutex.cpp \
|
||||
$(VACA_DIR)/src/Point.cpp \
|
||||
$(VACA_DIR)/src/Referenceable.cpp \
|
||||
$(VACA_DIR)/src/Rect.cpp \
|
||||
$(VACA_DIR)/src/Size.cpp \
|
||||
$(VACA_DIR)/src/win32/Mutex.cpp
|
||||
|
||||
VACA_OBJS = $(addprefix $(OBJ_DIR)/vaca., \
|
||||
$(addsuffix $(OBJ), \
|
||||
$(notdir $(basename $(VACA_SOURCES)))))
|
||||
|
||||
######################################################################
|
||||
# All objects and libraries
|
||||
@ -521,7 +531,8 @@ ALL_OBJS = \
|
||||
$(LIBPNG_OBJS) \
|
||||
$(ZLIB_OBJS) \
|
||||
$(LOADPNG_OBJS) \
|
||||
$(TINYXML_OBJS)
|
||||
$(TINYXML_OBJS) \
|
||||
$(VACA_OBJS)
|
||||
|
||||
THIRD_PARTY_LIBS = \
|
||||
$(LIBART_LIB) \
|
||||
@ -530,7 +541,8 @@ THIRD_PARTY_LIBS = \
|
||||
$(LIBPNG_LIB) \
|
||||
$(ZLIB_LIB) \
|
||||
$(LOADPNG_LIB) \
|
||||
$(TINYXML_LIB)
|
||||
$(TINYXML_LIB) \
|
||||
$(VACA_LIB)
|
||||
|
||||
######################################################################
|
||||
# Tests
|
||||
|
10
makefile.vc
10
makefile.vc
@ -134,6 +134,10 @@ $(TINYXML_LIB): $(TINYXML_OBJS)
|
||||
-rm -f $@
|
||||
lib -NOLOGO -OUT:$@ $^
|
||||
|
||||
$(VACA_LIB): $(VACA_OBJS)
|
||||
-rm -f $@
|
||||
lib -NOLOGO -OUT:$@ $^
|
||||
|
||||
######################################################################
|
||||
# Rules to build objects and the application
|
||||
|
||||
@ -180,7 +184,8 @@ VPATH = src \
|
||||
$(LIBPNG_DIR) \
|
||||
$(ZLIB_DIR) \
|
||||
$(LOADPNG_DIR) \
|
||||
$(TINYXML_DIR)
|
||||
$(TINYXML_DIR) \
|
||||
$(VACA_DIR)/src
|
||||
|
||||
ASE_DEPS = $(ASE_OBJS) $(THIRD_PARTY_LIBS)
|
||||
|
||||
@ -214,6 +219,9 @@ $(OBJ_DIR)/loadpng.%$(OBJ): %.c
|
||||
$(OBJ_DIR)/tinyxml.%$(OBJ): %.cpp
|
||||
$(CC) $(CFLAGS) -Fo$@ -c $<
|
||||
|
||||
$(OBJ_DIR)/vaca.%$(OBJ): %.cpp
|
||||
$(CC) $(CFLAGS) -Fo$@ -c $<
|
||||
|
||||
######################################################################
|
||||
# Application
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "core/cfg.h"
|
||||
@ -32,15 +34,18 @@
|
||||
#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.
|
||||
**********************************************************************/
|
||||
|
||||
typedef struct ThreadData
|
||||
struct ThreadData
|
||||
{
|
||||
Effect *effect; /* effect to be applied */
|
||||
JMutex mutex; /* mutex to access to 'pos', 'done'
|
||||
Effect* effect; /* effect to be applied */
|
||||
Mutex mutex; /* mutex to access to 'pos', 'done'
|
||||
and 'cancelled' fields in different
|
||||
threads */
|
||||
float pos; /* current progress position */
|
||||
@ -51,7 +56,7 @@ typedef struct ThreadData
|
||||
JThread thread; /* thread to apply the effect in background */
|
||||
Frame* alert_window; /* alert for the user to cancel the
|
||||
effect-progress if he wants */
|
||||
} ThreadData;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by @ref effect_apply to informate the progress of the
|
||||
@ -63,9 +68,8 @@ static void effect_progress_hook(void *_data, float progress)
|
||||
{
|
||||
ThreadData *data = (ThreadData *)_data;
|
||||
|
||||
jmutex_lock(data->mutex);
|
||||
ScopedLock lock(data->mutex);
|
||||
data->pos = progress;
|
||||
jmutex_unlock(data->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,9 +83,8 @@ static bool effect_is_cancelled_hook(void *_data)
|
||||
ThreadData *data = (ThreadData *)_data;
|
||||
bool cancelled;
|
||||
|
||||
jmutex_lock(data->mutex);
|
||||
ScopedLock lock(data->mutex);
|
||||
cancelled = data->cancelled;
|
||||
jmutex_unlock(data->mutex);
|
||||
|
||||
return cancelled;
|
||||
}
|
||||
@ -99,9 +102,8 @@ static void effect_bg(void *_data)
|
||||
effect_apply_to_target(data->effect);
|
||||
|
||||
/* mark the work as 'done' */
|
||||
jmutex_lock(data->mutex);
|
||||
ScopedLock lock(data->mutex);
|
||||
data->done = true;
|
||||
jmutex_unlock(data->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,10 +118,11 @@ static void monitor_effect_bg(void *_data)
|
||||
float pos;
|
||||
bool done;
|
||||
|
||||
jmutex_lock(data->mutex);
|
||||
pos = data->pos;
|
||||
done = data->done;
|
||||
jmutex_unlock(data->mutex);
|
||||
{
|
||||
ScopedLock lock(data->mutex);
|
||||
pos = data->pos;
|
||||
done = data->done;
|
||||
}
|
||||
|
||||
if (data->progress)
|
||||
progress_update(data->progress, pos);
|
||||
@ -149,13 +152,12 @@ static void monitor_free(void *_data)
|
||||
*/
|
||||
void effect_apply_to_target_with_progressbar(Effect* effect)
|
||||
{
|
||||
ThreadData *data = new ThreadData;
|
||||
ThreadData* data = new ThreadData;
|
||||
|
||||
effect->progress_data = data;
|
||||
effect->progress = effect_progress_hook;
|
||||
effect->is_cancelled = effect_is_cancelled_hook;
|
||||
|
||||
data->mutex = jmutex_new();
|
||||
data->effect = effect;
|
||||
data->pos = 0.0;
|
||||
data->done = false;
|
||||
@ -171,12 +173,13 @@ void effect_apply_to_target_with_progressbar(Effect* effect)
|
||||
|
||||
data->alert_window->open_window_fg();
|
||||
|
||||
jmutex_lock(data->mutex);
|
||||
if (!data->done) {
|
||||
remove_gui_monitor(data->monitor);
|
||||
data->cancelled = true;
|
||||
{
|
||||
ScopedLock lock(data->mutex);
|
||||
if (!data->done) {
|
||||
remove_gui_monitor(data->monitor);
|
||||
data->cancelled = true;
|
||||
}
|
||||
}
|
||||
jmutex_unlock(data->mutex);
|
||||
|
||||
/* wait the `effect_bg' thread */
|
||||
jthread_join(data->thread);
|
||||
|
@ -21,9 +21,10 @@
|
||||
#include <allegro.h>
|
||||
#include <vector>
|
||||
|
||||
#include "jinete/jmutex.h"
|
||||
#include "jinete/jstring.h"
|
||||
#include "jinete/jwindow.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "commands/commands.h"
|
||||
#include "commands/params.h"
|
||||
@ -36,9 +37,12 @@
|
||||
|
||||
#ifdef ALLEGRO_WINDOWS
|
||||
|
||||
using Vaca::Mutex;
|
||||
using Vaca::ScopedLock;
|
||||
|
||||
static WNDPROC base_wnd_proc = NULL;
|
||||
static std::vector<jstring>* dropped_files;
|
||||
static JMutex dropped_files_mutex;
|
||||
static Mutex* dropped_files_mutex = NULL;
|
||||
|
||||
static void subclass_hwnd();
|
||||
static void unsubclass_hwnd();
|
||||
@ -47,7 +51,7 @@ static LRESULT ase_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
|
||||
void install_drop_files()
|
||||
{
|
||||
dropped_files = new std::vector<jstring>();
|
||||
dropped_files_mutex = jmutex_new();
|
||||
dropped_files_mutex = new Mutex();
|
||||
|
||||
subclass_hwnd();
|
||||
}
|
||||
@ -56,7 +60,7 @@ void uninstall_drop_files()
|
||||
{
|
||||
unsubclass_hwnd();
|
||||
|
||||
jmutex_free(dropped_files_mutex);
|
||||
delete dropped_files_mutex;
|
||||
dropped_files_mutex = NULL;
|
||||
|
||||
delete dropped_files;
|
||||
@ -70,7 +74,7 @@ void check_for_dropped_files()
|
||||
if (!app_get_top_window()->is_toplevel())
|
||||
return;
|
||||
|
||||
jmutex_lock(dropped_files_mutex);
|
||||
ScopedLock lock(*dropped_files_mutex);
|
||||
if (!dropped_files->empty()) {
|
||||
std::vector<jstring> files = *dropped_files;
|
||||
dropped_files->clear();
|
||||
@ -87,7 +91,6 @@ void check_for_dropped_files()
|
||||
UIContext::instance()->execute_command(cmd_open_file, ¶ms);
|
||||
}
|
||||
}
|
||||
jmutex_unlock(dropped_files_mutex);
|
||||
}
|
||||
|
||||
static void subclass_hwnd()
|
||||
@ -116,8 +119,8 @@ static LRESULT ase_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
||||
switch (msg) {
|
||||
|
||||
case WM_DROPFILES:
|
||||
jmutex_lock(dropped_files_mutex);
|
||||
{
|
||||
ScopedLock lock(*dropped_files_mutex);
|
||||
HDROP hdrop = (HDROP)(wparam);
|
||||
int index, count, length;
|
||||
|
||||
@ -134,7 +137,6 @@ static LRESULT ase_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
||||
|
||||
DragFinish(hdrop);
|
||||
}
|
||||
jmutex_unlock(dropped_files_mutex);
|
||||
break;
|
||||
|
||||
}
|
||||
|
@ -19,16 +19,20 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jalert.h"
|
||||
#include "jinete/jmutex.h"
|
||||
#include "jinete/jthread.h"
|
||||
#include "jinete/jwidget.h"
|
||||
#include "jinete/jwindow.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "core/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;
|
||||
@ -40,7 +44,7 @@ Job::Job(const char* job_name)
|
||||
m_done_flag = false;
|
||||
m_canceled_flag = false;
|
||||
|
||||
m_mutex = jmutex_new();
|
||||
m_mutex = new Mutex();
|
||||
m_progress = progress_new(app_get_statusbar());
|
||||
m_monitor = add_gui_monitor(&Job::monitor_proc,
|
||||
&Job::monitor_free,
|
||||
@ -52,7 +56,7 @@ Job::~Job()
|
||||
{
|
||||
// The job was canceled by the user?
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
ScopedLock hold(*m_mutex);
|
||||
if (!m_done_flag)
|
||||
m_canceled_flag = true;
|
||||
}
|
||||
@ -69,7 +73,7 @@ Job::~Job()
|
||||
progress_free(m_progress);
|
||||
|
||||
if (m_mutex)
|
||||
jmutex_free(m_mutex);
|
||||
delete m_mutex;
|
||||
|
||||
if (m_alert_window)
|
||||
jwidget_free(m_alert_window);
|
||||
@ -83,13 +87,13 @@ void Job::do_job()
|
||||
|
||||
void Job::job_progress(float f)
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
ScopedLock hold(*m_mutex);
|
||||
m_last_progress = f;
|
||||
}
|
||||
|
||||
bool Job::is_canceled()
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
ScopedLock hold(*m_mutex);
|
||||
return m_canceled_flag;
|
||||
}
|
||||
|
||||
@ -110,7 +114,7 @@ void Job::on_job()
|
||||
*/
|
||||
void Job::on_monitor_tick()
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
ScopedLock hold(*m_mutex);
|
||||
|
||||
// update progress
|
||||
progress_update(m_progress, m_last_progress);
|
||||
@ -135,7 +139,7 @@ void Job::on_monitor_destroyed()
|
||||
|
||||
void Job::done()
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
ScopedLock hold(*m_mutex);
|
||||
m_done_flag = true;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
|
||||
namespace Vaca { class Mutex; }
|
||||
|
||||
class Frame;
|
||||
struct Monitor;
|
||||
struct Progress;
|
||||
@ -30,7 +32,7 @@ class Job
|
||||
JThread m_thread;
|
||||
Monitor* m_monitor;
|
||||
Progress* m_progress;
|
||||
JMutex m_mutex;
|
||||
Vaca::Mutex* m_mutex;
|
||||
Frame* m_alert_window;
|
||||
float m_last_progress;
|
||||
bool m_done_flag;
|
||||
|
@ -24,7 +24,8 @@
|
||||
|
||||
#include "jinete/jalert.h"
|
||||
#include "jinete/jlist.h"
|
||||
#include "jinete/jmutex.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "console.h"
|
||||
#include "app.h"
|
||||
@ -36,6 +37,9 @@
|
||||
#include "raster/raster.h"
|
||||
#include "widgets/statebar.h"
|
||||
|
||||
using Vaca::Mutex;
|
||||
using Vaca::ScopedLock;
|
||||
|
||||
extern FileFormat format_ase;
|
||||
extern FileFormat format_bmp;
|
||||
extern FileFormat format_fli;
|
||||
@ -671,21 +675,15 @@ void fop_operate(FileOp *fop)
|
||||
void fop_done(FileOp *fop)
|
||||
{
|
||||
/* finally done */
|
||||
jmutex_lock(fop->mutex);
|
||||
{
|
||||
fop->done = true;
|
||||
}
|
||||
jmutex_unlock(fop->mutex);
|
||||
ScopedLock lock(*fop->mutex);
|
||||
fop->done = true;
|
||||
}
|
||||
|
||||
void fop_stop(FileOp *fop)
|
||||
{
|
||||
jmutex_lock(fop->mutex);
|
||||
{
|
||||
if (!fop->done)
|
||||
fop->stop = true;
|
||||
}
|
||||
jmutex_unlock(fop->mutex);
|
||||
ScopedLock lock(*fop->mutex);
|
||||
if (!fop->done)
|
||||
fop->stop = true;
|
||||
}
|
||||
|
||||
void fop_free(FileOp *fop)
|
||||
@ -710,7 +708,7 @@ void fop_free(FileOp *fop)
|
||||
palette_free(fop->seq.palette);
|
||||
|
||||
if (fop->mutex)
|
||||
jmutex_free(fop->mutex);
|
||||
delete fop->mutex;
|
||||
|
||||
jfree(fop);
|
||||
}
|
||||
@ -792,9 +790,10 @@ void fop_error(FileOp *fop, const char *format, ...)
|
||||
uvszprintf(buf_error, sizeof(buf_error), format, ap);
|
||||
va_end(ap);
|
||||
|
||||
jmutex_lock(fop->mutex);
|
||||
{
|
||||
/* concatenate old errors with the new one */
|
||||
ScopedLock lock(*fop->mutex);
|
||||
|
||||
// Concatenate old errors with the new one
|
||||
if (fop->error) {
|
||||
char *old_error = fop->error;
|
||||
fop->error = reinterpret_cast<char*>(jmalloc(ustrsizez(old_error) + ustrsizez(buf_error) + 1));
|
||||
@ -806,37 +805,31 @@ void fop_error(FileOp *fop, const char *format, ...)
|
||||
else
|
||||
fop->error = jstrdup(buf_error);
|
||||
}
|
||||
jmutex_unlock(fop->mutex);
|
||||
}
|
||||
|
||||
void fop_progress(FileOp *fop, float progress)
|
||||
{
|
||||
/* rest(8); */
|
||||
|
||||
jmutex_lock(fop->mutex);
|
||||
{
|
||||
if (fop->seq.filename_list != NULL) {
|
||||
fop->progress =
|
||||
fop->seq.progress_offset +
|
||||
fop->seq.progress_fraction*progress;
|
||||
}
|
||||
else {
|
||||
fop->progress = progress;
|
||||
}
|
||||
ScopedLock lock(*fop->mutex);
|
||||
|
||||
if (fop->seq.filename_list != NULL) {
|
||||
fop->progress =
|
||||
fop->seq.progress_offset +
|
||||
fop->seq.progress_fraction*progress;
|
||||
}
|
||||
else {
|
||||
fop->progress = progress;
|
||||
}
|
||||
jmutex_unlock(fop->mutex);
|
||||
}
|
||||
|
||||
float fop_get_progress(FileOp *fop)
|
||||
{
|
||||
float progress;
|
||||
|
||||
jmutex_lock(fop->mutex);
|
||||
{
|
||||
ScopedLock lock(*fop->mutex);
|
||||
progress = fop->progress;
|
||||
}
|
||||
jmutex_unlock(fop->mutex);
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
@ -847,26 +840,20 @@ float fop_get_progress(FileOp *fop)
|
||||
bool fop_is_done(FileOp *fop)
|
||||
{
|
||||
bool done;
|
||||
|
||||
jmutex_lock(fop->mutex);
|
||||
{
|
||||
ScopedLock lock(*fop->mutex);
|
||||
done = fop->done;
|
||||
}
|
||||
jmutex_unlock(fop->mutex);
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
bool fop_is_stop(FileOp *fop)
|
||||
{
|
||||
bool stop;
|
||||
|
||||
jmutex_lock(fop->mutex);
|
||||
{
|
||||
ScopedLock lock(*fop->mutex);
|
||||
stop = fop->stop;
|
||||
}
|
||||
jmutex_unlock(fop->mutex);
|
||||
|
||||
return stop;
|
||||
}
|
||||
|
||||
@ -881,7 +868,7 @@ static FileOp *fop_new(FileOpType type)
|
||||
fop->sprite = NULL;
|
||||
fop->filename = NULL;
|
||||
|
||||
fop->mutex = jmutex_new();
|
||||
fop->mutex = new Mutex();
|
||||
fop->progress = 0.0f;
|
||||
fop->error = NULL;
|
||||
fop->done = false;
|
||||
|
@ -39,6 +39,8 @@
|
||||
#define FILE_LOAD_SEQUENCE_YES (1<<2)
|
||||
#define FILE_LOAD_ONE_FRAME (1<<3)
|
||||
|
||||
namespace Vaca { class Mutex; }
|
||||
|
||||
class Cel;
|
||||
class Image;
|
||||
class Layer;
|
||||
@ -79,7 +81,7 @@ struct FileOp
|
||||
char* filename; /* file-name to load/save */
|
||||
|
||||
/* shared fields between threads */
|
||||
JMutex mutex; /* mutex to access to the next two fields */
|
||||
Vaca::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 */
|
||||
|
@ -221,7 +221,6 @@ enum {
|
||||
typedef unsigned int JID;
|
||||
|
||||
typedef void* JThread;
|
||||
typedef void* JMutex;
|
||||
|
||||
typedef struct jaccel* JAccel;
|
||||
typedef struct jhook* JHook;
|
||||
|
@ -54,7 +54,6 @@
|
||||
#include "jinete/jmanager.h"
|
||||
#include "jinete/jmenu.h"
|
||||
#include "jinete/jmessage.h"
|
||||
#include "jinete/jmutex.h"
|
||||
#include "jinete/jpanel.h"
|
||||
#include "jinete/jpoint.h"
|
||||
#include "jinete/jpopup_window.h"
|
||||
|
@ -37,8 +37,8 @@
|
||||
#include <string.h>
|
||||
#include <allegro/unicode.h>
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
#include "jinete/jmutex.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#if !defined MEMLEAK
|
||||
|
||||
@ -133,16 +133,19 @@ 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 JMutex mutex;
|
||||
static Mutex mutex;
|
||||
|
||||
void _jmemleak_init()
|
||||
{
|
||||
assert(!memleak_status);
|
||||
|
||||
headslot = NULL;
|
||||
mutex = jmutex_new();
|
||||
mutex = new Mutex();
|
||||
|
||||
memleak_status = true;
|
||||
}
|
||||
@ -208,7 +211,7 @@ void _jmemleak_exit()
|
||||
#endif
|
||||
}
|
||||
|
||||
jmutex_free(mutex);
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
static void addslot(void *ptr, unsigned long size)
|
||||
@ -236,9 +239,8 @@ static void addslot(void *ptr, unsigned long size)
|
||||
p->size = size;
|
||||
p->next = headslot;
|
||||
|
||||
jmutex_lock(mutex);
|
||||
ScopedLock lock(mutex);
|
||||
headslot = p;
|
||||
jmutex_unlock(mutex);
|
||||
}
|
||||
|
||||
static void delslot(void *ptr)
|
||||
@ -250,7 +252,7 @@ static void delslot(void *ptr)
|
||||
|
||||
assert(ptr != NULL);
|
||||
|
||||
jmutex_lock(mutex);
|
||||
ScopedLock lock(mutex);
|
||||
|
||||
for (it=headslot; it!=NULL; prev=it, it=it->next) {
|
||||
if (it->ptr == ptr) {
|
||||
@ -263,8 +265,6 @@ static void delslot(void *ptr)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
jmutex_unlock(mutex);
|
||||
}
|
||||
|
||||
void *jmalloc(unsigned long n_bytes)
|
||||
|
@ -1,78 +0,0 @@
|
||||
/* Jinete - a GUI library
|
||||
* Copyright (C) 2003-2010 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 "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "jinete/jmutex.h"
|
||||
|
||||
static struct {
|
||||
void (*destroy)(JMutex mutex);
|
||||
void (*lock)(JMutex mutex);
|
||||
void (*unlock)(JMutex mutex);
|
||||
} mutex_vtable = { NULL, NULL, NULL };
|
||||
|
||||
JMutex jmutex_new()
|
||||
{
|
||||
assert(system_driver != NULL);
|
||||
assert(system_driver->create_mutex != NULL);
|
||||
|
||||
if (!mutex_vtable.destroy) {
|
||||
mutex_vtable.destroy = system_driver->destroy_mutex;
|
||||
mutex_vtable.lock = system_driver->lock_mutex;
|
||||
mutex_vtable.unlock = system_driver->unlock_mutex;
|
||||
}
|
||||
|
||||
return (JMutex)system_driver->create_mutex();
|
||||
}
|
||||
|
||||
void jmutex_free(JMutex mutex)
|
||||
{
|
||||
assert(mutex_vtable.destroy != NULL);
|
||||
|
||||
(*mutex_vtable.destroy)(mutex);
|
||||
}
|
||||
|
||||
void jmutex_lock(JMutex mutex)
|
||||
{
|
||||
assert(mutex_vtable.lock != NULL);
|
||||
|
||||
(*mutex_vtable.lock)(mutex);
|
||||
}
|
||||
|
||||
void jmutex_unlock(JMutex mutex)
|
||||
{
|
||||
assert(mutex_vtable.unlock != NULL);
|
||||
|
||||
(*mutex_vtable.unlock)(mutex);
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/* Jinete - a GUI library
|
||||
* Copyright (C) 2003-2010 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 JINETE_JMUTEX_H_INCLUDED
|
||||
#define JINETE_JMUTEX_H_INCLUDED
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
|
||||
JMutex jmutex_new();
|
||||
void jmutex_free(JMutex mutex);
|
||||
|
||||
void jmutex_lock(JMutex mutex);
|
||||
void jmutex_unlock(JMutex mutex);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ScopedLock
|
||||
|
||||
class ScopedLock
|
||||
{
|
||||
JMutex m_mutex;
|
||||
public:
|
||||
ScopedLock(JMutex mutex) : m_mutex(mutex) { jmutex_lock(m_mutex); }
|
||||
~ScopedLock() { jmutex_unlock(m_mutex); }
|
||||
};
|
||||
|
||||
#endif
|
@ -1,35 +0,0 @@
|
||||
/* Jinete - a GUI library
|
||||
* Copyright (C) 2003-2010 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 "config.h"
|
||||
|
||||
// Jinete+Vaca merge
|
||||
#include "jinete/vaca_fusion/src/Point.cpp"
|
@ -128,6 +128,3 @@ void jrect_displace(JRect rect, int dx, int dy)
|
||||
rect->x2 += dx;
|
||||
rect->y2 += dy;
|
||||
}
|
||||
|
||||
// Jinete+Vaca merge
|
||||
#include "jinete/vaca_fusion/src/Rect.cpp"
|
||||
|
@ -1,35 +0,0 @@
|
||||
/* Jinete - a GUI library
|
||||
* Copyright (C) 2003-2010 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 "config.h"
|
||||
|
||||
// Jinete+Vaca merge
|
||||
#include "jinete/vaca_fusion/src/Size.cpp"
|
@ -34,6 +34,7 @@
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
#include "jinete/jrect.h"
|
||||
#include "Vaca/Widget.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -170,7 +171,7 @@ bool jwidget_check_underscored(JWidget widget, int scancode);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Widget
|
||||
class Widget : public Vaca::Widget
|
||||
{
|
||||
public:
|
||||
JID id; /* identify code */
|
||||
|
57
src/jinete/vaca_fusion/include/Vaca/Component.h
Normal file
57
src/jinete/vaca_fusion/include/Vaca/Component.h
Normal file
@ -0,0 +1,57 @@
|
||||
// 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_COMPONENT_H
|
||||
#define VACA_COMPONENT_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
#include "Vaca/Referenceable.h"
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
/**
|
||||
A component is a visual object, such as widgets or menus.
|
||||
|
||||
Components are non-copyable but are referenceable (e.g. you can
|
||||
use them inside a SharedPtr).
|
||||
|
||||
@see NonCopyable, Referenceable, SharedPtr
|
||||
*/
|
||||
class VACA_DLL Component : public Referenceable
|
||||
{
|
||||
public:
|
||||
Component();
|
||||
virtual ~Component();
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_COMPONENT_H
|
90
src/jinete/vaca_fusion/include/Vaca/Debug.h
Normal file
90
src/jinete/vaca_fusion/include/Vaca/Debug.h
Normal file
@ -0,0 +1,90 @@
|
||||
// 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_DEBUG_H
|
||||
#define VACA_DEBUG_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
#ifdef NDEBUG
|
||||
# ifdef __GNUC__
|
||||
# define VACA_TRACE(msg...)
|
||||
# else
|
||||
# define VACA_TRACE(...)
|
||||
# endif
|
||||
#else
|
||||
# ifdef __GNUC__
|
||||
# define VACA_TRACE(msg...) Vaca::details::trace(__FILE__, __LINE__, msg)
|
||||
# else
|
||||
# define VACA_TRACE Vaca::details::make_trace(__FILE__, __LINE__)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
namespace details {
|
||||
|
||||
void VACA_DLL trace(const char* filename, size_t line, const char* msg, ...);
|
||||
void VACA_DLL closeLogFile();
|
||||
|
||||
#ifndef __GNUC__
|
||||
/**
|
||||
@internal
|
||||
Dirty trick for compilers that does not support
|
||||
macros with ellipsis (...).
|
||||
*/
|
||||
struct trace_t {
|
||||
const char* filename;
|
||||
size_t line;
|
||||
void operator()(const char* fmt, ...) {
|
||||
char buf[1024]; // TODO: overflow
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsprintf(buf, fmt, ap);
|
||||
va_end(ap);
|
||||
Vaca::details::trace(filename, line, buf);
|
||||
}
|
||||
};
|
||||
inline trace_t make_trace(const char* filename, size_t line) {
|
||||
trace_t tmp;
|
||||
tmp.filename = filename;
|
||||
tmp.line = line;
|
||||
return tmp;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace details
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_DEBUG_H
|
73
src/jinete/vaca_fusion/include/Vaca/Mutex.h
Normal file
73
src/jinete/vaca_fusion/include/Vaca/Mutex.h
Normal file
@ -0,0 +1,73 @@
|
||||
// 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 MutexPimpl;
|
||||
MutexPimpl* m_pimpl;
|
||||
|
||||
public:
|
||||
|
||||
Mutex();
|
||||
~Mutex();
|
||||
|
||||
void lock();
|
||||
bool tryLock();
|
||||
void unlock();
|
||||
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_MUTEX_H
|
74
src/jinete/vaca_fusion/include/Vaca/NonCopyable.h
Normal file
74
src/jinete/vaca_fusion/include/Vaca/NonCopyable.h
Normal file
@ -0,0 +1,74 @@
|
||||
// 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_NONCOPYABLE_H
|
||||
#define VACA_NONCOPYABLE_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
/**
|
||||
Class which can't be copied.
|
||||
|
||||
If you derive from this class, then you will not be able to make
|
||||
copies of your own class. This means that the class will be
|
||||
copied neither using the copy constructor nor the assigment operator.
|
||||
|
||||
Example:
|
||||
@code
|
||||
class MyClass : private NonCopyable
|
||||
{
|
||||
public:
|
||||
MyClass() {
|
||||
}
|
||||
};
|
||||
int main()
|
||||
{
|
||||
MyClass a, b;
|
||||
MyClass c(a); // <-- compiler error
|
||||
b = a; // <-- compiler error
|
||||
}
|
||||
@endcode
|
||||
*/
|
||||
class VACA_DLL NonCopyable
|
||||
{
|
||||
public:
|
||||
NonCopyable() { }
|
||||
~NonCopyable() { }
|
||||
private:
|
||||
NonCopyable(const NonCopyable&);
|
||||
NonCopyable& operator=(const NonCopyable&);
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_NONCOPYABLE_H
|
68
src/jinete/vaca_fusion/include/Vaca/Referenceable.h
Normal file
68
src/jinete/vaca_fusion/include/Vaca/Referenceable.h
Normal file
@ -0,0 +1,68 @@
|
||||
// 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_REFERENCEABLE_H
|
||||
#define VACA_REFERENCEABLE_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
#include "Vaca/NonCopyable.h"
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
/**
|
||||
Class that counts references and can be wrapped by a SharedPtr.
|
||||
*/
|
||||
class VACA_DLL Referenceable : private NonCopyable
|
||||
{
|
||||
template<class> friend class SharedPtr;
|
||||
unsigned m_refCount;
|
||||
|
||||
public:
|
||||
|
||||
Referenceable();
|
||||
virtual ~Referenceable();
|
||||
|
||||
void ref();
|
||||
unsigned unref();
|
||||
|
||||
unsigned getRefCount();
|
||||
|
||||
#ifndef NDEBUG
|
||||
static void showLeaks();
|
||||
#endif
|
||||
|
||||
private:
|
||||
void destroy();
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_REFERENCEABLE_H
|
104
src/jinete/vaca_fusion/include/Vaca/ScopedLock.h
Normal file
104
src/jinete/vaca_fusion/include/Vaca/ScopedLock.h
Normal file
@ -0,0 +1,104 @@
|
||||
// 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
|
48
src/jinete/vaca_fusion/include/Vaca/Widget.h
Normal file
48
src/jinete/vaca_fusion/include/Vaca/Widget.h
Normal file
@ -0,0 +1,48 @@
|
||||
// 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_WIDGET_H
|
||||
#define VACA_WIDGET_H
|
||||
|
||||
#include "Vaca/Component.h"
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
class VACA_DLL Widget : public Component
|
||||
{
|
||||
public:
|
||||
Widget() { }
|
||||
virtual ~Widget() { }
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_WIDGET_H
|
59
src/jinete/vaca_fusion/src/Component.cpp
Normal file
59
src/jinete/vaca_fusion/src/Component.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
// 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/Component.h"
|
||||
#include "Vaca/Debug.h"
|
||||
|
||||
using namespace Vaca;
|
||||
|
||||
/**
|
||||
Creates a new component.
|
||||
|
||||
With the debug version of the library, you will get in the
|
||||
@ref page_debug_log a line specifying when the component
|
||||
was created.
|
||||
*/
|
||||
Component::Component()
|
||||
{
|
||||
VACA_TRACE("new Component (%p)\n", this);
|
||||
}
|
||||
|
||||
/**
|
||||
Destroys the component.
|
||||
|
||||
With the debug version of the library, you will get in the
|
||||
@ref page_debug_log a line specifying when the component
|
||||
was destroyed.
|
||||
*/
|
||||
Component::~Component()
|
||||
{
|
||||
VACA_TRACE("delete Component (%p)\n", this);
|
||||
}
|
95
src/jinete/vaca_fusion/src/Debug.cpp
Normal file
95
src/jinete/vaca_fusion/src/Debug.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
// 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/Debug.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
// #include "Vaca/System.h"
|
||||
// #include "Vaca/Thread.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
using namespace std;
|
||||
using namespace Vaca;
|
||||
|
||||
#ifndef NDEBUG
|
||||
struct Debug;
|
||||
|
||||
static bool closed;
|
||||
static Debug* dbg;
|
||||
|
||||
struct Debug
|
||||
{
|
||||
Mutex mutex;
|
||||
FILE* file;
|
||||
Debug() {
|
||||
file = fopen("vaca.log", "w");
|
||||
fprintf(file, "Log file created\n");
|
||||
}
|
||||
virtual ~Debug() {
|
||||
fprintf(file, "Log file closed\n");
|
||||
fclose(file);
|
||||
file = NULL;
|
||||
closed = true;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
void Vaca::details::trace(const char* filename, size_t line, const char* fmt, ...)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if (closed) { return; }
|
||||
if (!dbg) { dbg = new Debug; }
|
||||
|
||||
ScopedLock lock(dbg->mutex);
|
||||
char buf[1024]; // TODO: overflow
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsprintf(buf, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
// TODO add Thread class
|
||||
// fprintf(dbg->file, "%s:%d: [%d] %s", filename, line,
|
||||
// static_cast<unsigned>(::GetCurrentThreadId()), buf);
|
||||
fprintf(dbg->file, "%s:%d: [%d] %s", filename, line,
|
||||
static_cast<unsigned>(0), buf);
|
||||
fflush(dbg->file);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Vaca::details::closeLogFile()
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
delete dbg;
|
||||
dbg = NULL;
|
||||
#endif
|
||||
}
|
107
src/jinete/vaca_fusion/src/Mutex.cpp
Normal file
107
src/jinete/vaca_fusion/src/Mutex.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
// 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_WINDOWS)
|
||||
#include "win32/MutexPimpl.h"
|
||||
#elif defined(VACA_ALLEGRO)
|
||||
#include <allegro/base.h>
|
||||
#if defined(ALLEGRO_WINDOWS)
|
||||
#include "win32/MutexPimpl.h"
|
||||
#else
|
||||
#include "unix/MutexPimpl.h"
|
||||
#endif
|
||||
#else
|
||||
#include "unix/MutexPimpl.h"
|
||||
#endif
|
||||
|
||||
using namespace Vaca;
|
||||
|
||||
/**
|
||||
Creates a new mutex.
|
||||
|
||||
@win32
|
||||
It uses @msdn{InitializeCriticalSection}.
|
||||
@endwin32
|
||||
*/
|
||||
Mutex::Mutex()
|
||||
{
|
||||
m_pimpl = new MutexPimpl();
|
||||
}
|
||||
|
||||
/**
|
||||
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();
|
||||
}
|
142
src/jinete/vaca_fusion/src/Referenceable.cpp
Normal file
142
src/jinete/vaca_fusion/src/Referenceable.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
// 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/Referenceable.h"
|
||||
#include "Vaca/Debug.h"
|
||||
|
||||
#ifndef NDEBUG
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
#include <vector>
|
||||
#include <typeinfo>
|
||||
#endif
|
||||
|
||||
using namespace Vaca;
|
||||
|
||||
#ifndef NDEBUG
|
||||
static Mutex s_mutex;
|
||||
static std::vector<Referenceable*> s_list;
|
||||
#endif
|
||||
|
||||
/**
|
||||
Constructs a new referenceable object starting with zero references.
|
||||
*/
|
||||
Referenceable::Referenceable()
|
||||
{
|
||||
m_refCount = 0;
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
ScopedLock hold(s_mutex);
|
||||
VACA_TRACE("new Referenceable (%d, %p)\n", s_list.size()+1, this);
|
||||
s_list.push_back(this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
Destroys a referenceable object.
|
||||
|
||||
When compiling with assertions it checks that the references'
|
||||
counter is really zero.
|
||||
*/
|
||||
Referenceable::~Referenceable()
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
ScopedLock hold(s_mutex);
|
||||
VACA_TRACE("delete Referenceable (%d, %p)\n", s_list.size()-1, this);
|
||||
remove_from_container(s_list, this);
|
||||
}
|
||||
#endif
|
||||
assert(m_refCount == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
Called by SharedPtr to destroy the referenceable.
|
||||
*/
|
||||
void Referenceable::destroy()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
/**
|
||||
Makes a new reference to this object.
|
||||
|
||||
You are responsible for removing references using the #unref
|
||||
member function. Remember that for each call to #ref that you made,
|
||||
there should be a corresponding #unref.
|
||||
|
||||
@see unref
|
||||
*/
|
||||
void Referenceable::ref()
|
||||
{
|
||||
++m_refCount;
|
||||
}
|
||||
|
||||
/**
|
||||
Deletes an old reference to this object.
|
||||
|
||||
If assertions are activated this routine checks that the
|
||||
reference counter never get negative, because that implies
|
||||
an error of the programmer.
|
||||
|
||||
@see ref
|
||||
*/
|
||||
unsigned Referenceable::unref()
|
||||
{
|
||||
assert(m_refCount > 0);
|
||||
return --m_refCount;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the current number of references that this object has.
|
||||
|
||||
If it's zero you can delete the object safely.
|
||||
*/
|
||||
unsigned Referenceable::getRefCount()
|
||||
{
|
||||
return m_refCount;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
void Referenceable::showLeaks()
|
||||
{
|
||||
#ifdef VACA_WINDOWS
|
||||
if (!s_list.empty())
|
||||
::Beep(400, 100);
|
||||
#endif
|
||||
|
||||
for (std::vector<Referenceable*>::iterator
|
||||
it=s_list.begin(); it!=s_list.end(); ++it) {
|
||||
VACA_TRACE("leak Referenceable %p\n", *it);
|
||||
}
|
||||
}
|
||||
#endif
|
66
src/jinete/vaca_fusion/src/unix/MutexPimpl.h
Normal file
66
src/jinete/vaca_fusion/src/unix/MutexPimpl.h
Normal file
@ -0,0 +1,66 @@
|
||||
// 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>
|
||||
|
||||
class Vaca::Mutex::MutexPimpl
|
||||
{
|
||||
pthread_mutex_t m_handle;
|
||||
|
||||
public:
|
||||
|
||||
MutexPimpl()
|
||||
{
|
||||
pthread_mutex_init(&m_handle, NULL);
|
||||
}
|
||||
|
||||
~MutexPimpl()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
||||
|
65
src/jinete/vaca_fusion/src/win32/MutexPimpl.h
Normal file
65
src/jinete/vaca_fusion/src/win32/MutexPimpl.h
Normal file
@ -0,0 +1,65 @@
|
||||
// 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 <windows.h>
|
||||
|
||||
class Vaca::Mutex::MutexPimpl
|
||||
{
|
||||
CRITICAL_SECTION m_handle;
|
||||
|
||||
public:
|
||||
|
||||
MutexPimpl()
|
||||
{
|
||||
InitializeCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
~MutexPimpl()
|
||||
{
|
||||
DeleteCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
EnterCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
bool tryLock()
|
||||
{
|
||||
return TryEnterCriticalSection(&m_handle) ? true: false;
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
LeaveCriticalSection(&m_handle);
|
||||
}
|
||||
|
||||
};
|
@ -23,12 +23,15 @@
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
#include "jinete/jmutex.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "raster/gfxobj.h"
|
||||
|
||||
static JMutex objects_mutex;
|
||||
using Vaca::Mutex;
|
||||
using Vaca::ScopedLock;
|
||||
|
||||
static Mutex* objects_mutex;
|
||||
static gfxobj_id object_id = 0; // last object ID created
|
||||
static std::map<gfxobj_id, GfxObj*>* objects_map; // graphics objects map
|
||||
|
||||
@ -38,14 +41,14 @@ static void erase_gfxobj(GfxObj* gfxobj);
|
||||
RasterModule::RasterModule()
|
||||
{
|
||||
objects_map = new std::map<gfxobj_id, GfxObj*>;
|
||||
objects_mutex = jmutex_new();
|
||||
objects_mutex = new Mutex();
|
||||
}
|
||||
|
||||
RasterModule::~RasterModule()
|
||||
{
|
||||
assert(objects_map->empty());
|
||||
delete objects_map;
|
||||
jmutex_free(objects_mutex);
|
||||
delete objects_mutex;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -65,25 +68,21 @@ GfxObj::GfxObj(const GfxObj& gfxobj)
|
||||
|
||||
GfxObj::~GfxObj()
|
||||
{
|
||||
ScopedLock lock(*objects_mutex);
|
||||
|
||||
// we have to remove this object from the map
|
||||
jmutex_lock(objects_mutex);
|
||||
{
|
||||
erase_gfxobj(this);
|
||||
}
|
||||
jmutex_unlock(objects_mutex);
|
||||
erase_gfxobj(this);
|
||||
}
|
||||
|
||||
void GfxObj::assign_id()
|
||||
{
|
||||
// we have to assign an ID for this object
|
||||
jmutex_lock(objects_mutex);
|
||||
{
|
||||
this->id = ++object_id;
|
||||
ScopedLock lock(*objects_mutex);
|
||||
|
||||
// and here we add the object in the map of graphics-objects
|
||||
insert_gfxobj(this);
|
||||
}
|
||||
jmutex_unlock(objects_mutex);
|
||||
// we have to assign an ID for this object
|
||||
this->id = ++object_id;
|
||||
|
||||
// and here we add the object in the map of graphics-objects
|
||||
insert_gfxobj(this);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -91,17 +90,15 @@ void GfxObj::assign_id()
|
||||
GfxObj* gfxobj_find(gfxobj_id id)
|
||||
{
|
||||
GfxObj* ret = NULL;
|
||||
|
||||
jmutex_lock(objects_mutex);
|
||||
{
|
||||
ScopedLock lock(*objects_mutex);
|
||||
|
||||
std::map<gfxobj_id, GfxObj*>::iterator
|
||||
it = objects_map->find(id);
|
||||
|
||||
if (it != objects_map->end())
|
||||
ret = it->second;
|
||||
}
|
||||
jmutex_unlock(objects_mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -110,13 +107,11 @@ void _gfxobj_set_id(GfxObj* gfxobj, gfxobj_id id)
|
||||
assert(gfxobj_find(gfxobj->id) == gfxobj);
|
||||
assert(gfxobj_find(id) == NULL);
|
||||
|
||||
jmutex_lock(objects_mutex);
|
||||
{
|
||||
erase_gfxobj(gfxobj); // remove the object
|
||||
gfxobj->id = id; // change the ID
|
||||
insert_gfxobj(gfxobj); // insert the object again in the map
|
||||
}
|
||||
jmutex_unlock(objects_mutex);
|
||||
ScopedLock lock(*objects_mutex);
|
||||
|
||||
erase_gfxobj(gfxobj); // remove the object
|
||||
gfxobj->id = id; // change the ID
|
||||
insert_gfxobj(gfxobj); // insert the object again in the map
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -22,13 +22,17 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "jinete/jlist.h"
|
||||
#include "jinete/jmutex.h"
|
||||
#include "Vaca/Mutex.h"
|
||||
#include "Vaca/ScopedLock.h"
|
||||
|
||||
#include "file/format_options.h"
|
||||
#include "modules/palettes.h"
|
||||
#include "raster/raster.h"
|
||||
#include "util/boundary.h"
|
||||
|
||||
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);
|
||||
static int layer_count_layers(const Layer *layer);
|
||||
@ -94,7 +98,7 @@ Sprite::Sprite(int imgtype, int w, int h)
|
||||
/* multiple access */
|
||||
m_write_lock = false;
|
||||
m_read_locks = 0;
|
||||
m_mutex = jmutex_new();
|
||||
m_mutex = new Mutex();
|
||||
|
||||
/* file format options */
|
||||
this->format_options = NULL;
|
||||
@ -144,9 +148,7 @@ Sprite::~Sprite()
|
||||
delete this->m_extras; // image
|
||||
if (this->frlens) jfree(this->frlens);
|
||||
if (this->bound.seg) jfree(this->bound.seg);
|
||||
|
||||
/* destroy mutex */
|
||||
jmutex_free(this->m_mutex);
|
||||
delete this->m_mutex;
|
||||
|
||||
/* destroy file format options */
|
||||
if (this->format_options)
|
||||
@ -314,7 +316,7 @@ bool sprite_need_alpha(const Sprite* sprite)
|
||||
*/
|
||||
bool Sprite::lock(bool write)
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
ScopedLock lock(*m_mutex);
|
||||
|
||||
// read-only
|
||||
if (!write) {
|
||||
@ -344,7 +346,7 @@ bool Sprite::lock(bool write)
|
||||
*/
|
||||
bool Sprite::lock_to_write()
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
ScopedLock lock(*m_mutex);
|
||||
|
||||
// this only is possible if there are just one reader
|
||||
if (m_read_locks == 1) {
|
||||
@ -363,7 +365,8 @@ bool Sprite::lock_to_write()
|
||||
*/
|
||||
void Sprite::unlock_to_read()
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
ScopedLock lock(*m_mutex);
|
||||
|
||||
assert(m_read_locks == 0);
|
||||
assert(m_write_lock);
|
||||
|
||||
@ -373,7 +376,7 @@ void Sprite::unlock_to_read()
|
||||
|
||||
void Sprite::unlock()
|
||||
{
|
||||
ScopedLock hold(m_mutex);
|
||||
ScopedLock lock(*m_mutex);
|
||||
|
||||
if (m_write_lock) {
|
||||
m_write_lock = false;
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include "jinete/jbase.h"
|
||||
#include "raster/gfxobj.h"
|
||||
|
||||
namespace Vaca { class Mutex; }
|
||||
|
||||
struct FormatOptions;
|
||||
class Image;
|
||||
class Layer;
|
||||
@ -82,7 +84,7 @@ private:
|
||||
int m_extras_opacity; // Opacity to be used to draw the extra image
|
||||
|
||||
// Mutex to modify the 'locked' flag.
|
||||
JMutex m_mutex;
|
||||
Vaca::Mutex* m_mutex;
|
||||
|
||||
// True if some thread is writing the sprite.
|
||||
bool m_write_lock;
|
||||
|
Loading…
x
Reference in New Issue
Block a user