Commit 661c75b6 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Remove SingletonVault C bindings

Summary: [Folly] Remove `SingletonVault` C bindings. They are not generally needed.

Reviewed By: spalamarchuk

Differential Revision: D6632104

fbshipit-source-id: 3aecb35277bc76a2171487404d6994a5ea296afc
parent 43523e0c
/*
* Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/SingletonVault_c.h>
#include <folly/Singleton.h>
extern "C" {
SingletonVault_t *SingletonVault_singleton() {
return folly::SingletonVault::singleton();
}
void SingletonVault_registrationComplete(SingletonVault_t *vault) {
((folly::SingletonVault*) vault)->registrationComplete();
}
void SingletonVault_destroyInstances(SingletonVault_t *vault) {
((folly::SingletonVault*) vault)->destroyInstances();
}
void SingletonVault_reenableInstances(SingletonVault_t *vault) {
((folly::SingletonVault*) vault)->reenableInstances();
}
} // extern "C"
/*
* Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Plain C interface to SingletonVault. This facilitates combining programs
// that cannot use C++ (e.g. programs written in C) with libraries that use
// Singleton, by allowing the program to perform the required SingletonVault
// lifecycle calls.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef void SingletonVault_t;
SingletonVault_t *SingletonVault_singleton();
void SingletonVault_registrationComplete(SingletonVault_t *vault);
void SingletonVault_destroyInstances(SingletonVault_t *vault);
void SingletonVault_reenableInstances(SingletonVault_t *vault);
#ifdef __cplusplus
} // extern "C"
#endif
/*
* Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/Singleton.h>
#include <folly/SingletonVault_c.h>
#include <folly/portability/GTest.h>
FOLLY_TLS long instance_counter_instances = 0;
class InstanceCounter {
public:
InstanceCounter() {
instance_counter_instances++;
}
~InstanceCounter() {
instance_counter_instances--;
}
};
TEST(SingletonVault, singletonReturnsSingletonInstance) {
SingletonVault_t *c = SingletonVault_singleton();
auto *cpp = folly::SingletonVault::singleton();
EXPECT_EQ(c, cpp);
}
struct TestTag {};
template <typename T, typename Tag = folly::detail::DefaultTag>
using SingletonTest = folly::Singleton <T, Tag, TestTag>;
TEST(SingletonVault, singletonsAreCreatedAndDestroyed) {
auto vault = folly::SingletonVault::singleton<TestTag>();
SingletonTest<InstanceCounter> counter_singleton;
SingletonVault_registrationComplete((SingletonVault_t*) vault);
SingletonTest<InstanceCounter>::try_get();
EXPECT_EQ(instance_counter_instances, 1);
SingletonVault_destroyInstances((SingletonVault_t*) vault);
EXPECT_EQ(instance_counter_instances, 0);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment