11use core:: {
2+ cell:: Cell ,
23 ffi:: { CStr , c_char, c_int, c_void} ,
34 ptr:: null_mut,
4- sync:: atomic:: { AtomicBool , Ordering } ,
55} ;
66
77use alloc:: { boxed:: Box , rc:: Rc } ;
@@ -22,7 +22,7 @@ use crate::{constants::SUBTYPE_JSON, error::PowerSyncError, state::DatabaseState
2222/// closed and the function is unregistered.
2323pub fn register ( db : * mut sqlite:: sqlite3 , state : Rc < DatabaseState > ) -> Result < ( ) , ResultCode > {
2424 let state = Box :: new ( HookState {
25- has_registered_hooks : AtomicBool :: new ( false ) ,
25+ has_registered_hooks : Cell :: new ( false ) ,
2626 db,
2727 state,
2828 } ) ;
@@ -41,15 +41,15 @@ pub fn register(db: *mut sqlite::sqlite3, state: Rc<DatabaseState>) -> Result<()
4141}
4242
4343struct HookState {
44- has_registered_hooks : AtomicBool ,
44+ has_registered_hooks : Cell < bool > ,
4545 db : * mut sqlite:: sqlite3 ,
4646 state : Rc < DatabaseState > ,
4747}
4848
4949extern "C" fn destroy_function ( ctx : * mut c_void ) {
5050 let state = unsafe { Box :: from_raw ( ctx as * mut HookState ) } ;
5151
52- if state. has_registered_hooks . load ( Ordering :: Relaxed ) {
52+ if state. has_registered_hooks . get ( ) {
5353 check_previous (
5454 "update" ,
5555 & state. state ,
@@ -107,7 +107,7 @@ extern "C" fn powersync_update_hooks(
107107 Rc :: into_raw ( db_state. clone ( ) ) as * mut c_void ,
108108 ) ,
109109 ) ;
110- state. has_registered_hooks . store ( true , Ordering :: Relaxed ) ;
110+ state. has_registered_hooks . set ( true ) ;
111111 }
112112 "get" => {
113113 let state = unsafe { user_data. as_ref ( ) . unwrap_unchecked ( ) } ;
0 commit comments