lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <CVZ2KU4KK5YH.2HVL1F6X93YLL@pogg>
Date:   Tue, 03 Oct 2023 23:13:25 +0300
From:   "Konstantin Shelekhin" <k.shelekhin@...l.net>
To:     <aliceryhl@...gle.com>
Cc:     <alex.gaynor@...il.com>, <benno.lossin@...ton.me>,
        <bjorn3_gh@...tonmail.com>, <boqun.feng@...il.com>,
        <gary@...yguo.net>, <jiangshanlai@...il.com>,
        <linux-kernel@...r.kernel.org>, <nmi@...aspace.dk>,
        <ojeda@...nel.org>, <patches@...ts.linux.dev>,
        <rust-for-linux@...r.kernel.org>, <tj@...nel.org>,
        <wedsonaf@...il.com>, <yakoyoku@...il.com>
Subject: Re: [PATCH v4 7/7] rust: workqueue: add examples

+//! #[pin_data]
+//! struct MyStruct {
+//!     value: i32,
+//!     #[pin]
+//!     work: Work<MyStruct>,
+//! }
+//!
+//! impl_has_work! {
+//!     impl HasWork<Self> for MyStruct { self.work }
+//! }
+//!
+//! impl MyStruct {
+//!     fn new(value: i32) -> Result<Arc<Self>> {
+//!         Arc::pin_init(pin_init!(MyStruct {
+//!             value,
+//!             work <- new_work!("MyStruct::work"),
+//!         }))
+//!     }
+//! }
+//!
+//! impl WorkItem for MyStruct {
+//!     type Pointer = Arc<MyStruct>;
+//!
+//!     fn run(this: Arc<MyStruct>) {
+//!         pr_info!("The value is: {}", this.value);
+//!     }
+//! }
+//!
+//! /// This method will enqueue the struct for execution on the system workqueue, where its value
+//! /// will be printed.
+//! fn print_later(val: Arc<MyStruct>) {
+//!     let _ = workqueue::system().enqueue(val);
+//! }

I understand that this is highly opionated, but is it possible to make
the initialization less verbose?

Because the C version looks much, much cleaner and easier to grasp:

    struct my_struct {
        i32 value;
        struct work_struct work;
    };

    void log_value(struct work_struct *work)
    {
        struct my_struct *s = container_of(work, struct my_struct, work);
        pr_info("The value is: %d\n", s->value);
    }

    void print_later(struct my_struct &s)
    {
        INIT_WORK(&s->work, log_value);
        schedule_work(&s->work);
    }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ