Atomic operation question
Glib provides a set of functions to atomically read and set int and void* values. The documentation says that, where possible, this uses atomic write, read, and test operations provided by the specific architecture, and where the architecture doesn't support it glib uses slower backups.
My question is, are these or any similar functions likely to play well with bit fields? I'm looking to write an application that would require lightning-fast IPC between two processes, and I'm looking to use SysV style shared memory to fit the task. In the structure I'm creating I thought that I'd use a single unsigned char of data to represent eight different pollable flags. I'd rather not implement a semaphore for each value. As you might have guessed, performance and memory footprint are at a premium here - hence the bothering with bit fields. The question's over, but in case you're wondering, the application is a (very experimental, design phase) VFS. I don't feel like gnome-vfs or KIO will reconcile very soon, and I don't like the freedesktop.org assumption that a VFS is for desktop (graphical) apps only, so I'm starting to design one myself. If this ever becomes more than a crazy idea in my head and ravings on paper, I'll get a sourceforge and let you know then. |
It sounds like you want to reinvent a "spinlock" for yourself.
Here are a couple of links that might help: http://www.open-std.org/jtc1/sc22/wg...007/n2195.html http://msdn.microsoft.com/msdnmag/is...urrentAffairs/ http://www.cs.usu.edu/~jerry/Classes.../hardware.html 'Hope that helps .. pSM |
A spin lock is pretty much exactly what I'm trying to implement. I'm just trying to keepdown the amount of shared memory required by using 1-bit booleans. Unfortunately for me, It appears that atomic operations only play well with an entire int or pointer, so I guess I'll have to use 32 bit booleans.
|
|
From some documentation for GLibC
Quote:
http://www.aquaphoenix.com/ref/gnu_c...60.html#SEC360 |
All times are GMT -5. The time now is 04:57 AM. |