zouboan commented on issue #6012:
URL: https://github.com/apache/nuttx/issues/6012#issuecomment-1597428830

   @xiaoxiang781216 sorry I did not continue with my work, I implemented a 
read-write lock, based on semaphore last year:
   
https://github.com/zouboan/nuttx/commit/a9ff305f2d365462513c28f416134152f862c749
   
   but I feel my implementation was something dumb, for example, the read lock 
implementation as follow:
   ` flags = enter_critical_section();
   
     ret = nxsem_wait_uninterruptible(&lock->read);
     if (ret < 0)
       {
         goto errout;
       }
   
     lock->reads++;
   
     if (lock->reads == 1)
       {
         ret = nxsem_wait_uninterruptible(&lock->write);
         if (ret < 0)
           {
             goto errout;
           }
       }
   
     ret = nxsem_post(&lock->read);
     leave_critical_section(flags);
   `
   there's need critical section protect between get read lock and get write 
lock, and at that time I thought why not use critical section on 
   `      *filep = &list->fl_files[fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK]
                                 [fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK];`
   directly?
   maybe the community has a better implementation


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to