multithreading - C++ shared_ptr and direct buffer enqueueing. How? -


i need make small code refactoring queueing/dequeueing operation in multi-thread application. current implementation is:

  • enqueueing function called argument:

    enqueue(obj_ptr item) 

    where obj_ptr pointer class obj created using shared_ptr. then, given items (type obj_ptr) enqueued in std list

    list<obj_ptr> 

    and dequeued using front() , pop_front() , sent further. works fine in implementation.

  • what want is:

    enqueue items in special list using api:

    a_enqueue(void *buffer) 

    so need direct address buffer.

i thinking use:

    item->get() 

which returns type obj dequeue obj, not obj_ptr expected next operations after dequeueing (+ loose information class references , destroy multi-thread app)

i thinking provide list pointer obj_ref item:

    a_enqueue(&item) 

but item created in function long time ago , put argument many times (not pointer) , not possible find direct address it.

the best way me enqueue buffer obj (item->get()), dequeue , find somehow same reference obj_ptr item used in get(). possible? other ideas?

thanks.

edit: dequeue call is:

 a_dequeue(void **buffer) 

what api dequeue like?

usually if you're enqueueing void *, you're defining handler function can this...

void enqueue_ptr (obj_ptr enqueue_me) {   // making copy on heap increments ptr count   obj_ptr * heap_ptr = new obj_ptr(enqueue_me);   a_enqueue (heap_ptr); }   obj_ptr dequeue_ptr (void) {   // might need casting change void * obj_ptr *   obj_ptr * heap_ptr;   a_dequeue (&heap_ptr);    // sticking copy in auto_ptr decrements ptr count when leave scope.   std::auto_ptr<obj_ptr> obj_pptr(heap_ptr);   return *obj_pptr; } 

basically, treat obj_ptr same other object being passed around void *.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -