18 #define FLYWEIGHT_FAILED (-1) 19 #define FLYWEIGHT_SUCCESS (0) 73 #define FLYWEIGHT_CLASS_LOCK(instance) DPUTIL_LOCK(instance->lock) 74 #define FLYWEIGHT_CLASS_UNLOCK DPUTIL_UNLOCK 88 instance->
instance = calloc(1, size);
98 if( instance && instance->
instance ) {
120 instance=instance->
next;
171 if(input_parameter==NULL) {
175 memcpy(
this, input_parameter, size);
180 if(input_parameter==NULL) {
184 return (memcmp(
this, input_parameter, size) == 0);
189 if(input_parameter==NULL) {
193 memcpy(
this, input_parameter, size);
221 DEBUG_ERRPRINT(
"calloc instance list error:%s\n", strerror(errno));
226 if( is_threadsafe ) {
227 class_factory->lock = (pthread_mutex_t *) calloc(1,
sizeof(pthread_mutex_t));
229 DEBUG_ERRPRINT(
"class instance lock error:%s\n", strerror(errno));
282 ret = setter(instance->
instance, this->class_size, data);
283 }
else if ( this->methods.setter ) {
284 ret = this->methods.setter(instance->
instance, this->class_size, data);
299 pthread_mutex_t *keep_mutex_for_free=this->lock;
307 if(this->methods.destructor) {
308 this->methods.destructor(instance->
instance);
318 free(keep_mutex_for_free);
pthread_mutex_t * lock
list of instance
struct flyweight_factory_t * FlyweightFactory
FlyweightFactory definition.
static void flyweight_factory_push_instance(FlyweightInstance instance, FlyweightFactory class_factory)
push instance into list.
static void flyweight_class_default_constructor(void *this, size_t size, void *input_parameter)
Default constructor.
This is API as Flyweight design petten.
instance data definition.
#define FLYWEIGHT_SUCCESS
#define FLYWEIGHT_CLASS_UNLOCK
static FlyweightInstance flyweight_factory_get_storaged_instance(FlyweightFactory class_factory, void *constructor_parameter)
Check has instance.
void(* free)(EventInstance this)
static void flyweight_class_set_methods(FlyweightMethodsIF methods, FlyweightFactory instance)
Set methods.
FlyweightFactory member definition, defined in flyweight.c.
static int flyweight_class_default_equall_operand(void *this, size_t size, void *input_parameter)
Default equall operand.
struct flyweight_instance_t * FlyweightInstance
static FlyweightInstance flyweight_instance_new(size_t size)
static int flyweight_class_default_setter(void *this, size_t size, void *input_parameter)
Default setter.
int flyweight_set(FlyweightFactory this, void *constructor_parameter, void *data, int(*setter)(void *this, size_t size, void *input_parameter))
setter
FlyweightInstance class_instances
size of class
void flyweight_factory_free(FlyweightFactory this)
clear class handle
static FlyweightInstance flyweight_factory_instance_new(FlyweightFactory class_factory, void *constructor_parameter)
allocate.
static FlyweightInstance flyweight_factory_pop_instance(FlyweightFactory class_factory)
pop instance from list.
#define FLYWEIGHT_CLASS_LOCK(instance)
FlyweightFactory flyweight_factory_new(size_t class_size, int is_threadsafe, FlyweightMethodsIF methods)
define class for flyweight
static void flyweight_instance_free(FlyweightInstance instance)
instance data definition, instance storaged by list
static FlyweightInstance flyweight_factory_get(FlyweightFactory class_factory, void *constructor_parameter)
Getter.
flyweight_methods_t methods
void * flyweight_get(FlyweightFactory this, void *constructor_parameter)
getter
#define DEBUG_ERRPRINT(...)
Flyweight methods interface definition, to set flyweight_factory_new.