bin: reorganize _remove_func to avoid races
bin: reorganize _remove_func to avoid races

Make the gst_bin_remove_func more like the add_func. Check if the element we try
to remove from the bin has the bin as the parent and set the parent flag to NULL
immediately, this allows us to avoid concurrent remove operations without using
the UNPARENTING element flag. After we unparented the element from the bin, we
update the bin state and remove the element from the list. Finally we unlink
all the pads.

This avoids a race condition where the element could still claim to have the
bin as the parent while the bin didn't have a pointer to the element anymore.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=647759

mparis/gstreamer,jpakkane/gstreamer,StreamUtils/gstreamer,krieger-od/gstreamer,cablelabs/gstreamer,surround-io/gstreamer,collects/gstreamer,krieger-od/gstreamer,ensonic/gstreamer,lubosz/gstreamer,centricular/gstreamer,ensonic/gstreamer,jpxiong/gstreamer,justinjoy/gstreamer,mparis/gstreamer,justinjoy/gstreamer,surround-io/gstreamer,krieger-od/gstreamer,shelsonjava/gstreamer,krieger-od/gstreamer,centricular/gstreamer,StreamUtils/gstreamer,shelsonjava/gstreamer,lovebug356/gstreamer,jpxiong/gstreamer,jpxiong/gstreamer,cfoch/gstreamer,collects/gstreamer,cablelabs/gstreamer,ensonic/gstreamer,surround-io/gstreamer,ensonic/gstreamer,Lachann/gstreamer,jpakkane/gstreamer,lubosz/gstreamer,Lachann/gstreamer,cfoch/gstreamer,jpakkane/gstreamer,jpxiong/gstreamer,centricular/gstreamer,Lachann/gstreamer,StreamUtils/gstreamer,shelsonjava/gstreamer,cablelabs/gstreamer,collects/gstreamer,mparis/gstreamer,krichter722/gstreamer,shelsonjava/gstreamer,collects/gstreamer,krichter722/gstreamer,centricular/gstreamer,krichter722/gstreamer,Lachann/gstreamer,lubosz/gstreamer,cfoch/gstreamer,lovebug356/gstreamer,cablelabs/gstreamer,lubosz/gstreamer,surround-io/gstreamer,krieger-od/gstreamer,Lachann/gstreamer,collects/gstreamer,jpakkane/gstreamer,krichter722/gstreamer,jpxiong/gstreamer,jpakkane/gstreamer,justinjoy/gstreamer,justinjoy/gstreamer,StreamUtils/gstreamer,lovebug356/gstreamer,centricular/gstreamer,mparis/gstreamer,StreamUtils/gstreamer,ensonic/gstreamer,shelsonjava/gstreamer,lubosz/gstreamer,krichter722/gstreamer,cfoch/gstreamer,lovebug356/gstreamer,mparis/gstreamer,cfoch/gstreamer,justinjoy/gstreamer,surround-io/gstreamer,cablelabs/gstreamer,lovebug356/gstreamer