LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 12-24-2011, 06:47 AM   #1
Fratty
LQ Newbie
 
Registered: Dec 2011
Location: Rome, Italy
Posts: 3

Rep: Reputation: Disabled
Question Kernel programming - how to get an array of mutex or spinlock?


Hi to all. I hope to post in the right forum

I'm writing some kernel code and I have some problem with the initialization of a mutex array.

I inherited some code from other guys but I can't make it work.

Code:
#define NUM_BUCKETS 256;

static barrier_struct *barrier_hash[NUM_BUCKETS];
struct mutex bucket_lock[NUM_BUCKETS];
...

int insert_barrier(int key){
...
        mutex_lock(&(bucket_lock[buck_bd]));
	barrier->next = barrier_hash[buck_bd];
	barrier_hash[buck_bd] = barrier;	
	mutex_unlock(&(bucket_lock[buck_bd]));
	
	return bd;

}
The problem is with the mutexes.
I can compile this code but when I try to use this it kills my process.
If I use only a single mutex and I use DEFINE_MUTEX() it works, but I want to have a mutex array. How could I initialize a whole array withous initializing it one-by-one?
Also, the same question is for spinlock, how could I use them?
 
Old 12-24-2011, 01:25 PM   #2
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 217

Rep: Reputation: 21
Hello.
You have to reserve memory for your array, else an access is undeffined - runtime error.
notes:
- type name[256]
- (new)
- SECTION .bss

Think about - kernel memory is rare.
 
Old 12-24-2011, 06:00 PM   #3
Fratty
LQ Newbie
 
Registered: Dec 2011
Location: Rome, Italy
Posts: 3

Original Poster
Rep: Reputation: Disabled
Yes, I know about the kernel memory... maybe you are right, I'll use less mutexes.

I was confused because I though that the code my friends gave me was working. But they told me just some time ago that it wasn't the working code.

Thank you really much.

Last edited by Fratty; 12-24-2011 at 06:07 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array question C programming chibi2666 Programming 7 07-16-2009 12:53 PM
[C programming] sorting strings in an array miguetoo Programming 1 05-26-2003 02:48 AM


All times are GMT -5. The time now is 04:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration