|
12 | 12 | // See the License for the specific language governing permissions and
|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 |
| -use std::cell::UnsafeCell; |
16 |
| -use std::sync::Arc; |
17 |
| - |
18 |
| -use common_base::base::GlobalIORuntime; |
19 |
| -use common_base::base::Runtime; |
20 |
| -use common_base::base::SingletonImpl; |
| 15 | +use common_base::base::GlobalInstance; |
| 16 | +use common_base::runtime::GlobalIORuntime; |
21 | 17 | use common_exception::Result;
|
22 | 18 |
|
23 | 19 | use crate::accessor::SharingAccessor;
|
24 | 20 | use crate::configs::Config;
|
25 | 21 |
|
26 | 22 | // hold singleton services.
|
27 |
| -pub struct SharingServices { |
28 |
| - // by default, operator init needs the global_runtime singleton instance |
29 |
| - // thus we keep it in the sharing services, alternatively, we may consider expose no layer operator |
30 |
| - global_runtime: UnsafeCell<Option<Arc<Runtime>>>, |
31 |
| - // storage_accessor is the accessor for the shared tenant data. |
32 |
| - storage_accessor: UnsafeCell<Option<Arc<SharingAccessor>>>, |
33 |
| -} |
34 |
| - |
35 |
| -unsafe impl Send for SharingServices {} |
36 |
| - |
37 |
| -unsafe impl Sync for SharingServices {} |
| 23 | +pub struct SharingServices {} |
38 | 24 |
|
39 | 25 | impl SharingServices {
|
40 | 26 | pub async fn init(config: Config) -> Result<()> {
|
41 |
| - let sharing_services = Arc::new(SharingServices { |
42 |
| - global_runtime: UnsafeCell::new(None), |
43 |
| - storage_accessor: UnsafeCell::new(None), |
44 |
| - }); |
45 |
| - GlobalIORuntime::init(config.storage.num_cpus as usize, sharing_services.clone())?; |
46 |
| - SharingAccessor::init(&config, sharing_services.clone()).await |
47 |
| - } |
48 |
| -} |
49 |
| - |
50 |
| -impl SingletonImpl<Arc<SharingAccessor>> for SharingServices { |
51 |
| - fn get(&self) -> Arc<SharingAccessor> { |
52 |
| - unsafe { |
53 |
| - match &*self.storage_accessor.get() { |
54 |
| - None => panic!("Sharing Accessor is not init"), |
55 |
| - Some(storage_accessor) => storage_accessor.clone(), |
56 |
| - } |
57 |
| - } |
58 |
| - } |
59 |
| - |
60 |
| - fn init(&self, value: Arc<SharingAccessor>) -> Result<()> { |
61 |
| - unsafe { |
62 |
| - *(self.storage_accessor.get() as *mut Option<Arc<SharingAccessor>>) = Some(value); |
63 |
| - Ok(()) |
64 |
| - } |
65 |
| - } |
66 |
| -} |
67 |
| - |
68 |
| -impl SingletonImpl<Arc<Runtime>> for SharingServices { |
69 |
| - fn get(&self) -> Arc<Runtime> { |
70 |
| - unsafe { |
71 |
| - match &*self.global_runtime.get() { |
72 |
| - None => panic!("Global Runtime is not init"), |
73 |
| - Some(runtime) => runtime.clone(), |
74 |
| - } |
75 |
| - } |
76 |
| - } |
| 27 | + // init global instance singleton |
| 28 | + GlobalInstance::init_production(); |
77 | 29 |
|
78 |
| - fn init(&self, value: Arc<Runtime>) -> Result<()> { |
79 |
| - unsafe { |
80 |
| - *(self.global_runtime.get() as *mut Option<Arc<Runtime>>) = Some(value); |
81 |
| - Ok(()) |
82 |
| - } |
| 30 | + GlobalIORuntime::init(config.storage.num_cpus as usize)?; |
| 31 | + SharingAccessor::init(&config).await |
83 | 32 | }
|
84 | 33 | }
|
0 commit comments