rewrite OnSubscribeRefCount to handle synchronous source

Resubmitting this one having stuffed up the rebase.

Rewrite of ```OnSubscribeRefCount``` because original didn't handle synchronous source (#1688) and as far as I could see the original was fundamentally broken by this use case. Please note also includes a fix in ```OperatorMulticast``` where a null check was required. I've done the rewrite using locks rather than submit a lock-free version just to ensure that the approach is valid with the experts first.
Yep it is in response to an existing RefCount test testing subscription
with an unsubscribed subscriber.
On 3 Oct 2014 11:39, "Ben Christensen" <notifications@github.com> wrote:

> In rxjava-core/src/main/java/rx/internal/operators/OperatorMulticast.java:
>
> > @@ -137,7 +137,13 @@ public void call() {
> >              }));
> >
> >              // now that everything is hooked up let's subscribe
> > -            source.unsafeSubscribe(subscription);
> > +            // as long as the subscription is not null
> > +            boolean subscriptionIsNull;
> > +            synchronized(guard) {
> > +                subscriptionIsNull = subscription == null;
>
> What causes this? Is it because the subscription has been unsubscribed
> already?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/ReactiveX/RxJava/pull/1695/files#r18372612>.
>