How to invoke Spin Locks methods or macros in Red Hat Linux?

Hi,

I need to implement some section of code in Linux that I must use Spin Locks. My box is Red Hat AS Enterprise 3.0.

If you've known about the Spin Locks in Red Hat Linux: how to use them, how to invoke their library functions or system calls, please give some help.

Thanks a lot,

Rfr1tz

LVL 3
rfr1tzAsked:
Who is Participating?
 
sunnycoderCommented:
Look for

documentation/spinlocks.txt  ... It will give information about the spinlocks in your kernel.

-spin_lock_irq()
-spin_unlock_irq()
- spin_lock_irqsave()
- spin_unlock_irqrestore()

These are available at kernel level only. An names suggest, they are used for interrupt request handling
0
 
sunnycoderCommented:
Hi Rfr1tz,

Spinlocks are available inside the kernel but I do not think they are provided in the user library ... What are you trying to accomplish? Won't smeaphores and/or conditional variables of some help?

sunnycoder
0
 
manish_regmiCommented:
hi,
  If you are In user space you need spinlocks if you are writing multithreaded apps.
 So you might be using pthreads. Pthreads have a righ locking mechanisms including mutex, condvars, barriers, semaphores etc.

I think pthread mutex is what you are looking for.
int   pthread_mutex_lock(pthread_mutex_t *);
int   pthread_mutex_unlock(pthread_mutex_t *);

http://www.opengroup.org/onlinepubs/007908799/xsh/pthread.h.html

google for a tut on pthreads.
http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html
 
regards manish
 
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sunnycoderCommented:
Hi Manish,

I would not recommend using pthreads just for using their locking mechanisms. A lot of things can go wrong with an application which uses threads while there is no need. :)
0
 
rfr1tzAuthor Commented:
Hi sunnycoder and manish_regmi,

Our system is SMP (symmetric multiple processors). And The assignment requires that we must implement spin locks so that it would be polled coninuously to eb able to get the lock in the shortest period of time in some special cases whre the waiting time is very short.
 
I read into some articles of internets and found that some functions of spin locks are amentioned like:
-spin_lock_irq()
-spin_unlock_irq()
- spin_lock_irqsave()
- spin_unlock_irqrestore()

...

I don't know whether we can called these functions at user levels or not? If you alrready have experiences with these, please help.
I also looked into /usr/include/asm/spinlocks.h

I found the file there but the file is empty. Do you have any idea why the file is empty? And also, if I'd liek to look into the file spinlock.c. Do you know where this file is, which directory the file resides?

Thanks a lot,

Rfr1tz

0
 
manish_regmiCommented:
hi,
 Spinlocks in SMP are more difficult to implement. You cannot just implement traditional test_and_set() mechanism. I have never used spinlocks in user space. The function you gave is for kernel.
 I think it will be better you copy linux spinlock code from linux kernel tree (and remember include those with #ifdef CONFIG_SMP). And there are a lot of things you need to omit.

http://lxr.linux.no/source/include/linux/spinlock.h
http://lxr.linux.no/source/include/asm-i386/spinlock.h

CAn you extract what you require?

regards manish
 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.